Make sure we don't double-buffer an input causing undo to become stuck

This commit is contained in:
Logan Hunt 2022-04-10 22:21:38 -06:00
parent 69b5f4448c
commit 1bdfb42c3d

View File

@ -11,14 +11,16 @@ game.system.KeyboardInput = (undoSystem) => {
const entity = entities[id];
if (entity.hasComponent('controllable')) {
const controls = entity.components.controllable.controls;
if (controls.includes('left') && keys['ArrowLeft']) {
entity.addComponent(game.components.Momentum({ dx: -1, dy: 0 }));
} else if (controls.includes('right') && keys['ArrowRight']) {
entity.addComponent(game.components.Momentum({ dx: 1, dy: 0 }));
} else if (controls.includes('up') && keys['ArrowUp']) {
entity.addComponent(game.components.Momentum({ dx: 0, dy: -1 }));
} else if (controls.includes('down') && keys['ArrowDown']) {
entity.addComponent(game.components.Momentum({ dx: 0, dy: 1 }));
if (!changedIds.has(entity.id)) {
if (controls.includes('left') && keys['ArrowLeft']) {
entity.addComponent(game.components.Momentum({ dx: -1, dy: 0 }));
} else if (controls.includes('right') && keys['ArrowRight']) {
entity.addComponent(game.components.Momentum({ dx: 1, dy: 0 }));
} else if (controls.includes('up') && keys['ArrowUp']) {
entity.addComponent(game.components.Momentum({ dx: 0, dy: -1 }));
} else if (controls.includes('down') && keys['ArrowDown']) {
entity.addComponent(game.components.Momentum({ dx: 0, dy: 1 }));
}
}
}
}