Open ninjawithkillmoon opened 7 years ago
Why not store a history of actions? As long as each individual action is invertible, then you save a lot of overhead. You could also use the change history as a log of what has happened, if you wanted to be able to display that to the user (e.g. #22).
Since you're using Flux this shouldn't be too technically invasive (I think? I'm only familiar with Redux as opposed to vanilla Flux, but I think the concept is the same)
A button that allows a user to return to a previous state. This could be either:
To keep it simple (and to keep save file sizes to a minimum) this probably does not need to persist if the user loads the page again?
I'm thinking just storing the entire save file in memory whenever a user makes a change. Each one of these is about 10KB, so storing the last 100 changes is only 1MB of memory.
The challenge is the idea of a "change". Every single tap of a button that removes 1 health from a monster, for example, is changing the save game state. Could this be run on a timer? Every 5 seconds we check for a change. If the game state has changed, generate a new restore point in memory. The undo button could then just restore the most recent one.