Skip to content

Commit

Permalink
Merge branch 'phases-overhaul' into delucis/stages-once-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Aug 23, 2019
2 parents cc4690c + 22c45cd commit 3d80788
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/core/events.js
Expand Up @@ -24,10 +24,11 @@ export class Events {
*/
attach(ctx) {
const events = {};
const { phase, turn } = ctx;

for (const key of this.flow.eventNames) {
events[key] = (...args) => {
this.dispatch.push({ key, args });
this.dispatch.push({ key, args, phase, turn });
};
}

Expand All @@ -42,7 +43,21 @@ export class Events {
const length = this.dispatch.length;
for (let i = 0; i < length; i++) {
const item = this.dispatch[i];

// If the turn already ended some other way,
// don't try to end the turn again.
if (item.key === 'endTurn' && item.turn !== state.ctx.turn) {
continue;
}

// If the phase already ended some other way,
// don't try to end the phase again.
if (item.key === 'endPhase' && item.phase !== state.ctx.phase) {
continue;
}

const action = automaticGameEvent(item.key, item.args, this.playerID);

state = {
...state,
...this.flow.processGameEvent(state, action),
Expand Down

0 comments on commit 3d80788

Please sign in to comment.