A typescript finite state machine library
Download the source file and add state-machine
to you project.
First define the states:
enum EHreoStatus {
stand,
kneel,
leap
}
A state machine can be constructed:
const option = {
init: EHreoStatus.stand,
transitions: {
squat: BuildTransition(EHreoStatus.stand, EHreoStatus.kneel),
standup: BuildTransition(EHreoStatus.kneel, EHreoStatus.stand),
jump: BuildTransition(EHreoStatus.stand, EHreoStatus.leap),
land: BuildTransition(EHreoStatus.leap, EHreoStatus.stand),
}
};
const fsm = new StateMachine(option);
Then you can transition to different state:
fsm.transition().squat();
fsm.transition().standup();
fsm.transition().jump();
fsm.transition().land();