diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-10 22:21:38 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-10 22:21:38 -0600 |
commit | 1bdfb42c3d5dd9a9ed416d97ae7f288f6d831a7e (patch) | |
tree | 062a2a651808a4db4818524db5b5b00bc8a8cf87 | |
parent | 69b5f4448c1cbd00ebcb6f444f2434cc272b7e97 (diff) | |
download | bbiy-1bdfb42c3d5dd9a9ed416d97ae7f288f6d831a7e.tar.gz bbiy-1bdfb42c3d5dd9a9ed416d97ae7f288f6d831a7e.zip |
Make sure we don't double-buffer an input causing undo to become stuck
-rw-r--r-- | src/systems/keyboardInput.js | 18 |
1 files 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 })); + } } } } |