Babylon state machine demo with xmachina

hi, I use state machines quite a bit - usually I just paste in code from previous projects :smiley: They are great for game logic (configurators, decisions, etc.) and UI generation or complex state management. I wanted something that was strongly typed and had an event mechanism to communicate changes (this lets my UI and components listen in on changes and adapt accordingly). I couldn’t find any options various reasons and made my own.

I created a library called xmachina and a demo with babylonjs that uses it. It’s a really contrived demo, because it could easily be done with the built-in babylonjs animations, but hopefully you can see the power available. It is a strongly typed state machine that has also a pub/sub on state or transition changes that can be registered using the exact same mechanism as babylonjs observables (I copied a bunch of /src/Misc/observable.ts). I wanted to borrow the masking capability of the observer, so you can subscribe to different groups of events like State changes or transitions (and additionally on specific events only). This creates reactive coding and allows multiple subscribers to just listen in an you can build a much cleaner design.

Live demo is up here and also all of the source code on github:
xmachina semáforo (