diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index 75ccd7b7ed..6cd90c6303 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -42,6 +42,7 @@ import { storedProp, StoredBooleanProp } from 'common/storage'; import { StudyCtrl } from './study/interfaces'; import { StudyPracticeCtrl } from './study/practice/interfaces'; import { valid as crazyValid } from './crazy/crazyCtrl'; +import {treeReconstruct} from './util'; export default class AnalyseCtrl { @@ -184,7 +185,7 @@ export default class AnalyseCtrl { this.ongoing = !this.synthetic && game.playable(data); const prevTree = merge && this.tree.root; - this.tree = makeTree(treeOps.reconstruct(this.data.treeParts)); + this.tree = makeTree(treeReconstruct(this.data.treeParts)); if (prevTree) this.tree.merge(prevTree); this.actionMenu = new ActionMenuCtrl(); diff --git a/ui/analyse/src/util.ts b/ui/analyse/src/util.ts index 51cfd0e54c..ba2fb2f75f 100644 --- a/ui/analyse/src/util.ts +++ b/ui/analyse/src/util.ts @@ -191,3 +191,17 @@ export function option(value: string, current: string | undefined, name: string) export function scrollTo(el: HTMLElement | undefined, target: HTMLElement | null) { if (el && target) el.scrollTop = target.offsetTop - el.offsetHeight / 2 + target.offsetHeight / 2; } + +export function treeReconstruct(parts: any): Tree.Node { + const root = parts[0], nb = parts.length; + let node = root, i: number; + root.id = ''; + for (i = 1; i < nb; i++) { + const n = parts[i]; + if (node.children) node.children.unshift(n); + else node.children = [n]; + node = n; + } + node.children = node.children || []; + return root; +}