From 1bdfb42c3d5dd9a9ed416d97ae7f288f6d831a7e Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Sun, 10 Apr 2022 22:21:38 -0600 Subject: [PATCH] Make sure we don't double-buffer an input causing undo to become stuck --- src/systems/keyboardInput.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/systems/keyboardInput.js b/src/systems/keyboardInput.js index 5ce6737..50afda1 100644 --- a/src/systems/keyboardInput.js +++ b/src/systems/keyboardInput.js @@ -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 })); + } } } }