Skip to content

Commit a352d1e

Browse files
committed
decouple once and allOthers
1 parent 57fa642 commit a352d1e

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

docs/events.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ const opts = {
6868
all: true,
6969
7070
// Use this to set actionPlayers to all players
71-
// except the current player.
71+
// except the current player. When combined with
72+
// `once: true`, the current player is added back
73+
// to `actionPlayers` once everyone else takes a move.
7274
allOthers: true,
7375
};
7476

examples/react/modules/turnorder/game.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const TurnExample = Game({
3333

3434
moves: {
3535
playMilitia: (G, ctx) => {
36-
ctx.events.setActionPlayers({ allOthers: true });
36+
ctx.events.setActionPlayers({ once: true, allOthers: true });
3737

3838
const currentPlayer = ctx.currentPlayer;
3939
const playersNext = [...G.players];

src/core/flow.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,8 @@ export function FlowWithPhases({
552552
if (state.ctx._actionPlayersOnce) {
553553
const playerID = action.playerID;
554554
actionPlayers = actionPlayers.filter(id => id !== playerID);
555-
}
556-
if (state.ctx._actionPlayersAllOthers) {
557-
const playerID = action.playerID;
558-
actionPlayers = actionPlayers.filter(id => id !== playerID);
559-
if (actionPlayers.length === 0) {
555+
556+
if (state.ctx._actionPlayersAllOthers && actionPlayers.length === 0) {
560557
actionPlayers = [state.ctx.currentPlayer];
561558
}
562559
}

src/core/turn-order.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ export const Pass = (G, ctx) => {
3333
* @param {object} arg - An array of playerID's or <object> of:
3434
* {
3535
* value: [], // array of playerID's (optional if all is set).
36+
*
3637
* all: true, // set value to all playerID's
38+
*
3739
* allOthers: true, // set value to all except currentPlayer.
38-
* once: true, // players have one move.
40+
* // when combined with `once` (below)
41+
* // currentPlayer is added back after
42+
* // everyone has taken their move.
43+
*
44+
* once: true, // players have one move
45+
* // (after which they're pruned from actionPlayers).
3946
* }
4047
*/
4148
export function SetActionPlayers(state, arg) {

src/core/turn-order.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ describe('SetActionPlayers', () => {
245245
B: (G, ctx) => {
246246
ctx.events.setActionPlayers({
247247
value: ['0', '1', '2'],
248+
once: true,
248249
allOthers: true,
249250
});
250251
return G;

0 commit comments

Comments
 (0)