Skip to content

Feature/multi stage #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 24, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix cross stage continue
  • Loading branch information
ShMcK committed Jul 24, 2019
commit 7c21cf1db3a9dd93fbe4497639186f8a85eff2ae
52 changes: 35 additions & 17 deletions src/state/actions/index.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,24 @@ let currentProgress: CR.Progress = {
complete: false,
}

const calculatePosition = ({ data, progress }: { data: CR.TutorialData, progress: CR.Progress }): CR.Position => {
const { levelList } = data.summary
// take next incomplete level or the final step
const levelId = levelList.find((id: string) => !progress.levels[id]) || levelList[levelList.length - 1]
const { stageList } = data.levels[levelId]
const stageId = stageList.find((id: string) => !progress.stages[id]) || stageList[stageList.length - 1]
const { stepList } = data.stages[stageId]
const stepId = stepList.find((id: string) => !progress.steps[id]) || stepList[stepList.length - 1]

const nextPosition: CR.Position = {
levelId,
stageId,
stepId,
}

return nextPosition
}

export default (dispatch: CR.EditorDispatch) => ({
createWebview() {
dispatch('coderoad.open_webview')
@@ -79,24 +97,9 @@ export default (dispatch: CR.EditorDispatch) => ({
if (!currentTutorial) {
throw new Error('No Tutorial loaded')
}

const { data } = currentTutorial
const position = calculatePosition({ data, progress: currentProgress })

const { levelList } = data.summary
// take next incomplete level or the final step
const levelId = levelList.find((id: string) => !currentProgress.levels[id]) || levelList[levelList.length - 1]
const { stageList } = data.levels[levelId]
const stageId = stageList.find((id: string) => !currentProgress.stages[id]) || stageList[stageList.length - 1]
console.log('position stepList')
console.log(data.stages[stageId])
const { stepList } = data.stages[stageId]
const stepId = stepList.find((id: string) => !currentProgress.steps[id]) || stepList[stepList.length - 1]

const position = {
levelId,
stageId,
stepId,
}
console.log('position', position)
return position
},
@@ -113,6 +116,7 @@ export default (dispatch: CR.EditorDispatch) => ({
// @ts-ignore
progressUpdate: assign({
progress: (context: CR.MachineContext): CR.Progress => {
console.log('progress update')
const { progress, position, data } = context
const nextProgress = progress

@@ -156,9 +160,23 @@ export default (dispatch: CR.EditorDispatch) => ({
loadLevel() {
console.log('loadLevel')
},
loadStage() {
stageLoadNext(context: CR.MachineContext) {
console.log('stageLoadNext')
const { position } = context
console.log(position)
},
loadStage(context: CR.MachineContext): void {
console.log('loadStage')
const { position } = context
console.log(position)
},
// @ts-ignore
updatePosition: assign({
position: (context: CR.MachineContext) => calculatePosition({
data: context.data,
progress: context.progress,
}),
}),
stepLoadCommits(context: CR.MachineContext): void {
const { data, position } = context
const { setup } = data.steps[position.stepId].actions
7 changes: 4 additions & 3 deletions src/state/machine.ts
Original file line number Diff line number Diff line change
@@ -71,12 +71,10 @@ export const machine = (dispatch: CR.EditorDispatch) =>
after: {
0: [{
target: 'Stage',
internal: true,
cond: 'hasNextStep',
},
{
target: 'Stage',
internal: false,
cond: 'hasNextStage',
},
{
@@ -150,7 +148,10 @@ export const machine = (dispatch: CR.EditorDispatch) =>
},
StageComplete: {
on: {
STAGE_NEXT: '#tutorial-load-next',
STAGE_NEXT: {
target: '#tutorial-load-next',
actions: ['updatePosition'],
},
},
},
},