Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6993147

Browse files
committed
add machine loadTutorial
1 parent4be011f commit6993147

File tree

3 files changed

+182
-105
lines changed

3 files changed

+182
-105
lines changed

‎src/state/actions/index.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import{send}from"xstate";
1+
import{assign,send}from'xstate'
2+
import*asCRfrom'typings'
23
import*asstoragefrom'../../services/storage'
34
import*asgitfrom'../../services/git'
45

6+
letinitialTutorial:CR.Tutorial|undefined
7+
letinitialProgress:CR.Progress={
8+
levels:{},
9+
stages:{},
10+
steps:{},
11+
complete:false,
12+
}
13+
514
exportdefault{
615
start:async()=>{
716
const[tutorial,progress,hasGit,hasGitRemote]=awaitPromise.all([
@@ -10,7 +19,38 @@ export default {
1019
git.gitVersion(),
1120
git.gitCheckRemoteExists(),
1221
])
22+
initialTutorial=tutorial
23+
initialProgress=progress
1324
constcanContinue=!!(tutorial&&progress&&hasGit&&hasGitRemote)
1425
send(canContinue ?'CONTINUE' :'NEW')
15-
}
26+
},
27+
loadTutorial:assign({
28+
// load initial data, progress & position
29+
data():CR.TutorialData{
30+
if(!initialTutorial){
31+
thrownewError('No Tutorial loaded')
32+
}
33+
returninitialTutorial.data
34+
35+
},
36+
progress():CR.Progress{returninitialProgress},
37+
position(){
38+
if(!initialTutorial){
39+
thrownewError('No Tutorial loaded')
40+
}
41+
const{ data}=initialTutorial
42+
43+
constlevelId=data.summary.levelList[0]
44+
conststageId=data.levels[levelId].stageList[0]
45+
conststepId=data.stages[stageId].stepList[0]
46+
47+
constposition={
48+
levelId,
49+
stageId,
50+
stepId,
51+
}
52+
53+
returnposition
54+
}
55+
}),
1656
}

‎src/state/machine.ts

Lines changed: 114 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -15,120 +15,144 @@ export const tutorialMachine = Machine<
1515
{
1616
id:'tutorial',
1717
context:initialContext,
18-
initial:'initial',
18+
initial:'Start',
1919
states:{
20-
initial:{
21-
onEntry:'start',
22-
on:{
23-
CONTINUE:'continue',
24-
NEW:'new',
25-
},
26-
},
27-
new:{
28-
on:{
29-
TUTORIAL_START:'loading',
30-
},
31-
},
32-
continue:{
33-
on:{
34-
TUTORIAL_START:'loading',
35-
},
36-
},
37-
loading:{
38-
on:{
39-
TUTORIAL_LOADED:[
40-
{
41-
target:'summary',
42-
cond:'hasNoProgress',
43-
},
44-
{
45-
target:'level',
46-
cond:'hasNoLevelProgress',
47-
},
48-
{
49-
target:'stage',
50-
},
51-
],
52-
},
53-
},
54-
summary:{
55-
on:{
56-
NEXT:'level',
57-
},
58-
},
59-
level:{
60-
onEntry:['loadLevel'],
61-
on:{
62-
NEXT:'stage',
63-
BACK:'summary',
64-
},
65-
},
66-
stage:{
67-
onEntry:['loadStage'],
68-
initial:'stageNormal',
20+
Start:{
6921
states:{
70-
stageNormal:{
22+
Initial:{
23+
onEntry:'start',
7124
on:{
72-
TEST_RUN:'testRunning',
73-
STEP_SOLUTION_LOAD:{
74-
actions:['callSolution'],
75-
},
25+
CONTINUE:'ContinueTutorial',
26+
NEW:'NewTutorial',
7627
},
7728
},
78-
testRunning:{
79-
on:{
80-
TEST_SUCCESS:[
81-
{
82-
target:'complete',
83-
cond:'tasksComplete',
29+
NewTutorial:{
30+
initial:'SelectTutorial',
31+
states:{
32+
SelectTutorial:{
33+
on:{
34+
TUTORIAL_START:'InitializeTutorial',
8435
},
85-
{
86-
target:'testPass',
87-
},
88-
],
89-
TEST_FAILURE:'testFail',
90-
},
36+
},
37+
InitializeTutorial:{
38+
on:{
39+
TUTORIAL_LOADED:'Tutorial'
40+
}
41+
},
42+
}
43+
44+
},
45+
ContinueTutorial:{
46+
onEntry:'loadTutorial',
47+
on:{
48+
TUTORIAL_START:{
49+
target:'Tutorial',
50+
}
51+
}
9152
},
92-
testPass:{
93-
onEntry:['stepComplete'],
53+
}
54+
},
55+
Tutorial:{
56+
initial:'Initialize',
57+
states:{
58+
Initialize:{
9459
on:{
95-
NEXT:[
60+
TUTORIAL_LOADED:[
61+
{
62+
target:'Summary',
63+
cond:'hasNoProgress',
64+
},
9665
{
97-
target:'stageNormal',
98-
cond:'hasNextStep',
66+
target:'Level',
67+
cond:'hasNoLevelProgress',
9968
},
10069
{
101-
target:'stageComplete',
70+
target:'Stage',
10271
},
10372
],
10473
},
10574
},
106-
testFail:{
75+
76+
Summary:{
10777
on:{
108-
RETURN:'stageNormal',
78+
NEXT:'Level',
10979
},
11080
},
111-
stageComplete:{
81+
Level:{
82+
onEntry:['loadLevel'],
11283
on:{
113-
NEXT:[
114-
{
115-
target:'stage',
116-
cond:'hasNextStage',
84+
NEXT:'Stage',
85+
BACK:'Summary',
86+
},
87+
},
88+
Stage:{
89+
onEntry:['loadStage'],
90+
initial:'StageNormal',
91+
states:{
92+
StageNormal:{
93+
on:{
94+
TEST_RUN:'TestRunning',
95+
STEP_SOLUTION_LOAD:{
96+
actions:['callSolution'],
97+
},
11798
},
118-
{
119-
target:'level',
120-
cond:'hasNextLevel',
99+
},
100+
TestRunning:{
101+
on:{
102+
TEST_SUCCESS:[
103+
{
104+
target:'StageComplete',
105+
cond:'tasksComplete',
106+
},
107+
{
108+
target:'TestPass',
109+
},
110+
],
111+
TEST_FAILURE:'TestFail',
121112
},
122-
{
123-
target:'complete',
113+
},
114+
TestPass:{
115+
onEntry:['stepComplete'],
116+
on:{
117+
NEXT:[
118+
{
119+
target:'StageNormal',
120+
cond:'hasNextStep',
121+
},
122+
{
123+
target:'StageComplete',
124+
},
125+
],
124126
},
125-
],
127+
},
128+
TestFail:{
129+
on:{
130+
RETURN:'StageNormal',
131+
},
132+
},
133+
StageComplete:{
134+
on:{
135+
NEXT:[
136+
{
137+
target:'Stage',
138+
cond:'hasNextStage',
139+
},
140+
{
141+
target:'Level',
142+
cond:'hasNextLevel',
143+
},
144+
{
145+
target:'EndTutorial',
146+
},
147+
],
148+
},
149+
},
126150
},
127151
},
128-
},
129-
},
130-
complete:{},
131-
},
152+
EndTutorial:{},
153+
}
154+
}
155+
}
132156
},
133157
{
134158
actions,

‎src/typings/index.d.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,34 @@ export interface MachineEvent {
129129

130130
exportinterfaceMachineStateSchema{
131131
states:{
132-
initial:{}
133-
new:{}
134-
continue:{}
135-
loading:{}
136-
summary:{}
137-
level:{}
138-
stage:{
132+
Start:{
139133
states:{
140-
stageNormal:{}
141-
testRunning:{}
142-
testPass:{}
143-
testFail:{}
144-
stageComplete:{}
134+
Initial:{}
135+
NewTutorial:{
136+
states:{
137+
SelectTutorial:{}
138+
InitializeTutorial:{}
139+
}
140+
}
141+
ContinueTutorial:{}
142+
}
143+
}
144+
Tutorial:{
145+
states:{
146+
Initialize:{}
147+
Summary:{}
148+
Level:{}
149+
Stage:{
150+
states:{
151+
StageNormal:{}
152+
TestRunning:{}
153+
TestPass:{}
154+
TestFail:{}
155+
StageComplete:{}
156+
}
157+
}
158+
EndTutorial:{}
145159
}
146160
}
147-
complete:{}
148161
}
149162
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp