Skip to content

Instantly share code, notes, and snippets.

@Radek-Palisa
Last active March 21, 2020 23:05
Show Gist options
  • Save Radek-Palisa/13779b607d96c75907afdca395c2daea to your computer and use it in GitHub Desktop.
Save Radek-Palisa/13779b607d96c75907afdca395c2daea to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'game',
initial: 'idle',
context: {
activePlayer: 0,
startingPlayer: 2,
deckDungeon: ['1a', '1b', '1c', '1d'],
deckTreasure: ['2a', '2b', '2c', '2d'],
activeCard: '',
},
states: {
idle: {
on: {
START: {
target: 'turnStart',
actions: assign({
activePlayer: ctx => ctx.startingPlayer,
}),
},
},
},
turnStart: {
on: {
NEXT: {
target: 'doorListen',
actions: assign({
activeCard: ctx => ctx.deckTreasure[0],
deckTreasure: ctx => {
const [fist, ...rest] = ctx.deckTreasure;
return rest
}
}),
},
}
},
doorListen: {
on: {
KEEP: "doorKick",
COMBAT: "combat",
},
},
doorKick: {
on: {
KEEP: "sack",
COMBAT: "combat",
}
},
combat: {
on: {
NEXT: {
target: "turnEnd",
cond: (ctx, e) => {
console.log('HEEELO', e);
return true
}
},
DOOR_KICK: "doorKick",
}
},
sack: {
on: {
NEXT: "turnEnd",
}
},
turnEnd: {
on: {
NEXT: "turnStart"
}
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment