Skip to content

Instantly share code, notes, and snippets.

@naosim
Created June 22, 2025 15:17
Show Gist options
  • Save naosim/f0ebef81a64dab1127084497c28fb874 to your computer and use it in GitHub Desktop.
Save naosim/f0ebef81a64dab1127084497c28fb874 to your computer and use it in GitHub Desktop.
nocodestate.mjs
const event = {
action: 'idle',
onGround: false
}
const stateMaChines = [
{
state: 'idle',
events: [
{event: {action:'move', onGround:true}, to: 'walk'},
{event: {action:'jump'}, to: 'airborne'},
{event: {onGround: false}, to: 'airborne'},
]
},
{
state: 'walk',
events: [
{event: {action:'stop', onGround:true}, to: 'idle'},
{event: {action:'jump'}, to: 'airborne'},
{event: {onGround: false}, to: 'airborne'},
]
},
{
state: 'airborne',
events: [
{event: {action:'stop', onGround:false}, to: 'idle'},
{event: {action:'move', onGround:false}, to: 'walk'},
]
},
];
class StateManager {
event = {}
constructor({initState, stateMaChines}) {
this.stateMaChines = stateMaChines;
this.state = initState;
}
resetEvent() {
this.event = {}
}
setEvent(event) {
this.event = {...this.event, ...event};
}
commit() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment