diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-03-04 16:39:19 +1100 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-03-04 16:39:36 +1100 |
| commit | ae78a0efe93641b11fe101329e784f58b9729459 (patch) | |
| tree | 45a09b26dddce7a77e042672efbae0358f8846b2 /src/App.vue | |
| parent | 0442b3c5c861c2096fb3d7f74fb77073660651f1 (diff) | |
Add tile expansion, modify tol representation
Diffstat (limited to 'src/App.vue')
| -rw-r--r-- | src/App.vue | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/App.vue b/src/App.vue index 26ae610..5e7f904 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,22 +1,19 @@ <script> import tol from './tol.json'; -function addTileCounts(tree){ - if (tree.children && tree.children.length > 0){ - tree.children.forEach(addTileCounts) - tree.tileCount = tree.children.reduce((acc, val) => acc + val.tileCount, 0); +function addChildArrays(tree){ + if (!tree.children){ + tree.children = []; } else { - tree.tileCount = 1; + tree.children.forEach(addChildArrays); } } -addTileCounts(tol); +addChildArrays(tol); import TileTree from "./components/TileTree.vue"; export default { data() { return { - //tree: {...tol, children:[]}, - tree: {...tol, children:tol.children.map(e => ({...e, children:[]}))}, - //tree: tol, + tree: this.genTreeForTol(tol, 1), //allow for zero-level? width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, } @@ -25,6 +22,18 @@ export default { onResize(){ this.width = document.documentElement.clientWidth; this.height = document.documentElement.clientHeight; + }, + genTreeForTol(tol, lvl){ + if (lvl == 0){ + return {tolNode: tol, children: [], tileCount: 1}; + } else { + let childTrees = tol.children.map(e => this.genTreeForTol(e, lvl-1)); + return { + tolNode: tol, + children: childTrees, + tileCount: (childTrees.length == 0) ? 1 : childTrees.map(e => e.tileCount).reduce((x,y) => x+y) + }; + } } }, created(){ |
