Last active
October 16, 2019 02:40
-
-
Save uliang/452f55ba92e1f17a6f89c27d77682bac to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Application = Machine({ | |
| id: 'app', | |
| initial: 'ready', | |
| states: { | |
| ready: { | |
| initial: 'ok', | |
| on: { | |
| NewGame: "characterCreation", | |
| LoadGame: 'loadCharacter' | |
| }, | |
| states: { | |
| ok: {}, | |
| error: {} | |
| } | |
| }, | |
| characterCreation: { | |
| initial: 'begin', | |
| entry: ['spawnNewPC', 'spawnAC'], | |
| states: { | |
| begin: { | |
| on: { | |
| GetBookList: 'loading' | |
| }, | |
| }, | |
| loading: { | |
| invoke: { | |
| id: 'fetchBookList', | |
| src: 'fetchBookListPromise', | |
| onDone: { | |
| target:'#app.bookList', | |
| actions: ['assignBookList'] | |
| }, | |
| onError: { | |
| target:'#app.ready.error', | |
| actions:['stopNewPC', 'stopAC'] | |
| } | |
| } | |
| }, | |
| } | |
| }, | |
| bookList: { | |
| on: { | |
| UpdateBookChoice: { | |
| target: 'construction', | |
| actions: ['spawnBook'] | |
| } | |
| } | |
| }, | |
| construction: { | |
| invoke: { | |
| id: 'newCharacterFactory', | |
| src: 'newCharacterFactoryMachine', | |
| onDone: 'saving' | |
| }, | |
| exit: ['stopNewPC'] | |
| }, | |
| saving: { | |
| entry: ['sendSaveData'], | |
| on: { | |
| Success: 'playing' | |
| }, | |
| exit: ['spawnReturningPC'] | |
| }, | |
| loadCharacter: { | |
| initial: 'begin', | |
| entry: ['spawnReturningPC'], | |
| states: { | |
| begin: { | |
| on: { | |
| GetPreviousSaves: 'loading' | |
| } | |
| }, | |
| loading: { | |
| invoke:{ | |
| id: 'fetchSavedGames', | |
| src: 'fetchSavedGamesPromise', | |
| onError: { | |
| target: '#app.ready.error', | |
| actions: ['stopReturningPC'], | |
| }, | |
| onDone: { | |
| target:'display', | |
| actions: ['assignSavedGameList'] | |
| } | |
| } | |
| }, | |
| display: { | |
| on: { | |
| LoadGame: '#app.loading' | |
| } | |
| } | |
| } | |
| }, | |
| loading: { | |
| invoke: { | |
| id: 'fetchThisGame', | |
| src: 'fetchThisGamePromise', | |
| onError: { | |
| target: '#app.loadCharacter', | |
| actions: ['stopReturningPC'] | |
| }, | |
| onDone: { | |
| target:'playing', | |
| actions: ['spawnAC', 'spawnBook'] | |
| } | |
| } | |
| }, | |
| playing: { | |
| on: { | |
| Save: 'saving', | |
| SaveNQuit: { | |
| target: 'cleanup' | |
| } | |
| }, | |
| exit:['stopReturningPC'] | |
| }, | |
| cleanup: { | |
| entry: ['sendSaveData'], | |
| exit: ['stopBook', 'stopAC'], | |
| on: { | |
| Success: '#app.ready' | |
| } | |
| } | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment