diff options
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 |