Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 2 additions & 9 deletions ui/analyse/src/study/gamebook/gamebookPlayCtrl.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
}

Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion ui/analyse/src/study/studyCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to take place before the following line or clicking back out of the analysis board causes a null gamebook where we expect a gamebook object.

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;
Expand Down