Skip to content

Commit ea3754b

Browse files
committed
player needs to be in actionPlayers in order to call events
1 parent 5024015 commit ea3754b

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

docs/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ analogous to a move, except that while a move changes
55
`G`, an event changes `ctx`. Also, events are provided by the
66
framework (as opposed to moves, which are written by you).
77

8-
Some events are enabled by default, and can be turned off if you dont want them. Others need to be explicity turned on in order to use them.
8+
Some events are enabled by default, and can be turned off if you dont want them. Others need to be explicity turned on in order to use them. Also note that only the current player can call events (and must also be an action player to do so).
99

1010
##### endTurn
1111

examples/react/turnorder/simulator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Board extends React.Component {
4747
));
4848

4949
const events = Object.entries(this.props.events)
50-
.filter(() => current)
50+
.filter(() => current && active)
5151
.filter(e => e[0] != 'setActionPlayers')
5252
.map(e => (
5353
<button key={e[0]} onClick={e[1]}>

src/core/flow.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ export function Flow({
100100
optimisticUpdate,
101101

102102
canPlayerCallEvent: (G, ctx, playerID) => {
103-
return ctx.currentPlayer == playerID;
103+
return (
104+
ctx.currentPlayer == playerID && ctx.actionPlayers.includes(playerID)
105+
);
104106
},
105107

106108
canPlayerMakeMove: (G, ctx, playerID) => {

src/core/flow.test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,20 @@ test('canPlayerCallEvent', () => {
506506

507507
let flow = Flow({});
508508
expect(flow.canPlayerCallEvent({}, {}, playerID)).toBe(false);
509-
expect(flow.canPlayerCallEvent({}, { actionPlayers: ['1'] }, playerID)).toBe(
510-
false
511-
);
512-
expect(flow.canPlayerCallEvent({}, { actionPlayers: ['0'] }, playerID)).toBe(
513-
false
514-
);
509+
expect(
510+
flow.canPlayerCallEvent(
511+
{},
512+
{ currentPlayer: '0', actionPlayers: ['1'] },
513+
playerID
514+
)
515+
).toBe(false);
516+
expect(
517+
flow.canPlayerCallEvent(
518+
{},
519+
{ currentPlayer: '0', actionPlayers: ['0'] },
520+
playerID
521+
)
522+
).toBe(true);
515523
});
516524

517525
test('endGame', () => {

0 commit comments

Comments
 (0)