diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-10 22:13:05 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-10 22:13:05 -0600 |
commit | 69b5f4448c1cbd00ebcb6f444f2434cc272b7e97 (patch) | |
tree | 02152d8eb67f1b4913222b412d72740f59808c7b /src/systems/undo.js | |
parent | a23ea2e014d140dbe9c090e6cf7d55906480c260 (diff) | |
download | bbiy-69b5f4448c1cbd00ebcb6f444f2434cc272b7e97.tar.gz bbiy-69b5f4448c1cbd00ebcb6f444f2434cc272b7e97.zip |
Unlimited undo; add spritename component instead of sprites on each entity; update canvas on game object
Diffstat (limited to 'src/systems/undo.js')
-rw-r--r-- | src/systems/undo.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/systems/undo.js b/src/systems/undo.js new file mode 100644 index 0000000..fa36c93 --- /dev/null +++ b/src/systems/undo.js @@ -0,0 +1,32 @@ +game.system.Undo = (entitiesGrid) => { + const states = []; + + const update = (elapsedTime, entities, changedIds) => { + if (changedIds.size) { + lastUndid = false; + const state = {}; + for (let id in entities) { + if (entities[id].hasComponent("gridPosition")) { + state[id] = JSON.parse(JSON.stringify(entities[id].components)); + } + } + states.push(state); + } + return new Set(); + } + + const undo = (entities) => { + states.map((state) => console.log(state[65].gridPosition)); + let state = states.slice(0, -1).pop(); + for (let id in state) { + for (let componentName in state[id]) { + entities[id].addComponent({name: componentName, ...state[id][componentName]}); + } + } + if (states.length > 1) { + states.pop(); + } + } + + return { update, undo }; +}
\ No newline at end of file |