refactor: App::isDebugging

This commit is contained in:
cha0s 2019-04-14 16:46:22 -05:00
parent 92e36587d0
commit 44597caa96
3 changed files with 15 additions and 8 deletions

View File

@ -3,6 +3,9 @@ import {EventEmitter, Property} from '@avocado/mixins';
const decorate = compose( const decorate = compose(
EventEmitter, EventEmitter,
Property('isDebugging', {
track: true,
}),
Property('selfEntity', { Property('selfEntity', {
track: true, track: true,
}), }),

View File

@ -85,6 +85,12 @@ room.on('entityAdded', (entity) => {
} }
}); });
// Accept input. // Accept input.
window.addEventListener('keydown', (event) => {
event = event || window.event;
if ('F2' === event.key) {
app.isDebugging = !app.isDebugging;
}
});
const actionRegistry = new ActionRegistry(); const actionRegistry = new ActionRegistry();
actionRegistry.mapKeysToActions({ actionRegistry.mapKeysToActions({
'w': 'MoveUp', 'w': 'MoveUp',
@ -155,7 +161,8 @@ const pointerMovementHandle = setInterval(() => {
do { do {
let normal; let normal;
if (isPointingAtAnything()) { if (isPointingAtAnything()) {
normal = createMoveToNormal(pointingAt); const toVector = Vector.scale(pointingAt, app.isDebugging ? 2 : 1);
normal = createMoveToNormal(toVector);
if (normal) { if (normal) {
actionRegistry.state = actionRegistry.state.withMutations((state) => { actionRegistry.state = actionRegistry.state.withMutations((state) => {
if (normal[0]) { if (normal[0]) {

View File

@ -40,15 +40,12 @@ const DebugUi = ({
}, []); }, []);
// F2 toggle debug. // F2 toggle debug.
useEffect(() => { useEffect(() => {
const onKeyDown = (event) => { const onIsDebuggingChanged = () => {
event = event || window.event; setIsDebugging(app.isDebugging);
if ('F2' === event.key) {
setIsDebugging(!isDebugging);
}
}; };
window.addEventListener('keydown', onKeyDown); app.on('isDebuggingChanged', onIsDebuggingChanged);
return () => { return () => {
window.removeEventListener('keydown', onKeyDown); app.off('isDebuggingChanged', onIsDebuggingChanged);
}; };
}, [isDebugging]); }, [isDebugging]);
// Scale stage when debugging. // Scale stage when debugging.