Skip to content

Instantly share code, notes, and snippets.

@mobyjames
Created January 22, 2021 16:37
Show Gist options
  • Save mobyjames/3350f105dd97cfcde1664cbf10814bd4 to your computer and use it in GitHub Desktop.
Save mobyjames/3350f105dd97cfcde1664cbf10814bd4 to your computer and use it in GitHub Desktop.
const PlayStateMachine = Machine(
{
id: 'game',
initial: 'idle',
states: {
idle: {
on: {
INIT: 'waiting',
},
},
waiting: {
exit: ['stopWaiting'],
on: {
QUORUM: 'quorum',
},
},
quorum: {
on: {
QUORUM_FAIL: 'waiting',
START_GAME: 'newRound',
},
},
newRound: {
entry: ['beginRound'],
on: {
ROUND_READY: 'roundIntro',
QUORUM_FAIL: 'waiting',
NO_ARTISTS: 'quorum',
},
},
roundIntro: {
entry: ['beginRoundIntro'],
exit: ['stopTimer'],
on: {
TIMER: 'playing',
ARTIST_READY: 'playing',
ARTIST_SKIP: 'skipped',
ARTIST_LEAVE: 'newRound',
QUORUM_FAIL: 'waiting',
},
},
playing: {
entry: ['beginPlaying'],
exit: ['stopPlaying'],
on: {
TIMER: 'reveal',
ALL_ANSWERS: 'reveal',
ARTIST_LEAVE: 'newRound',
ARTIST_DERP: 'skipped',
QUORUM_FAIL: 'waiting',
},
},
skipped: {
entry: ['beginSkipped'],
exit: ['stopTimer'],
on: {
TIMER: 'newRound',
QUORUM_FAIL: 'waiting',
},
},
reveal: {
entry: ['beginReveal'],
exit: ['stopTimer'],
on: {
TIMER: 'newRound',
QUORUM_FAIL: 'waiting',
},
},
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment