Skip to content

Instantly share code, notes, and snippets.

@tmbritton
Last active May 2, 2021 03:07
Show Gist options
  • Save tmbritton/48cb49273535f1254e3fb879dbd9d1b8 to your computer and use it in GitHub Desktop.
Save tmbritton/48cb49273535f1254e3fb879dbd9d1b8 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const turnMachine = Machine({
id: 'turn',
initial: 'beginning',
states: {
beginning: {
initial: 'untap',
states: {
untap: {
entry: sendParent({type: 'UNTAP_STEP_START'}),
exit: sendParent({type: 'UNTAP_STEP_END'}),
on: {
'ADVANCE_STEP': {target: 'upkeep'}
}
},
upkeep: {
entry: sendParent({type: 'UPKEEP_STEP_START'}),
exit: sendParent({type: 'UPKEEP_STEP_END'}),
on: {
'ADVANCE_STEP': {target: 'draw'}
}
},
draw: {
entry: sendParent({type: 'DRAW_STEP_START'}),
exit: sendParent({type: 'DRAW_STEP_END'}),
on: {
'ADVANCE_STEP': {target: '#turn.main'}
}
},
}
},
main: {
initial: 'firstMain',
states: {
firstMain: {
entry: sendParent({type: 'FIRST_MAIN_STEP_START'}),
exit: sendParent({type: 'FIRST_MAIN_STEP_END'}),
on: {
'ADVANCE_STEP': {target: 'attackStep'}
}
},
attackStep: {
inital: 'makeChoice',
entry: sendParent({type: 'ATTACK_STEP_START'}),
exit: sendParent({type: 'ATTACK_STEP_END'}),
states: {
makeChoice: {
on: {
'ATTACK': {target: 'attack'},
'SKIP_ATTACK': {target: '#turn.main.secondMain'}
}
},
attack: {
initial: 'chooseAttackers',
states: {
chooseAttackers: {
entry: sendParent({type: 'CHOOSE_ATTACKERS_STEP_START'}),
exit: sendParent({type: 'CHOOSE_ATTACKERS_STEP_END'}),
on: {
'ADVANCE_STEP': {target: 'chooseBlockers'}
}
},
chooseBlockers: {
entry: sendParent({type: 'CHOOSE_BLOCKERS_STEP_START'}),
exit: sendParent({type: 'CHOOSE_BLOCKERS_STEP_END'}),
on: {
'ADVANCE_STEP': {target: 'resolveDamage'}
}
},
resolveDamage: {
entry: sendParent({type: 'RESOLVE_DAMAGE_STEP_START'}),
exit: sendParent({type: 'RESOLVE_DAMAGE_STEP_END'}),
on: {
'ADVANCE_STEP': {target: '#turn.main.secondMain'}
}
}
}
}
},
},
secondMain: {
entry: sendParent({type: 'SECOND_MAIN_STEP_START'}),
exit: sendParent({type: 'SECOND_MAIN_STEP_END'}),
on: {
'ADVANCE_STEP': {target: '#turn.end'}
}
}
}
},
end: {
type: 'final',
entry: sendParent({type: 'END_STEP_START'}),
exit: sendParent({type: 'END_STEP_END'}),
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment