nkzw-tech / athena-crisis

Athena Crisis is an Advance Wars inspired modern-retro turn-based tactical strategy game. Athena Crisis is open core technology.
https://athenacrisis.com/open-source
Other
1.37k stars 105 forks source link

[Feature] Map Editor Undo should be stored in localStorage #3

Open cpojer opened 2 months ago

cpojer commented 2 months ago

Right now, when you accidentally reload you lose undo/redo state. Ideally undo/redo state is stored in an encoded form (MapData.toJSON) in localStorage and is therefore persisted after a reload, ensuring that players do not accidentally lose a map in progress. See the MapEditor component. It's also worth checking out the updateUndoStack function.

I suggest storing the undo state by mapObject?.id (or a fallback id if no mapObject is provided) so the undo stack can be per-map which will be on a different route in the game.

Additionally, when loading the map editor it has the ability to "restore" previous state, like from the last playtest. It should no longer be necessary to keep that feature separate, and instead the code should be cleaned up so that restorePreviousState just restores from the undo stack. This might need a fallback behavior so that it doesn't keep restoring the same previous map – or alternatively the "Restore Map" button in the MapEditorControlPanel should just be an "Undo" button after the first click (or after undo/redo is executed once). Open to ideas to ensure a good user experience.

Links

Funding

Fund with Polar

connorlindsey commented 1 month ago

I'd be interested in taking a pass at this one after the share url issue is complete since it touches similar parts of the code unless someone else wants to before then.

cpojer commented 1 month ago

Go for it!

tjamesmac commented 1 month ago

Oh I was beaten to the punch! I have been working on this a bit so probably my fault for not mentioning it sooner, is it okay if I keep plugging away @connorlindsey?

I'm at the point where i've got the undo stack restoring on reload and restoring the previous map. But I have a few questions about the MapObject.id and the restore previous state UX.

connorlindsey commented 1 month ago

@tjamesmac Yeah, go ahead 😄

tjamesmac commented 1 month ago

Thank you!

My questions were:

cpojer commented 1 month ago

Hey @tjamesmac, thanks for working on this and sorry for the late reply, I was at a conference. Let's take it to the PR you created.