Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3098375

Browse files
committed
navigate through stages & levels
1 parentbb14901 commit3098375

File tree

2 files changed

+68
-28
lines changed

2 files changed

+68
-28
lines changed

‎web-app/src/services/state/actions/context.ts

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,70 @@ export default {
2727
},
2828
}),
2929
//@ts-ignore
30+
updateStepPosition:assign({
31+
position:(context:CR.MachineContext,event:CR.MachineEvent):CR.Position=>{
32+
constposition:CR.Position=context.position
33+
// merge in the updated position
34+
// sent with the test to ensure consistency
35+
conststeps:G.Step[]=context.tutorial.version
36+
.levels.find((l:G.Level)=>l.id===position.levelId)
37+
.stages.find((s:G.Stage)=>s.id===position.stageId)
38+
.steps
39+
40+
conststepIndex=steps.findIndex((s:G.Step)=>s.id===position.stepId)
41+
conststep:G.Step=steps[stepIndex+1]
42+
43+
console.log('step load next',step.id,position.stepId)
44+
45+
return{
46+
...position,
47+
stepId:step.id
48+
}
49+
},
50+
}),
51+
//@ts-ignore
52+
updateStagePosition:assign({
53+
position:(context:CR.MachineContext,event:CR.MachineEvent):CR.Position=>{
54+
constposition:CR.Position=context.position
55+
// merge in the updated position
56+
// sent with the test to ensure consistency
57+
conststages:G.Stage[]=context.tutorial.version
58+
.levels.find((l:G.Level)=>l.id===position.levelId)
59+
.stages
60+
61+
conststageIndex=stages.findIndex((s:G.Stage)=>s.id===position.stageId)
62+
conststage:G.Stage=stages[stageIndex+1]
63+
64+
console.log('stage load next',stage.id,position.stageId)
65+
66+
return{
67+
...position,
68+
stageId:stage.id,
69+
stepId:stage.steps[0].id,
70+
}
71+
},
72+
}),
73+
//@ts-ignore
74+
updateLevelPosition:assign({
75+
position:(context:CR.MachineContext,event:CR.MachineEvent):CR.Position=>{
76+
constposition:CR.Position=context.position
77+
// merge in the updated position
78+
// sent with the test to ensure consistency
79+
constlevels:G.Level[]=context.tutorial.version.levels
80+
81+
constlevelIndex=levels.findIndex((l:G.Level)=>l.id===position.levelId)
82+
constlevel:G.Level=levels[levelIndex+1]
83+
84+
console.log('level load next',level.id,position.levelId)
85+
86+
return{
87+
levelId:level.id,
88+
stageId:level.stages[0].id,
89+
stepId:level.stages[0].steps[0].id,
90+
}
91+
},
92+
}),
93+
//@ts-ignore
3094
updateStepProgress:assign({
3195
progress:(context:CR.MachineContext,event:CR.MachineEvent):CR.Progress=>{
3296
// update progress by tracking completed
@@ -53,27 +117,4 @@ export default {
53117
returnprogress
54118
},
55119
}),
56-
//@ts-ignore
57-
stepLoadNext:assign({
58-
position:(context:CR.MachineContext,event:CR.MachineEvent):CR.Position=>{
59-
constposition:CR.Position=context.position
60-
// merge in the updated position
61-
// sent with the test to ensure consistency
62-
conststeps:G.Step[]=context.tutorial.version
63-
.levels.find((l:G.Level)=>l.id===position.levelId)
64-
.stages.find((s:G.Stage)=>s.id===position.stageId)
65-
.steps
66-
67-
conststepIndex=steps.findIndex((s:G.Step)=>s.id===position.stepId)
68-
console.log('step index',stepIndex)
69-
conststep:G.Step=steps[stepIndex+1]
70-
71-
console.log('step load next',step.id,position.stepId)
72-
73-
return{
74-
...position,
75-
stepId:step.id
76-
}
77-
},
78-
})
79120
}

‎web-app/src/services/state/machine.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
7777
{
7878
target:'Stage',
7979
cond:'hasNextStage',
80+
actions:['updateStagePosition']
8081
},
8182
{
8283
target:'Level',
8384
cond:'hasNextLevel',
85+
actions:['updateLevelPosition']
8486
},
8587
{
8688
target:'#completed-tutorial',
@@ -130,7 +132,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
130132
},
131133
},
132134
TestPass:{
133-
onExit:['stepLoadNext'],
135+
onExit:['updateStepPosition'],
134136
after:{
135137
1000:'StepNext',
136138
},
@@ -158,10 +160,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
158160
},
159161
StageComplete:{
160162
on:{
161-
STAGE_NEXT:{
162-
target:'#tutorial-load-next',
163-
actions:['updatePosition'],
164-
},
163+
STAGE_NEXT:'#tutorial-load-next',
165164
},
166165
},
167166
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp