@@ -28,7 +28,7 @@ export default {
28
28
return event . payload . tutorial
29
29
} ,
30
30
progress :( ) :CR . Progress => {
31
- return { levels :{ } , stages : { } , steps :{ } , complete :false }
31
+ return { levels :{ } , steps :{ } , complete :false }
32
32
}
33
33
} ) ,
34
34
initTutorial :assign ( {
@@ -74,41 +74,20 @@ export default {
74
74
} ,
75
75
} ) ,
76
76
//@ts -ignore
77
- updateStagePosition :assign ( {
78
- position :( context :CR . MachineContext ) :CR . Position => {
79
- const { position} = context
80
-
81
- const level :G . Level = selectors . currentLevel ( context )
82
- const stages :G . Stage [ ] = level . stages
83
-
84
- const stageIndex = stages . findIndex ( ( s :G . Stage ) => s . id === position . stageId )
85
- const stage :G . Stage = stages [ stageIndex + 1 ]
86
-
87
- const nextPosition :CR . Position = {
88
- ...position ,
89
- stageId :stage . id ,
90
- stepId :stage . steps [ 0 ] . id ,
91
- }
92
-
93
- return nextPosition
94
- } ,
95
- } ) ,
96
- //@ts -ignore
97
77
updateLevelPosition :assign ( {
98
78
position :( context :CR . MachineContext ) :CR . Position => {
99
79
const { position} = context
100
80
const version = selectors . currentVersion ( context )
101
81
// merge in the updated position
102
82
// sent with the test to ensure consistency
103
- const levels :G . Level [ ] = version . levels
83
+ const levels :G . Level [ ] = version . data . levels
104
84
105
85
const levelIndex = levels . findIndex ( ( l :G . Level ) => l . id === position . levelId )
106
86
const level :G . Level = levels [ levelIndex + 1 ]
107
87
108
88
const nextPosition :CR . Position = {
109
89
levelId :level . id ,
110
- stageId :level . stages [ 0 ] . id ,
111
- stepId :level . stages [ 0 ] . steps [ 0 ] . id ,
90
+ stepId :level . steps [ 0 ] . id ,
112
91
}
113
92
114
93
return nextPosition
@@ -128,19 +107,6 @@ export default {
128
107
} ,
129
108
} ) ,
130
109
//@ts -ignore
131
- updateStageProgress :assign ( {
132
- progress :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
133
- // update progress by tracking completed
134
- const { progress, position} = context
135
-
136
- const stageId :string = position . stageId
137
-
138
- progress . stages [ stageId ] = true
139
-
140
- return progress
141
- } ,
142
- } ) ,
143
- //@ts -ignore
144
110
updatePosition :assign ( {
145
111
position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
146
112
const { position} = event . payload
@@ -152,9 +118,8 @@ export default {
152
118
153
119
const version = selectors . currentVersion ( context )
154
120
const level = selectors . currentLevel ( context )
155
- const stage = selectors . currentStage ( context )
156
121
157
- const steps :G . Step [ ] = stage . steps
122
+ const steps :G . Step [ ] = level . steps
158
123
159
124
const stepIndex = steps . findIndex ( ( s :G . Step ) => s . id === position . stepId )
160
125
const stepComplete = progress . steps [ position . stepId ]
@@ -168,39 +133,19 @@ export default {
168
133
return { type :'NEXT_STEP' , payload :{ position :nextPosition } }
169
134
}
170
135
171
- // has next stage?
172
-
173
- const { stages} = level
174
- const stageIndex = stages . findIndex ( ( s :G . Stage ) => s . id === position . stageId )
175
- const finalStage = ( stageIndex > - 1 && stageIndex === stages . length - 1 )
176
- const hasNextStage = ( ! finalStage )
177
-
178
- // NEXT STAGE
179
- if ( hasNextStage ) {
180
- const nextStage = stages [ stageIndex + 1 ]
181
- const nextPosition = {
182
- levelId :position . levelId ,
183
- stageId :nextStage . id ,
184
- stepId :nextStage . steps [ 0 ] . id ,
185
- }
186
- return { type :'NEXT_STAGE' , payload :{ position :nextPosition } }
187
- }
188
-
189
136
// has next level?
190
137
191
- const { levels} = version
138
+ const levels = context ?. tutorial ?. version . data . levels ?? [ ]
192
139
const levelIndex = levels . findIndex ( ( l :G . Level ) => l . id === position . levelId )
193
140
const finalLevel = ( levelIndex > - 1 && levelIndex === levels . length - 1 )
194
141
const hasNextLevel = ( ! finalLevel )
195
142
196
143
// NEXT LEVEL
197
144
if ( hasNextLevel ) {
198
145
const nextLevel = levels [ levelIndex + 1 ]
199
- const nextStage = nextLevel . stages [ 0 ]
200
146
const nextPosition = {
201
147
levelId :nextLevel . id ,
202
- stageId :nextStage . id ,
203
- stepId :nextStage . steps [ 0 ] . id ,
148
+ stepId :nextLevel . steps [ 0 ] . id ,
204
149
}
205
150
return { type :'NEXT_LEVEL' , payload :{ position :nextPosition } }
206
151
}
@@ -211,9 +156,9 @@ export default {
211
156
stepNext :send ( ( context :CR . MachineContext ) :CR . Action => {
212
157
const { position, progress} = context
213
158
214
- const stage :G . Stage = selectors . currentStage ( context )
159
+ const level :G . Level = selectors . currentLevel ( context )
215
160
216
- const { steps} = stage
161
+ const { steps} = level
217
162
// TODO: verify not -1
218
163
const stepIndex = steps . findIndex ( ( s :G . Step ) => s . id === position . stepId )
219
164
const finalStep = stepIndex === steps . length - 1