Skip to content

WIP - Split state machines #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
simplify states
  • Loading branch information
ShMcK committed Jan 25, 2020
commit 072e25b4d1219a386c222373ef6d128e42da230a
44 changes: 18 additions & 26 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,32 @@ export interface MachineEvent {

export interface SelectTutorialMachineStateSchema {
states: {
Start: {
states: {
Startup: {}
Authenticate: {}
NewOrContinue: {}
SelectTutorial: {}
ContinueTutorial: {}
}
}
Startup: {}
Authenticate: {}
NewOrContinue: {}
SelectTutorial: {}
ContinueTutorial: {}
}
}

export interface PlayTutorialMachineStateSchema {
states: {
Tutorial: {
Initialize: {}
Summary: {}
LoadNext: {}
Level: {
states: {
Initialize: {}
Summary: {}
LoadNext: {}
Level: {
states: {
Load: {}
Normal: {}
TestRunning: {}
TestPass: {}
TestFail: {}
TestError: {}
StepNext: {}
LevelComplete: {}
}
}
Completed: {}
Load: {}
Normal: {}
TestRunning: {}
TestPass: {}
TestFail: {}
TestError: {}
StepNext: {}
LevelComplete: {}
}
}
Completed: {}
}
}

Expand Down
16 changes: 8 additions & 8 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ const Routes = () => {
return (
<Workspace>
<Router>
<Route path={['Start.Startup', 'Start.Authenticate', 'Start.NewOrContinue']}>
<Route path={['SelectTutorial.Startup', 'SelectTutorial.Authenticate', 'SelectTutorial.NewOrContinue']}>
<LoadingPage text="Launching..." context={{} as CR.MachineContext} />
</Route>
<Route path="Start.SelectTutorial">
<Route path="SelectTutorial.SelectTutorial">
<NewPage send={tempSend} context={{} as CR.MachineContext} />
</Route>
<Route path="Start.ContinueTutorial">
<Route path="SelectTutorial.ContinueTutorial">
<ContinuePage send={tempSend} context={{} as CR.MachineContext} />
</Route>
<Route path="Tutorial.Initialize">
<Route path="PlayTutorial.Initialize">
<LoadingPage text="Initializing..." context={{} as CR.MachineContext} />
</Route>
<Route path="Tutorial.LoadNext">
<Route path="PlayTutorial.LoadNext">
<LoadingPage text="Loading..." context={{} as CR.MachineContext} />
</Route>
<Route path="Tutorial.Summary">
<Route path="PlayTutorial.Summary">
<OverviewPage send={tempSend} context={{} as CR.MachineContext} />
</Route>
<Route path="Tutorial.Level">
<Route path="PlayTutorial.Level">
<LevelSummaryPage send={tempSend} context={{} as CR.PlayMachineContext} />
</Route>
<Route path="Tutorial.Completed">
<Route path="PlayTutorial.Completed">
<CompletedPage send={tempSend} context={{} as CR.PlayMachineContext} />
</Route>
</Router>
Expand Down
204 changes: 100 additions & 104 deletions web-app/src/services/state/playTutorial/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,136 +21,132 @@ export const playTutorialMachine = Machine<CR.PlayMachineContext, CR.PlayTutoria
},
processes: [],
},
id: 'tutorial',
initial: 'Initialize',
on: {
// track commands
COMMAND_START: {
actions: ['commandStart'],
},
COMMAND_SUCCESS: {
actions: ['commandSuccess'],
},
COMMAND_FAIL: {
actions: ['commandFail'],
},
ERROR: {
actions: ['setError'],
},
},
states: {
Tutorial: {
id: 'tutorial',
initial: 'Initialize',
// TODO move Initialize into New Tutorial setup
Initialize: {
onEntry: ['initializeTutorial'],
on: {
// track commands
COMMAND_START: {
actions: ['commandStart'],
},
COMMAND_SUCCESS: {
actions: ['commandSuccess'],
TUTORIAL_CONFIGURED: 'Summary',
// TUTORIAL_CONFIG_ERROR: 'Start' // TODO should handle error
},
},
Summary: {
on: {
LOAD_TUTORIAL: {
target: 'Level',
actions: ['initPosition', 'initTutorial'],
},
COMMAND_FAIL: {
actions: ['commandFail'],
},
},
LoadNext: {
id: 'tutorial-load-next',
onEntry: ['loadNext'],
on: {
NEXT_STEP: {
target: 'Level',
actions: ['updatePosition'],
},
ERROR: {
actions: ['setError'],
NEXT_LEVEL: {
target: 'Level', // TODO should return to levels summary page
actions: ['updatePosition'],
},
COMPLETED: '#completed-tutorial',
},
},
Level: {
initial: 'Load',
states: {
// TODO move Initialize into New Tutorial setup
Initialize: {
onEntry: ['initializeTutorial'],
on: {
TUTORIAL_CONFIGURED: 'Summary',
// TUTORIAL_CONFIG_ERROR: 'Start' // TODO should handle error
Load: {
onEntry: ['loadLevel', 'loadStep'],
after: {
0: 'Normal',
},
},
Summary: {
Normal: {
id: 'tutorial-level',
on: {
LOAD_TUTORIAL: {
target: 'Level',
actions: ['initPosition', 'initTutorial'],
TEST_RUNNING: 'TestRunning',
STEP_SOLUTION_LOAD: {
actions: ['editorLoadSolution'],
},
},
},
LoadNext: {
id: 'tutorial-load-next',
onEntry: ['loadNext'],
TestRunning: {
onEntry: ['testStart'],
on: {
NEXT_STEP: {
target: 'Level',
actions: ['updatePosition'],
},
NEXT_LEVEL: {
target: 'Level', // TODO should return to levels summary page
actions: ['updatePosition'],
TEST_PASS: {
target: 'TestPass',
actions: ['updateStepProgress'],
},
COMPLETED: '#completed-tutorial',
TEST_FAIL: 'TestFail',
TEST_ERROR: 'TestError',
},
},
Level: {
initial: 'Load',
states: {
Load: {
onEntry: ['loadLevel', 'loadStep'],
after: {
0: 'Normal',
},
},
Normal: {
id: 'tutorial-level',
on: {
TEST_RUNNING: 'TestRunning',
STEP_SOLUTION_LOAD: {
actions: ['editorLoadSolution'],
},
},
},
TestRunning: {
onEntry: ['testStart'],
on: {
TEST_PASS: {
target: 'TestPass',
actions: ['updateStepProgress'],
},
TEST_FAIL: 'TestFail',
TEST_ERROR: 'TestError',
},
},
TestError: {
onEntry: ['testFail'],
after: {
0: 'Normal',
},
},
TestPass: {
onExit: ['updateStepPosition'],
after: {
1000: 'StepNext',
},
},
TestFail: {
onEntry: ['testFail'],
after: {
0: 'Normal',
},
},
StepNext: {
onEntry: ['stepNext'],
on: {
LOAD_NEXT_STEP: {
target: 'Normal',
actions: ['loadStep'],
},
LEVEL_COMPLETE: {
target: 'LevelComplete',
actions: ['updateLevelProgress'],
},
},
TestError: {
onEntry: ['testFail'],
after: {
0: 'Normal',
},
},
TestPass: {
onExit: ['updateStepPosition'],
after: {
1000: 'StepNext',
},
},
TestFail: {
onEntry: ['testFail'],
after: {
0: 'Normal',
},
},
StepNext: {
onEntry: ['stepNext'],
on: {
LOAD_NEXT_STEP: {
target: 'Normal',
actions: ['loadStep'],
},
LevelComplete: {
on: {
LEVEL_NEXT: '#tutorial-load-next',
},
LEVEL_COMPLETE: {
target: 'LevelComplete',
actions: ['updateLevelProgress'],
},
},
},
Completed: {
id: 'completed-tutorial',
onEntry: ['userTutorialComplete'],
LevelComplete: {
on: {
SELECT_TUTORIAL: {
target: '#start-new-tutorial',
actions: ['reset'],
},
LEVEL_NEXT: '#tutorial-load-next',
},
},
},
},
Completed: {
id: 'completed-tutorial',
onEntry: ['userTutorialComplete'],
on: {
SELECT_TUTORIAL: {
type: 'final',
actions: ['reset'],
},
},
},
},
},
options,
Expand Down
Loading