diff --git a/client/app.js b/client/app.js index 18d9ab4..b716eca 100644 --- a/client/app.js +++ b/client/app.js @@ -3,6 +3,9 @@ import {EventEmitter, Property} from '@avocado/mixins'; const decorate = compose( EventEmitter, + Property('isDebugging', { + track: true, + }), Property('selfEntity', { track: true, }), diff --git a/client/index.js b/client/index.js index fe26bdb..54d5706 100644 --- a/client/index.js +++ b/client/index.js @@ -85,6 +85,12 @@ room.on('entityAdded', (entity) => { } }); // Accept input. +window.addEventListener('keydown', (event) => { + event = event || window.event; + if ('F2' === event.key) { + app.isDebugging = !app.isDebugging; + } +}); const actionRegistry = new ActionRegistry(); actionRegistry.mapKeysToActions({ 'w': 'MoveUp', @@ -155,7 +161,8 @@ const pointerMovementHandle = setInterval(() => { do { let normal; if (isPointingAtAnything()) { - normal = createMoveToNormal(pointingAt); + const toVector = Vector.scale(pointingAt, app.isDebugging ? 2 : 1); + normal = createMoveToNormal(toVector); if (normal) { actionRegistry.state = actionRegistry.state.withMutations((state) => { if (normal[0]) { diff --git a/client/ui/debug/index.js b/client/ui/debug/index.js index 793ce7b..2fb6ed3 100644 --- a/client/ui/debug/index.js +++ b/client/ui/debug/index.js @@ -40,15 +40,12 @@ const DebugUi = ({ }, []); // F2 toggle debug. useEffect(() => { - const onKeyDown = (event) => { - event = event || window.event; - if ('F2' === event.key) { - setIsDebugging(!isDebugging); - } + const onIsDebuggingChanged = () => { + setIsDebugging(app.isDebugging); }; - window.addEventListener('keydown', onKeyDown); + app.on('isDebuggingChanged', onIsDebuggingChanged); return () => { - window.removeEventListener('keydown', onKeyDown); + app.off('isDebuggingChanged', onIsDebuggingChanged); }; }, [isDebugging]); // Scale stage when debugging.