Created
March 20, 2020 10:21
-
-
Save chrishyle/8c6e6080c21780e96d33e19fd62fe5d1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gameMachine = Machine( | |
{ | |
id: "game", | |
initial: "nogame", | |
context: { | |
players: [], | |
roles: [ | |
{ | |
name: "1", | |
isActive: true | |
} | |
] | |
}, | |
states: { | |
nogame: { | |
on: { | |
CREATE: "notReadyToDeal" | |
} | |
}, | |
notReadyToDeal: { | |
states: { | |
tooFewPlayers: {}, | |
tooFewCards: {}, | |
tooManyCards: {}, | |
tooManyPlayers: {} | |
}, | |
"": [{ target: "readyToDeal", cond: "playersAndRolesMatch" }] | |
}, | |
readyToDeal: {}, | |
notReadyToStart: {}, | |
readyToStart: {} | |
} | |
}, | |
{ | |
guards: { | |
playersAndRolesMatch: (context, event) => { | |
const { players, roles } = context; | |
const numAactiveRoles = roles.filter(role => role.isActive).length; | |
const target = players.length + 3; | |
return target === numAactiveRoles; | |
// if (target === numAactiveRoles) { | |
// game.state = GameStates.ready; | |
// game.validationError = ""; | |
// return; | |
// } | |
// const numRolesOff = target - numAactiveRoles; | |
// const moreOrFewer = numRolesOff > 0 ? "more" : "fewer"; | |
// game.state = GameStates.invalid; | |
// game.validationError = `Please select ${Math.abs( | |
// numRolesOff | |
// )} ${moreOrFewer} roles.`; | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment