Implement Multi-Step Undo - #10294
Conversation
This commit adds support for the missing state fields when creating a snapshot, and adds a test to make sure that in the future new state is not forgotten in the snapshot mechanism.
When the experimental snapshot mechanism is enabled, the UI now allows for undoing the last 10 operations with Ctrl+Z.
tool4ever
left a comment
There was a problem hiding this comment.
In general this seems desirable to level up this feature, but it could use some fine tuning:
right now the "Undo" button will almost always be available and that means toggling auto-pass gets much harder to reach
|
Hm, do you think it would be better if undo is only available via keyboard shortcut then? That would not clutter the interface. But people would have to know about that shortcut. |
|
nah, I think Undo is also pretty essential to have as a direct GUI element for new users either the days of overloading the cancel button this way need to end or some intuitive way to access both gets added (e.g. for desktop right click still seems available 🤔) |
|
I think given that's is still gated by the experimental opt-in + we've now made the dock access more prominent as part of yield improvements this would be ok GUI wise for future iteration. 🤷♂️ But I still have some reservations about all those additional setters which are transferring full objects between games. That almost certainly should be avoided or it risks introducing weird bugs of the states bleeding into each other... Also because I've implemented showing size of undo stack in the meantime this should be aligned. |
|
I agree that this is a bit brittle. I tried to address that by introducing a test that uses reflection to see if new attributes were introduced, but it is not perfect. And I realized in the meantime that while I do check that for the state, I did not introduce such automatic checks for the card state. That would be needed, too, but that makes the patch even more invasive. |
|
@tool4ever pointed me here from #11416 — I had been building the same feature without knowing this PR existed. Rather than compete with it, here is what I have that might be useful to you. Two of my PRs were duplicates of yours and are now closed (#11420 foretold, #11422 controller) — your patch covers both. The GUI part, if you want itYou mentioned Ctrl-Z only, and @tool4ever asked for a direct GUI element. I have one working against the current snapshot code, and it ports to your list of states with almost no change:
Happy to open it as a PR against your branch, hand over the patch, or just let you take the idea — whichever suits. One thing you will run intoRestoring the state is not enough on its own: auto-pass immediately carries the game forward again past the position you just went back to. From a live game of mine, four rewind clicks in a row: Each restore was undone by auto-pass before the player could act, and each one stashed a fresh snapshot at the same spot. What fixed it here: switch off Gaps still open after your patchFrom playing with this rather than reading it, four things your diff does not touch. All are separate PRs already, independent of this one:
On the brittlenessYour Written with Claude Code, same as your patch; every claim above has a test that fails before the change and passes after. |
|
thanks for the summary a) but the problem like with most AI PR is clean architecture that makes the copying not pollute all relevant classes too much |
This pull request implements multi-step undo by pressing Ctrl-Z, guarded behind the experimental snapshot flag. It consists of two patches:
Claude Code helped with creating the patch, and was used to check if all state was covered in the snapshot mechanism. I manually tested state reconstruction with complex card states, e.g., planeswalkers. The old code was definitively incorrect/incomplete, and the whole feature is disabled by default, thus it should be an improvement for sure.