restore original gamebook shapes on clear

pull/3486/merge
Thibault Duplessis 2017-08-19 21:16:14 -05:00
parent c7f2129504
commit ba61397703
3 changed files with 13 additions and 2 deletions

View File

@ -24,7 +24,10 @@ export default class GamebookPlayCtrl {
// 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 || {});
treeOps.updateAll(root.tree.root, n => {
n.gamebook = n.gamebook || {};
if (n.shapes) n.gamebook.shapes = n.shapes.slice(0);
});
}
private makeState(): void {
@ -77,5 +80,11 @@ export default class GamebookPlayCtrl {
this.makeState();
};
private study = (): StudyCtrl => this.root.study!;
onShapeChange = shapes => {
const node = this.root.node;
if (node.gamebook && node.gamebook.shapes && !shapes.length) {
node.shapes = node.gamebook.shapes.slice(0);
this.root.jump(this.root.path);
}
};
}

View File

@ -217,6 +217,7 @@ export default function(data: StudyData, ctrl: AnalyseCtrl, tagTypes: TagTypes,
shapes
}));
}
gamebookPlay && gamebookPlay.onShapeChange(shapes);
};
}

View File

@ -206,6 +206,7 @@ declare namespace Tree {
export interface Gamebook {
deviation?: string;
hint?: string;
shapes?: Shape[]
}
export interface Opening {