@@ -78,23 +78,31 @@ export default {
78
78
console . log ( 'ACTION: tutorialLoad.progress' )
79
79
return currentProgress
80
80
} ,
81
- position ( ) {
81
+ position ( context : any ) : CR . Position {
82
82
console . log ( 'ACTION: tutorialLoad.position' )
83
83
if ( ! currentTutorial ) {
84
84
throw new Error ( 'No Tutorial loaded' )
85
85
}
86
86
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
+ }
91
99
92
100
const position = {
93
101
levelId,
94
102
stageId,
95
- stepId,
103
+ stepId
96
104
}
97
-
105
+ console . log ( 'position' , position )
98
106
return position
99
107
}
100
108
} ) ,
@@ -120,6 +128,7 @@ export default {
120
128
[ context . position . stepId ] : true ,
121
129
}
122
130
}
131
+ console . log ( 'progress update' , nextProgress )
123
132
storage . setProgress ( nextProgress )
124
133
return nextProgress
125
134
}
@@ -134,6 +143,7 @@ export default {
134
143
[ context . position . stageId ] : true ,
135
144
}
136
145
}
146
+ console . log ( 'progress update' , nextProgress )
137
147
storage . setProgress ( nextProgress )
138
148
return nextProgress
139
149
}
@@ -148,6 +158,7 @@ export default {
148
158
[ context . position . levelId ] : true ,
149
159
}
150
160
}
161
+ console . log ( 'progress update' , nextProgress )
151
162
storage . setProgress ( nextProgress )
152
163
return nextProgress
153
164
@@ -160,20 +171,24 @@ export default {
160
171
...context . progress ,
161
172
complete : true ,
162
173
}
174
+ console . log ( 'progress update' , nextProgress )
163
175
storage . setProgress ( nextProgress )
164
176
return nextProgress
165
177
}
166
178
} ) ,
167
179
stepLoadNext : assign ( {
168
- position : ( context : any ) => {
180
+ position : ( context : any ) : CR . Position => {
169
181
const { data, position } = context
170
182
const { stepList } = data . stages [ position . stageId ]
171
183
const currentStepIndex = stepList . indexOf ( position . stepId )
172
184
const nextStepId = stepList [ currentStepIndex + 1 ]
173
- return {
185
+
186
+ const nextPosition = {
174
187
...context . position ,
175
188
stepId : nextStepId ,
176
189
}
190
+ console . log ( 'position update' , nextPosition )
191
+ return nextPosition
177
192
}
178
193
} ) ,
179
194
loadLevel ( ) {
0 commit comments