Skip to content

Commit

Permalink
enable events API in initial onTurnBegin/onPhaseBegin
Browse files Browse the repository at this point in the history
  • Loading branch information
darthfiddler committed Jul 31, 2018
1 parent 5d3a34d commit acb9d8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ export function CreateGameReducer({ game, numPlayers, multiplayer }) {

const state = game.flow.init({ G: initial.G, ctx: ctxWithAPI });

const { ctx: ctxWithEvents } = events.update(state);
initial.G = state.G;
initial._undo = state._undo;
initial.ctx = random.update(state.ctx);
initial.ctx = ctxWithEvents;
initial.ctx = random.update(initial.ctx);
initial.ctx = Random.detach(initial.ctx);
initial.ctx = Events.detach(initial.ctx);

Expand Down
16 changes: 16 additions & 0 deletions src/core/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ describe('Random inside setup()', () => {
});
});

test('events API inside first onTurnBegin', () => {
const game = Game({
flow: {
setActionPlayers: true,
onTurnBegin: (G, ctx) => {
ctx.events.setActionPlayers(['0', '1']);
},
},
});

const reducer = CreateGameReducer({ game });
const state = reducer(undefined, { type: 'init' });

expect(state.ctx.actionPlayers).toEqual(['0', '1']);
});

test('undo / redo', () => {
let game = Game({
moves: {
Expand Down

0 comments on commit acb9d8c

Please sign in to comment.