@@ -47,34 +47,33 @@ export const Pass = (G, ctx) => {
4747 * // (after which they're pruned from actionPlayers).
4848 * }
4949 */
50- export function SetActionPlayers ( state , arg ) {
50+ export function SetActionPlayersEvent ( state , arg ) {
51+ return { ...state , ctx : setActionPlayers ( state . ctx , arg ) } ;
52+ }
53+
54+ function setActionPlayers ( ctx , arg ) {
5155 let actionPlayers = [ ] ;
5256
5357 if ( arg . value ) {
5458 actionPlayers = arg . value ;
5559 }
5660 if ( arg . all ) {
57- actionPlayers = [ ...state . ctx . playOrder ] ;
61+ actionPlayers = [ ...ctx . playOrder ] ;
5862 }
5963
6064 if ( arg . allOthers ) {
61- actionPlayers = [ ...state . ctx . playOrder ] . filter (
62- nr => nr !== state . ctx . currentPlayer
63- ) ;
65+ actionPlayers = [ ...ctx . playOrder ] . filter ( nr => nr !== ctx . currentPlayer ) ;
6466 }
6567
6668 if ( Array . isArray ( arg ) ) {
6769 actionPlayers = arg ;
6870 }
6971
7072 return {
71- ...state ,
72- ctx : {
73- ...state . ctx ,
74- actionPlayers,
75- _actionPlayersOnce : arg . once ,
76- _actionPlayersAllOthers : arg . allOthers ,
77- } ,
73+ ...ctx ,
74+ actionPlayers,
75+ _actionPlayersOnce : arg . once ,
76+ _actionPlayersAllOthers : arg . allOthers ,
7877 } ;
7978}
8079
@@ -94,26 +93,16 @@ function getCurrentPlayer(playOrder, playOrderPos) {
9493 * @param {object } turnOrder - A turn order object for this phase.
9594 */
9695export function InitTurnOrderState ( G , ctx , turnOrder ) {
97- let playOrderPos ;
98- let actionPlayers ;
99-
100- const t = turnOrder . first ( G , ctx ) ;
101-
102- if ( t . playOrderPos !== undefined ) {
103- playOrderPos = t . playOrderPos ;
104- } else {
105- playOrderPos = t ;
106- }
107-
96+ const playOrderPos = turnOrder . first ( G , ctx ) ;
10897 const currentPlayer = getCurrentPlayer ( ctx . playOrder , playOrderPos ) ;
10998
110- if ( t . actionPlayers !== undefined ) {
111- actionPlayers = t . actionPlayers ;
99+ if ( turnOrder . actionPlayers !== undefined ) {
100+ ctx = setActionPlayers ( ctx , turnOrder . actionPlayers ) ;
112101 } else {
113- actionPlayers = [ currentPlayer ] ;
102+ ctx = { ... ctx , actionPlayers : [ currentPlayer ] } ;
114103 }
115104
116- return { ...ctx , currentPlayer, playOrderPos, actionPlayers } ;
105+ return { ...ctx , currentPlayer, playOrderPos } ;
117106}
118107
119108/**
@@ -141,20 +130,13 @@ export function UpdateTurnOrderState(G, ctx, turnOrder, endTurnArg) {
141130 } else {
142131 const t = turnOrder . next ( G , ctx ) ;
143132
144- if ( t == undefined ) {
133+ if ( t === undefined ) {
145134 endPhase = true ;
146135 } else {
147- if ( t . playOrderPos !== undefined ) {
148- playOrderPos = t . playOrderPos ;
149- } else {
150- playOrderPos = t ;
151- }
152-
136+ playOrderPos = t ;
153137 currentPlayer = getCurrentPlayer ( ctx . playOrder , playOrderPos ) ;
154138
155- if ( t . actionPlayers !== undefined ) {
156- actionPlayers = t . actionPlayers ;
157- } else {
139+ if ( turnOrder . actionPlayers === undefined ) {
158140 actionPlayers = [ currentPlayer ] ;
159141 }
160142 }
@@ -179,9 +161,9 @@ export function UpdateTurnOrderState(G, ctx, turnOrder, endTurnArg) {
179161 * begins, and also a function `next` to determine who the
180162 * next player is when the turn ends.
181163 *
182- * first / next can also return an object of type
183- * { playOrderPos, actionPlayers }
184- * in which case they can also set actionPlayers simultaneously .
164+ * Objects can also contain an actionPlayers section which
165+ * is passed to SetActionPlayers above at the beginning of
166+ * the phase .
185167 *
186168 * The phase ends if next() returns undefined.
187169 */
@@ -217,16 +199,9 @@ export const TurnOrder = {
217199 * currentPlayer switches around in round-robin fashion, but any player can play on each turn.
218200 */
219201 ANY : {
220- first : ( G , ctx ) => {
221- return {
222- actionPlayers : [ ...ctx . playOrder ] ,
223- playOrderPos : ctx . playOrderPos ,
224- } ;
225- } ,
226- next : ( G , ctx ) => {
227- const playOrderPos = ( ctx . playOrderPos + 1 ) % ctx . playOrder . length ;
228- return { actionPlayers : [ ...ctx . playOrder ] , playOrderPos } ;
229- } ,
202+ first : ( G , ctx ) => ctx . playOrderPos ,
203+ next : ( G , ctx ) => ( ctx . playOrderPos + 1 ) % ctx . playOrder . length ,
204+ actionPlayers : { all : true } ,
230205 } ,
231206
232207 /**
0 commit comments