Skip to content

Commit

Permalink
rename changeActionPlayers to setActionPlayers
Browse files Browse the repository at this point in the history
  • Loading branch information
darthfiddler committed Jul 30, 2018
1 parent 9bd6bb6 commit 75a274c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
7 changes: 5 additions & 2 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/react/modules/turnorder/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -44,7 +44,7 @@ const TurnExample = Game({
},

flow: {
changeActionPlayers: true,
setActionPlayers: true,

onTurnBegin: (G, ctx) => {
const currentPlayer = ctx.currentPlayer;
Expand Down
4 changes: 2 additions & 2 deletions src/client/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ test('event dispatchers', () => {
flow: {
endPhase: true,
endGame: true,
changeActionPlayers: true,
setActionPlayers: true,
},
});
const reducer = CreateGameReducer({ game, numPlayers: 2 });
Expand All @@ -158,7 +158,7 @@ test('event dispatchers', () => {
'endTurn',
'endPhase',
'endGame',
'changeActionPlayers',
'setActionPlayers',
]);
expect(store.getState().ctx.turn).toBe(0);
api.endTurn();
Expand Down
14 changes: 7 additions & 7 deletions src/core/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {
ChangeActionPlayers,
SetActionPlayers,
InitTurnOrderState,
UpdateTurnOrderState,
TurnOrder,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -247,7 +247,7 @@ export function FlowWithPhases({
endTurn,
endPhase,
endGame,
changeActionPlayers,
setActionPlayers,
undoableMoves,
allowedMoves,
optimisticUpdate,
Expand All @@ -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;
Expand Down Expand Up @@ -600,8 +600,8 @@ export function FlowWithPhases({
if (endGame) {
enabledEvents['endGame'] = endGameEvent;
}
if (changeActionPlayers) {
enabledEvents['changeActionPlayers'] = ChangeActionPlayers;
if (setActionPlayers) {
enabledEvents['setActionPlayers'] = SetActionPlayers;
}

return Flow({
Expand Down
4 changes: 2 additions & 2 deletions src/core/turn-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions src/core/turn-order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,33 +190,33 @@ 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']);
});

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) => {
Expand All @@ -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;
}
Expand Down

0 comments on commit 75a274c

Please sign in to comment.