Skip to content

Commit

Permalink
player needs to be in actionPlayers in order to call events
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Oct 19, 2018
1 parent 5024015 commit ea3754b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ analogous to a move, except that while a move changes
`G`, an event changes `ctx`. Also, events are provided by the
framework (as opposed to moves, which are written by you).

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.
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).

##### endTurn

Expand Down
2 changes: 1 addition & 1 deletion examples/react/turnorder/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Board extends React.Component {
));

const events = Object.entries(this.props.events)
.filter(() => current)
.filter(() => current && active)
.filter(e => e[0] != 'setActionPlayers')
.map(e => (
<button key={e[0]} onClick={e[1]}>
Expand Down
4 changes: 3 additions & 1 deletion src/core/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export function Flow({
optimisticUpdate,

canPlayerCallEvent: (G, ctx, playerID) => {
return ctx.currentPlayer == playerID;
return (
ctx.currentPlayer == playerID && ctx.actionPlayers.includes(playerID)
);
},

canPlayerMakeMove: (G, ctx, playerID) => {
Expand Down
20 changes: 14 additions & 6 deletions src/core/flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,20 @@ test('canPlayerCallEvent', () => {

let flow = Flow({});
expect(flow.canPlayerCallEvent({}, {}, playerID)).toBe(false);
expect(flow.canPlayerCallEvent({}, { actionPlayers: ['1'] }, playerID)).toBe(
false
);
expect(flow.canPlayerCallEvent({}, { actionPlayers: ['0'] }, playerID)).toBe(
false
);
expect(
flow.canPlayerCallEvent(
{},
{ currentPlayer: '0', actionPlayers: ['1'] },
playerID
)
).toBe(false);
expect(
flow.canPlayerCallEvent(
{},
{ currentPlayer: '0', actionPlayers: ['0'] },
playerID
)
).toBe(true);
});

test('endGame', () => {
Expand Down

0 comments on commit ea3754b

Please sign in to comment.