@@ -78,23 +78,31 @@ export default {
7878 console . log ( 'ACTION: tutorialLoad.progress' )
7979 return currentProgress
8080 } ,
81- position ( ) {
81+ position ( context : any ) : CR . Position {
8282 console . log ( 'ACTION: tutorialLoad.position' )
8383 if ( ! currentTutorial ) {
8484 throw new Error ( 'No Tutorial loaded' )
8585 }
8686 const { data } = currentTutorial
87-
88- const levelId = data . summary . levelList [ 0 ]
89- const stageId = data . levels [ levelId ] . stageList [ 0 ]
90- const stepId = data . stages [ stageId ] . stepList [ 0 ]
87+ const levelId = data . summary . levelList . find ( ( id : string ) => ! currentProgress . levels [ id ] )
88+ if ( ! levelId ) {
89+ throw new Error ( 'No level found on position load' )
90+ }
91+ const stageId = data . levels [ levelId ] . stageList . find ( ( id : string ) => ! currentProgress . stages [ id ] )
92+ if ( ! stageId ) {
93+ throw new Error ( 'No stage found on position load' )
94+ }
95+ const stepId = data . stages [ stageId ] . stepList . find ( ( id : string ) => ! currentProgress . steps [ id ] )
96+ if ( ! stepId ) {
97+ throw new Error ( 'No step found on position load' )
98+ }
9199
92100 const position = {
93101 levelId,
94102 stageId,
95- stepId,
103+ stepId
96104 }
97-
105+ console . log ( 'position' , position )
98106 return position
99107 }
100108 } ) ,
@@ -120,6 +128,7 @@ export default {
120128 [ context . position . stepId ] : true ,
121129 }
122130 }
131+ console . log ( 'progress update' , nextProgress )
123132 storage . setProgress ( nextProgress )
124133 return nextProgress
125134 }
@@ -134,6 +143,7 @@ export default {
134143 [ context . position . stageId ] : true ,
135144 }
136145 }
146+ console . log ( 'progress update' , nextProgress )
137147 storage . setProgress ( nextProgress )
138148 return nextProgress
139149 }
@@ -148,6 +158,7 @@ export default {
148158 [ context . position . levelId ] : true ,
149159 }
150160 }
161+ console . log ( 'progress update' , nextProgress )
151162 storage . setProgress ( nextProgress )
152163 return nextProgress
153164
@@ -160,20 +171,24 @@ export default {
160171 ...context . progress ,
161172 complete : true ,
162173 }
174+ console . log ( 'progress update' , nextProgress )
163175 storage . setProgress ( nextProgress )
164176 return nextProgress
165177 }
166178 } ) ,
167179 stepLoadNext : assign ( {
168- position : ( context : any ) => {
180+ position : ( context : any ) : CR . Position => {
169181 const { data, position } = context
170182 const { stepList } = data . stages [ position . stageId ]
171183 const currentStepIndex = stepList . indexOf ( position . stepId )
172184 const nextStepId = stepList [ currentStepIndex + 1 ]
173- return {
185+
186+ const nextPosition = {
174187 ...context . position ,
175188 stepId : nextStepId ,
176189 }
190+ console . log ( 'position update' , nextPosition )
191+ return nextPosition
177192 }
178193 } ) ,
179194 loadLevel ( ) {
0 commit comments