@@ -28,7 +28,7 @@ export default {
2828 return event . payload . tutorial
2929 } ,
3030 progress : ( ) : CR . Progress => {
31- return { levels : { } , stages : { } , steps : { } , complete : false }
31+ return { levels : { } , steps : { } , complete : false }
3232 }
3333 } ) ,
3434 initTutorial : 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
9777 updateLevelPosition : assign ( {
9878 position : ( context : CR . MachineContext ) : CR . Position => {
9979 const { position} = context
10080 const 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
10585 const levelIndex = levels . findIndex ( ( l : G . Level ) => l . id === position . levelId )
10686 const level : G . Level = levels [ levelIndex + 1 ]
10787
10888 const nextPosition : CR . Position = {
10989 levelId : level . id ,
110- stageId : level . stages [ 0 ] . id ,
111- stepId : level . stages [ 0 ] . steps [ 0 ] . id ,
90+ stepId : level . steps [ 0 ] . id ,
11291 }
11392
11493 return 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
144110 updatePosition : assign ( {
145111 position : ( context : CR . MachineContext , event : CR . MachineEvent ) : CR . Progress => {
146112 const { position} = event . payload
@@ -152,9 +118,8 @@ export default {
152118
153119 const version = selectors . currentVersion ( context )
154120 const 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
159124 const stepIndex = steps . findIndex ( ( s : G . Step ) => s . id === position . stepId )
160125 const stepComplete = progress . steps [ position . stepId ]
@@ -168,39 +133,19 @@ export default {
168133 return { 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 ?? [ ]
192139 const levelIndex = levels . findIndex ( ( l : G . Level ) => l . id === position . levelId )
193140 const finalLevel = ( levelIndex > - 1 && levelIndex === levels . length - 1 )
194141 const hasNextLevel = ( ! finalLevel )
195142
196143 // NEXT LEVEL
197144 if ( hasNextLevel ) {
198145 const nextLevel = levels [ levelIndex + 1 ]
199- const nextStage = nextLevel . stages [ 0 ]
200146 const nextPosition = {
201147 levelId : nextLevel . id ,
202- stageId : nextStage . id ,
203- stepId : nextStage . steps [ 0 ] . id ,
148+ stepId : nextLevel . steps [ 0 ] . id ,
204149 }
205150 return { type : 'NEXT_LEVEL' , payload : { position : nextPosition } }
206151 }
@@ -211,9 +156,9 @@ export default {
211156 stepNext : send ( ( context : CR . MachineContext ) : CR . Action => {
212157 const { 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
218163 const stepIndex = steps . findIndex ( ( s : G . Step ) => s . id === position . stepId )
219164 const finalStep = stepIndex === steps . length - 1
0 commit comments