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(
EventEmitter,
Property('isDebugging', {
track: true,
}),
Property('selfEntity', {
track: true,
}),

View File

@ -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]) {

View File

@ -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.