boardgame.io icon indicating copy to clipboard operation
boardgame.io copied to clipboard

Is there currently any way to intercept undo-behavior?

Open on3iro opened this issue 1 year ago • 2 comments

Hey,

I am currently trying to build some kind of animation system alongside my game. What I want to do is, declare some kind of animation state inside my game state and make each clients UI react to the animation respectively. However this concept will somewhat clash with Undo, because the animation state will also be set to the last animation state and therefore trigger the animation again (which does not really make sense, when a move has just been undone).

First I thought of mutating the state from my react-ui and clearing the animation property whenever an undo happens, but that feels a) needlessly complicated and b) might trigger addiotional re-renders I don't want.

Now to the solution I'd prefer, but which currently seems not to be possible: The cleanest way to achieve something like this, would be writing a plugin, which simply wraps undo. So that when a move is being undone, we modify the state accordingly, remove the animation-declaration and set a new state, instead of the old one.

Is there already a way to build a middleware like this (the current plugin system does not seem to support such a use case) and if not would you be willing to accept PRs in that regard? Or do you have a better idea how I could solve this use case?

Thanks in advance

on3iro avatar Feb 16 '23 12:02 on3iro