Skip to content

Commit bff1d29

Browse files
committed
fix(flow): Run turn.endIf after setActivePlayers event
1 parent 064b750 commit bff1d29

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/core/flow.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {
10-
SetActivePlayersEvent,
1110
SetActivePlayers,
1211
UpdateActivePlayersOnceEmpty,
1312
InitTurnOrderState,
@@ -21,6 +20,7 @@ import * as logging from './logger';
2120
import type {
2221
ActionPayload,
2322
ActionShape,
23+
ActivePlayersArg,
2424
State,
2525
Ctx,
2626
LogEntry,
@@ -240,7 +240,7 @@ export function Flow({
240240
}
241241

242242
// Check if we should end the turn.
243-
if (fn === OnMove || fn === UpdateStage) {
243+
if ([OnMove, UpdateStage, UpdateActivePlayers].includes(fn)) {
244244
const shouldEndTurn = ShouldEndTurn(state);
245245
if (shouldEndTurn) {
246246
events.push({
@@ -392,6 +392,10 @@ export function Flow({
392392
return { ...state, ctx };
393393
}
394394

395+
function UpdateActivePlayers(state: State, { arg }): State {
396+
return { ...state, ctx: SetActivePlayers(state.ctx, arg) };
397+
}
398+
395399
///////////////
396400
// ShouldEnd //
397401
///////////////
@@ -685,6 +689,14 @@ export function Flow({
685689
return Process(state, [{ fn: EndStage, playerID }]);
686690
}
687691

692+
function SetActivePlayersEvent(
693+
state: State,
694+
_playerID: PlayerID,
695+
arg: ActivePlayersArg | PlayerID[]
696+
): State {
697+
return Process(state, [{ fn: UpdateActivePlayers, arg }]);
698+
}
699+
688700
function SetPhaseEvent(
689701
state: State,
690702
_playerID: PlayerID,

src/core/turn-order.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ import type {
1717
TurnConfig,
1818
} from '../types';
1919

20-
/**
21-
* Event to change the active players (and their stages) in the current turn.
22-
*/
23-
export function SetActivePlayersEvent(
24-
state: State,
25-
_playerID: PlayerID,
20+
export function SetActivePlayers(
21+
ctx: Ctx,
2622
arg: ActivePlayersArg | PlayerID[]
27-
) {
28-
return { ...state, ctx: SetActivePlayers(state.ctx, arg) };
29-
}
30-
31-
export function SetActivePlayers(ctx: Ctx, arg: ActivePlayersArg | PlayerID[]) {
23+
): Ctx {
3224
let activePlayers: typeof ctx.activePlayers = {};
3325
let _prevActivePlayers: typeof ctx._prevActivePlayers = [];
3426
let _nextActivePlayers: ActivePlayersArg | null = null;

0 commit comments

Comments
 (0)