@@ -30,31 +30,37 @@ export const Pass = (G, ctx) => {
3030/**
3131 * Event to change the actionPlayers array.
3232 * @param {object } state - The game state.
33- * @param {object } actionPlayers - An array of playerID's or
34- * TurnOrder.ALL.
33+ * @param {object } arg - An array of playerID's or <object> of:
34+ * {
35+ * value: [], // array of playerID's (optional if all is set).
36+ * all: true, // set value to all playerID's
37+ * once: true, // players have one move.
38+ * }
3539 */
36- export function SetActionPlayers ( state , actionPlayers , opts ) {
40+ export function SetActionPlayers ( state , arg ) {
3741 let _actionPlayersOnce = false ;
38- if ( opts && opts . once ) {
42+ let actionPlayers = [ ] ;
43+
44+ if ( arg . once ) {
3945 _actionPlayersOnce = true ;
4046 }
4147
42- if ( actionPlayers == TurnOrder . ALL ) {
48+ if ( arg . value ) {
49+ actionPlayers = arg . value ;
50+ }
51+
52+ if ( arg . all ) {
4353 actionPlayers = [ ...state . ctx . playOrder ] ;
44- return {
45- ...state ,
46- ctx : { ...state . ctx , actionPlayers, _actionPlayersOnce } ,
47- } ;
4854 }
4955
50- if ( actionPlayers && actionPlayers . length ) {
51- return {
52- ...state ,
53- ctx : { ...state . ctx , actionPlayers, _actionPlayersOnce } ,
54- } ;
56+ if ( Array . isArray ( arg ) ) {
57+ actionPlayers = arg ;
5558 }
5659
57- return state ;
60+ return {
61+ ...state ,
62+ ctx : { ...state . ctx , actionPlayers, _actionPlayersOnce } ,
63+ } ;
5864}
5965
6066/**
@@ -145,30 +151,22 @@ export function UpdateTurnOrderState(G, ctx, turnOrder, nextPlayer) {
145151 return { endPhase, ctx } ;
146152}
147153
154+ /**
155+ * Set of different turn orders possible in a phase.
156+ * These are meant to be passed to the `turnOrder` setting
157+ * in the flow objects.
158+ *
159+ * Each object defines the first player when the phase / game
160+ * begins, and also a function `next` to determine who the
161+ * next player is when the turn ends.
162+ *
163+ * first / next can also return an object of type
164+ * { playOrderPos, actionPlayers }
165+ * in which case they can also set actionPlayers simultaneously.
166+ *
167+ * The phase ends if next() returns undefined.
168+ */
148169export const TurnOrder = {
149- /**
150- * Constant that can be used as an argument to
151- * setActionPlayers to make it set actionPlayers
152- * to all the players in the game.
153- */
154- ALL : 'all' ,
155-
156- /**
157- * Set of different turn orders possible in a phase.
158- * These are meant to be passed to the `turnOrder` setting
159- * in the flow objects.
160- *
161- * Each object defines the first player when the phase / game
162- * begins, and also a function `next` to determine who the
163- * next player is when the turn ends.
164- *
165- * first / next can also return an object of type
166- * { playOrderPos, actionPlayers }
167- * in which case they can also set actionPlayers simultaneously.
168- *
169- * The phase ends if next() returns undefined.
170- */
171-
172170 /**
173171 * DEFAULT
174172 *
0 commit comments