From 75a274cff7e00ce877eae6b236c423d5e6e159a5 Mon Sep 17 00:00:00 2001 From: Nicolo Davis Date: Tue, 31 Jul 2018 00:09:44 +0800 Subject: [PATCH] rename changeActionPlayers to setActionPlayers --- docs/events.md | 7 +++++-- examples/react/modules/turnorder/game.js | 4 ++-- src/client/client.test.js | 4 ++-- src/core/flow.js | 14 +++++++------- src/core/turn-order.js | 4 ++-- src/core/turn-order.test.js | 14 +++++++------- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/docs/events.md b/docs/events.md index aefcaf370..9c2d1bc09 100644 --- a/docs/events.md +++ b/docs/events.md @@ -45,14 +45,17 @@ then that argument is made available in `ctx.gameover`. After the game is over, further state changes to the game (via a move or event) are not possible. -##### changeActionPlayers +##### setActionPlayers This changes `ctx.actionPlayers` to the provided argument. See the guide on [Turn Orders](turn-order.md) for more details about `actionPlayers`. +You may pass `TurnOrder.ALL` as an argument to set +`actionPlayers` to all the players in the game. + This event is not enabled by default and must be enabled -by setting `changeActionPlayers: true` in the `flow` section +by setting `setActionPlayers: true` in the `flow` section of your game. ### Triggering an event from a React client. diff --git a/examples/react/modules/turnorder/game.js b/examples/react/modules/turnorder/game.js index 8f18b56f6..ecea739e5 100644 --- a/examples/react/modules/turnorder/game.js +++ b/examples/react/modules/turnorder/game.js @@ -32,7 +32,7 @@ const TurnExample = Game({ playMilitia: (G, ctx) => { // Need to keep the currentPlayer inside actionPlayers - otherwise // he will not be able to make any move anymore. - ctx.events.changeActionPlayers(['0', '1', '2']); + ctx.events.setActionPlayers(['0', '1', '2']); const currentPlayer = ctx.currentPlayer; const playersNext = [...G.players]; @@ -44,7 +44,7 @@ const TurnExample = Game({ }, flow: { - changeActionPlayers: true, + setActionPlayers: true, onTurnBegin: (G, ctx) => { const currentPlayer = ctx.currentPlayer; diff --git a/src/client/client.test.js b/src/client/client.test.js index 06fc11a75..0e9278706 100644 --- a/src/client/client.test.js +++ b/src/client/client.test.js @@ -148,7 +148,7 @@ test('event dispatchers', () => { flow: { endPhase: true, endGame: true, - changeActionPlayers: true, + setActionPlayers: true, }, }); const reducer = CreateGameReducer({ game, numPlayers: 2 }); @@ -158,7 +158,7 @@ test('event dispatchers', () => { 'endTurn', 'endPhase', 'endGame', - 'changeActionPlayers', + 'setActionPlayers', ]); expect(store.getState().ctx.turn).toBe(0); api.endTurn(); diff --git a/src/core/flow.js b/src/core/flow.js index a0dd0d885..5adbe0739 100644 --- a/src/core/flow.js +++ b/src/core/flow.js @@ -7,7 +7,7 @@ */ import { - ChangeActionPlayers, + SetActionPlayers, InitTurnOrderState, UpdateTurnOrderState, TurnOrder, @@ -162,7 +162,7 @@ export function Flow({ * * @param {...object} endGame - Set to true to enable the `endGame` event. * - * @param {...object} changeActionPlayers - Set to true to enable the `changeActionPlayers` event. + * @param {...object} setActionPlayers - Set to true to enable the `setActionPlayers` event. * * @param {...object} allowedMoves - List of moves that are allowed. * This can be either a list of @@ -247,7 +247,7 @@ export function FlowWithPhases({ endTurn, endPhase, endGame, - changeActionPlayers, + setActionPlayers, undoableMoves, allowedMoves, optimisticUpdate, @@ -262,8 +262,8 @@ export function FlowWithPhases({ if (endGame === undefined) { endGame = false; } - if (changeActionPlayers === undefined) { - changeActionPlayers = false; + if (setActionPlayers === undefined) { + setActionPlayers = false; } if (optimisticUpdate === undefined) { optimisticUpdate = () => true; @@ -600,8 +600,8 @@ export function FlowWithPhases({ if (endGame) { enabledEvents['endGame'] = endGameEvent; } - if (changeActionPlayers) { - enabledEvents['changeActionPlayers'] = ChangeActionPlayers; + if (setActionPlayers) { + enabledEvents['setActionPlayers'] = SetActionPlayers; } return Flow({ diff --git a/src/core/turn-order.js b/src/core/turn-order.js index d1765290b..d67620dbf 100644 --- a/src/core/turn-order.js +++ b/src/core/turn-order.js @@ -33,7 +33,7 @@ export const Pass = (G, ctx) => { * @param {object} actionPlayers - An array of playerID's or * TurnOrder.ALL. */ -export function ChangeActionPlayers(state, actionPlayers) { +export function SetActionPlayers(state, actionPlayers) { if (actionPlayers == TurnOrder.ALL) { actionPlayers = [...state.ctx.playOrder]; return { ...state, ctx: { ...state.ctx, actionPlayers } }; @@ -137,7 +137,7 @@ export function UpdateTurnOrderState(G, ctx, turnOrder, nextPlayer) { export const TurnOrder = { /** * Constant that can be used as an argument to - * changeActionPlayers to make it set actionPlayers + * setActionPlayers to make it set actionPlayers * to all the players in the game. */ ALL: 'all', diff --git a/src/core/turn-order.test.js b/src/core/turn-order.test.js index c3149c283..96343e249 100644 --- a/src/core/turn-order.test.js +++ b/src/core/turn-order.test.js @@ -190,13 +190,13 @@ test('playOrder', () => { }); describe('change action players', () => { - const flow = FlowWithPhases({ changeActionPlayers: true }); + const flow = FlowWithPhases({ setActionPlayers: true }); const state = { ctx: flow.ctx(2) }; test('basic', () => { const newState = flow.processGameEvent( state, - gameEvent('changeActionPlayers', [['1']]) + gameEvent('setActionPlayers', [['1']]) ); expect(newState.ctx.actionPlayers).toMatchObject(['1']); }); @@ -204,19 +204,19 @@ describe('change action players', () => { test('all', () => { const newState = flow.processGameEvent( state, - gameEvent('changeActionPlayers', [TurnOrder.ALL]) + gameEvent('setActionPlayers', [TurnOrder.ALL]) ); expect(newState.ctx.actionPlayers).toMatchObject(['0', '1']); }); test('militia', () => { const game = Game({ - flow: { changeActionPlayers: true }, + flow: { setActionPlayers: true }, moves: { playMilitia: (G, ctx) => { // change which players need to act - ctx.events.changeActionPlayers([1, 2, 3]); + ctx.events.setActionPlayers([1, 2, 3]); return { ...G, playedCard: 'Militia' }; }, dropCards: (G, ctx) => { @@ -228,11 +228,11 @@ describe('change action players', () => { var newActionPlayers = [...ctx.actionPlayers].filter( pn => pn !== ctx.playerID ); - ctx.events.changeActionPlayers(newActionPlayers); + ctx.events.setActionPlayers(newActionPlayers); let playedCard = G.playedCard; if (actedOnMilitia.length === 3) { - ctx.events.changeActionPlayers([0]); + ctx.events.setActionPlayers([0]); actedOnMilitia = undefined; playedCard = undefined; }