Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add endStage and setStage events #458

Merged
merged 21 commits into from
Sep 18, 2019
Merged

feat: Add endStage and setStage events #458

merged 21 commits into from
Sep 18, 2019

Conversation

delucis
Copy link
Member

@delucis delucis commented Sep 15, 2019

Closes #445
Closes #446
Closes #447
🎉

I have tried adding the endStage and setStage events as discussed in #445, #446 and #447.

I’m most of the way there, but ran into a roadblock with adding the moveLimit option for setStage. If I understood correctly (and I’ll admit I felt a little lost reading through all the event-related code), when calling an event from the client, the single passed argument is used as the payload for the action sent to the reducer. So that makes my imagined syntax of setStage('B', { moveLimit: 2 }) not as trivial to implement as I imagined.

Presumably there would need to be a wrapper somewhere that formats arguments to client events so that supporting a second optional argument is possible, but I’m not sure exactly where or how that should be implemented.

In the meantime, I have added a failing test for moveLimit and UpdateStage in flow.js does contain the correct logic to hypothetically update ctx were the moveLimit argument to reach it. If you have any pointers, I can try to implement something, or if you prefer to get this merged without the moveLimit support, I can strip those parts out to be figured out later.

This moves the logic that resets an empty `activePlayers` to next, 
previous or `null` values into `UpdateActivePlayers`, so that it can be 
called from an `EndStage` event and not just inside `ProcessMove`.
@delucis delucis closed this Sep 15, 2019
@delucis delucis reopened this Sep 15, 2019
@delucis delucis changed the title [WIP [WIP] feat: Add endStage and setStage events Sep 15, 2019
@nicolodavis
Copy link
Member

The easiest solution might be to use the short form / long form pattern that we follow elsewhere.

setStage('B')
setStage({ stage: 'B, moveLimit: 2 })

So now you only have one argument.

@delucis
Copy link
Member Author

delucis commented Sep 16, 2019

Oh, right, good idea. I’ll go with that for now :-)

@delucis
Copy link
Member Author

delucis commented Sep 16, 2019

@nicolodavis How should I test for the automatic option to endStage and should it even exist? I’m guessing for endPhase and endTurn this is passed when it is called from endIf, which isn’t currently available for stages.

@nicolodavis
Copy link
Member

The only "automatic" end of stage that we have right now is triggered via moveLimit. Maybe have ProcessMove call EndStage and pass automatic: true?

@delucis
Copy link
Member Author

delucis commented Sep 16, 2019

OK!

One thing: right now endStage and setStage operate on currentPlayer only, but moveLimit can remove any active player. I’ll try adding a playerID optional argument that is used internally by ProcessMove.

If I understood correctly, events are only callable by currentPlayer right? What if an active player that is not the current player wants to endStage from a move? Would that work?

@nicolodavis
Copy link
Member

If I understood correctly, events are only callable by currentPlayer right? What if an active player that is not the current player wants to endStage from a move? Would that work?

We might have to relax the condition. Maybe let's have any player that is "active" (i.e. one of the activePlayers if it is set OR currentPlayer if it is not set) be able to call events?

@delucis
Copy link
Member Author

delucis commented Sep 16, 2019

let's have any player that is "active" (i.e. one of the activePlayers if it is set OR currentPlayer if it is not set) be able to call events?

That makes sense to me. I guess at some point some config for what events are enabled etc. might be needed, but for now stages are the loosest of all the game elements. (Unlike phases there are no checks that a stage is actually declared when setting it and at the moment they only declare moves.)

I’m not sure exactly how to go about those changes, so I’ll proceed like I suggested with ProcessMove and EndStage as that doesn’t need the changes to events in general.

@nicolodavis
Copy link
Member

Thanks again for getting the phases-overhaul effort over the finish line!

Allow a `playerID` to be passed to `EndStage` and `UpdateStage` so they 
can be used to end/update any player in `activePlayers`. They default to 
`ctx.currentPlayer` when called from the client, which could need 
changing once any active player can call events.
@delucis
Copy link
Member Author

delucis commented Sep 16, 2019

It’s been fun slowly figuring out how all the internals work!

ProcessMove now uses EndStage as you suggested — avoids some code duplication too, which is nice.

@delucis delucis changed the title [WIP] feat: Add endStage and setStage events feat: Add endStage and setStage events Sep 16, 2019
@delucis
Copy link
Member Author

delucis commented Sep 16, 2019

OK, I think this is good to go. Test coverage is just missing one branch where events.setStage passed to Flow is not undefined. Haven’t fixed that yet because I noticed that at the end of Flow, events.endPhase is used to enable both the endPhase and startPhase events. I copied that pattern for setStage and endStage, but if I’ve understood everything correctly this means that passing

Flow({
  events: {
    setStage: false,
    setPhase: false,
  },
});

will not actually have any effect. So I guess, maybe the logic that sets events.setStage and events.setPhase to true is redundant and should be removed? (All tests still passed when I tried removing them.)

@delucis
Copy link
Member Author

delucis commented Sep 16, 2019

Also, just realised this will resolve everything in #445 #446 & #447 😄 🎉

src/core/flow.js Show resolved Hide resolved
src/core/flow.js Show resolved Hide resolved
src/core/flow.js Show resolved Hide resolved
src/core/turn-order.js Outdated Show resolved Hide resolved
@nicolodavis nicolodavis merged commit b2f5160 into boardgameio:master Sep 18, 2019
@delucis delucis deleted the delucis/stage-events branch September 18, 2019 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transitioning between stages removing players from activePlayers reset behavior of activePlayers
2 participants