@@ -28,7 +28,7 @@ export default {
2828return event . payload . tutorial
2929} ,
3030progress :( ) :CR . Progress => {
31- return { levels :{ } , stages : { } , steps :{ } , complete :false }
31+ return { levels :{ } , steps :{ } , complete :false }
3232}
3333} ) ,
3434initTutorial :assign ( {
@@ -74,41 +74,20 @@ export default {
7474} ,
7575} ) ,
7676//@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
9777updateLevelPosition :assign ( {
9878position :( context :CR . MachineContext ) :CR . Position => {
9979const { position} = context
10080const version = selectors . currentVersion ( context )
10181// merge in the updated position
10282// sent with the test to ensure consistency
103- const levels :G . Level [ ] = version . levels
83+ const levels :G . Level [ ] = version . data . levels
10484
10585const levelIndex = levels . findIndex ( ( l :G . Level ) => l . id === position . levelId )
10686const level :G . Level = levels [ levelIndex + 1 ]
10787
10888const nextPosition :CR . Position = {
10989levelId :level . id ,
110- stageId :level . stages [ 0 ] . id ,
111- stepId :level . stages [ 0 ] . steps [ 0 ] . id ,
90+ stepId :level . steps [ 0 ] . id ,
11291}
11392
11493return nextPosition
@@ -128,19 +107,6 @@ export default {
128107} ,
129108} ) ,
130109//@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
144110updatePosition :assign ( {
145111position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
146112const { position} = event . payload
@@ -152,9 +118,8 @@ export default {
152118
153119const version = selectors . currentVersion ( context )
154120const level = selectors . currentLevel ( context )
155- const stage = selectors . currentStage ( context )
156121
157- const steps :G . Step [ ] = stage . steps
122+ const steps :G . Step [ ] = level . steps
158123
159124const stepIndex = steps . findIndex ( ( s :G . Step ) => s . id === position . stepId )
160125const stepComplete = progress . steps [ position . stepId ]
@@ -168,39 +133,19 @@ export default {
168133return { type :'NEXT_STEP' , payload :{ position :nextPosition } }
169134}
170135
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-
189136// has next level?
190137
191- const { levels} = version
138+ const levels = context ?. tutorial ?. version . data . levels ?? [ ]
192139const levelIndex = levels . findIndex ( ( l :G . Level ) => l . id === position . levelId )
193140const finalLevel = ( levelIndex > - 1 && levelIndex === levels . length - 1 )
194141const hasNextLevel = ( ! finalLevel )
195142
196143// NEXT LEVEL
197144if ( hasNextLevel ) {
198145const nextLevel = levels [ levelIndex + 1 ]
199- const nextStage = nextLevel . stages [ 0 ]
200146const nextPosition = {
201147levelId :nextLevel . id ,
202- stageId :nextStage . id ,
203- stepId :nextStage . steps [ 0 ] . id ,
148+ stepId :nextLevel . steps [ 0 ] . id ,
204149}
205150return { type :'NEXT_LEVEL' , payload :{ position :nextPosition } }
206151}
@@ -211,9 +156,9 @@ export default {
211156stepNext :send ( ( context :CR . MachineContext ) :CR . Action => {
212157const { position, progress} = context
213158
214- const stage :G . Stage = selectors . currentStage ( context )
159+ const level :G . Level = selectors . currentLevel ( context )
215160
216- const { steps} = stage
161+ const { steps} = level
217162// TODO: verify not -1
218163const stepIndex = steps . findIndex ( ( s :G . Step ) => s . id === position . stepId )
219164const finalStep = stepIndex === steps . length - 1