diff --git a/ui/analyse/src/study/gamebook/gamebookPlayCtrl.ts b/ui/analyse/src/study/gamebook/gamebookPlayCtrl.ts index d91f80fd7afb8..20193409b3244 100644 --- a/ui/analyse/src/study/gamebook/gamebookPlayCtrl.ts +++ b/ui/analyse/src/study/gamebook/gamebookPlayCtrl.ts @@ -1,5 +1,5 @@ import AnalyseCtrl from '../../ctrl'; -import { path as treePath, ops as treeOps } from 'tree'; +import { path as treePath } from 'tree'; import { makeShapesFromUci } from '../../autoShape'; export type Feedback = 'play' | 'good' | 'bad' | 'end'; @@ -21,13 +21,6 @@ export default class GamebookPlayCtrl { readonly trans: Trans, readonly redraw: () => void, ) { - // ensure all original nodes have a gamebook entry, - // so we can differentiate original nodes from user-made ones - treeOps.updateAll(root.tree.root, n => { - n.gamebook = n.gamebook || {}; - if (n.shapes) n.gamebook.shapes = n.shapes.slice(0); - }); - this.makeState(); } @@ -54,7 +47,7 @@ export default class GamebookPlayCtrl { } else { state.feedback = 'bad'; if (!state.comment) { - state.comment = parNode.children[0].gamebook!.deviation; + state.comment = parNode.children[0].gamebook?.deviation; } } this.state = state as State; diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index 0e3b2ed5f98d8..086d34cf39cf0 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -15,7 +15,7 @@ import { StudyShare } from './studyShare'; import { TagsForm } from './studyTags'; import ServerEval from './serverEval'; import * as xhr from './studyXhr'; -import { path as treePath } from 'tree'; +import { path as treePath, ops as treeOps } from 'tree'; import { StudyVm, Tab, @@ -404,6 +404,12 @@ export default class StudyCtrl { instanciateGamebookPlay = () => { if (!this.isGamebookPlay()) return (this.gamebookPlay = undefined); + // ensure all original nodes have a gamebook entry, + // so we can differentiate original nodes from user-made ones + treeOps.updateAll(this.ctrl.tree.root, n => { + n.gamebook = n.gamebook || {}; + if (n.shapes) n.gamebook.shapes = n.shapes.slice(0); + }); if (this.gamebookPlay?.chapterId === this.vm.chapterId) return; this.gamebookPlay = new GamebookPlayCtrl(this.ctrl, this.vm.chapterId, this.ctrl.trans, this.redraw); this.vm.mode.sticky = false;