I’m writing this because I hope that, in the process of writing it, I will help myself think through how to solve it and also, if I am honest, to have a bit of a whinge.
So I have been trying to implement undo in Rez and boy have I made life difficult for myself.
I’ve introduced an “Undo Manager” that receives a ‘revert’ command every time a game object changes an attribute. When a new event starts it creates a new undo context and the changes flow into that. I could, perhaps, even implement redo although I am less bothered to do that.
All good so far.
Except the view doesn’t update. Oh, yes, Rez has a fairly complex rendering pipeline. This is all Javascript objects and not part of the data model.
This is due to the Game>Scene>Card+>Blocks+ rendering system.
A game has a layout which contains a scene which has a layout that may include one or more cards, which can be flipped to their back side, and each of which may be composed of other cards. It’s very flexible and you can do some cool stuff with it.
For example the stack layout lets you append cards, instead of replacing a single card, as events happen. Only the current card shows its front face and past cards are “flipped”.
So on the front face you might have links representing actions the player can take and, on the flipped face, no links but a statement of what the player did, with the next card representing the result of that action.
Rez also support parameterized links.
<a card="fight" data-monster="goblin">
Passes {monster: "goblin"}
to the #fight
@card
and it can use that parameter as part of its processing.
Again this complicates things because those params have to live somewhere and it can’t be the card itself because it can be used in multiple contexts.
So all this is great, it makes it possible to do nifty stuff. But it comes at a cost.
So far I’ve been unable to either revert or rebuild the view properly after an undo and the view code is sufficiently twisty that I find it hard to hold the whole sequence in my head and think it through to see why.
Alas, neither Claude nor Gemini have made any headway on the problem. In fact their efforts have been pretty hapless. So I am going to have to fix this myself.
</whinge>