From be06ab1ddef1e6d100126ec0db42ed03e8bd27b2 Mon Sep 17 00:00:00 2001 From: delucis Date: Mon, 30 Sep 2019 21:03:54 +0200 Subject: [PATCH 1/2] test: Add test for `endStage` when stage has `next` field --- src/core/flow.test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/core/flow.test.js b/src/core/flow.test.js index 28836524e..735820f2f 100644 --- a/src/core/flow.test.js +++ b/src/core/flow.test.js @@ -569,6 +569,39 @@ describe('stage events', () => { state = flow.processEvent(state, gameEvent('endStage')); expect(state.ctx._activePlayersNumMoves).toMatchObject({ '0': 1 }); }); + + test('sets to next', () => { + let flow = Flow({ + turn: { + activePlayers: { player: 'A1', others: 'B1' }, + stages: { + A1: { next: 'A2' }, + B1: { next: 'B2' }, + }, + }, + }); + let state = { G: {}, ctx: flow.ctx(2) }; + state = flow.init(state); + + expect(state.ctx.activePlayers).toMatchObject({ + '0': 'A1', + '1': 'B1', + }); + + state = flow.processEvent(state, gameEvent('endStage', null, '0')); + + expect(state.ctx.activePlayers).toMatchObject({ + '0': 'A2', + '1': 'B1', + }); + + state = flow.processEvent(state, gameEvent('endStage', null, '1')); + + expect(state.ctx.activePlayers).toMatchObject({ + '0': 'A2', + '1': 'B2', + }); + }); }); }); From d4f0aaee4fd43511fc28ed8a90125bb47fd28dc1 Mon Sep 17 00:00:00 2001 From: delucis Date: Mon, 30 Sep 2019 21:06:31 +0200 Subject: [PATCH 2/2] feat: Move player to `next` stage on `endStage` --- src/core/flow.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/flow.js b/src/core/flow.js index d588b025c..0889de542 100644 --- a/src/core/flow.js +++ b/src/core/flow.js @@ -553,14 +553,20 @@ export function Flow({ moves, phases, endIf, turn, events, plugins }) { let { ctx } = state; let { activePlayers, _activePlayersMoveLimit } = ctx; + const playerInStage = activePlayers !== null && playerID in activePlayers; + + if (!arg && playerInStage) { + const conf = GetPhase(ctx); + const stage = conf.turn.stages[activePlayers[playerID]]; + if (stage && stage.next) arg = stage.next; + } + if (next && arg) { next.push({ fn: UpdateStage, arg, playerID }); } // If player isn’t in a stage, there is nothing else to do. - if (activePlayers === null || !(playerID in activePlayers)) { - return state; - } + if (!playerInStage) return state; // Remove player from activePlayers. activePlayers = Object.keys(activePlayers)