Skip to content

Commit

Permalink
fix(core): Fix undo/redo if the move changed the stage (#701)
Browse files Browse the repository at this point in the history
* Fix for null last move if changed the stage

* Added reducer test with using stages

* ESlint fixes and test logic fixes

* Fixed playerID in reducer undo/redo test

* feat(core): Mark numPlayers as optional in InitializeGame

* test(core): Convert reducer tests to TS & break up undo/redo tests

* test(core): Fix makeMove call in undo/redo test

* test(core): Improve test labelling

* feat(core): Move undo/redo stack update after event processing

* test(core): Remove unnecessary seed in test setup

* fix(core): Lookup undoable move from restore state not last state

* fix(core): Use playerID instead of currentPlayer in undoable move lookup

* test(core): Add low-level tests for undo/redo stacks

* feat(core): Don’t add move to update stack if turn was ended

Co-authored-by: delucis <swithinbank@gmail.com>
  • Loading branch information
JGrzybowski and delucis authored May 22, 2020
1 parent 60b32e5 commit d728425
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 25 deletions.
10 changes: 0 additions & 10 deletions src/core/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,16 +699,6 @@ export function Flow({
const G = conf.turn.wrapped.onMove(state);
state = { ...state, G };

// Update undo / redo state.
const undo = state._undo || [];
const moveType = action.type;

state = {
...state,
_undo: [...undo, { G: state.G, ctx: state.ctx, moveType }],
_redo: [],
};

let events = [{ fn: OnMove }];

return Process(state, events);
Expand Down
2 changes: 1 addition & 1 deletion src/core/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function InitializeGame({
setupData,
}: {
game: Game;
numPlayers: number;
numPlayers?: number;
setupData?: any;
}) {
game = ProcessGameConfig(game);
Expand Down
Loading

0 comments on commit d728425

Please sign in to comment.