-
Notifications
You must be signed in to change notification settings - Fork 0
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
add lobby machine #25
Conversation
86303f2
to
df27551
Compare
df27551
to
21c7053
Compare
21c7053
to
d6a2336
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never used xstate
, but this feels like a good use of it, and is definitely a useful thing to understand.
I've left a couple of comments, they might be a result of my lack of recent context but hopefully they're helpful.
d6a2336
to
142b524
Compare
0d7d017
to
d2e837e
Compare
1feb860
to
0c64ca7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks great, but I've added a few things it might be good to clean up or think about before we merge this
docs/decisions/0002-use-game-class-to-interact-with-state-machine.md
Outdated
Show resolved
Hide resolved
docs/decisions/0002-use-game-class-to-interact-with-state-machine.md
Outdated
Show resolved
Hide resolved
1e00236
to
bd01c85
Compare
6f86fa1
to
9f05665
Compare
It is useful to seperate logs that we want to keep in the application with 'debugging' logs we put in temporarily.
Previously we only had Playwright tests but we will soon have unit tests too so we need to update the script/test file and package.json
We also add lobby.typgen.ts which is imported via the 'tsTypes' key in the 'createMachine' call on line 43. This is autogenerated by the VSCode XState extension and, despite guidance in the XState docs, should be committed in order for CI to pass.
I think we should use this class as the intermediary between the state machine and the rest of the application.
- If a player leaves ensure the correct action takes place - Change the state back to OnePlayer if the player count ever reaches 1 Add tests for changing state on player leaves If we remove the cap on two players, we should add an additional test for the condition (which checks that there is only one player left before changing back to `OnePlayer` state. We should also add tests for the number of players on action 'playerLeaves'.
We were previously switching to GameStart when two players had joined the game. Instead we are displaying a button on two players joining to make 'playerClicksStart' a user triggered event to transition to 'GameStart' Add a new test that more than 2 players can join, and that 'GameStart' state only exits if one player is left.
Test that playerLeaves action removes players from the context in each state
We only want to switch to OnePlayer state if there is one player left - same as in GameStart state
9f05665
to
6863941
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to unblock. Can refactor later if needed
This is an attempt at introducing an XState state machine to control the lobby behaviour as a proof of concept to see what using XState might look like if used across the whole app.
I have opted to use XState 4.x.x as it is better documented and I have more experience with it