Skip to content

Commit

Permalink
Added: Object tree root node
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Sep 7, 2022
1 parent e7be0f9 commit bc03092
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/editor-view/object-tree/model/object-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ export interface ObjectTreeNodeModel {

export class ObjectTreeModel {
private objectMap: Record<number, ObjectTreeNodeModel>;
private _root: ObjectTreeNodeModel;

public get root() { return this._root; }

public getById(instanceId: number) { return this.objectMap[instanceId]; }

public create(root: PIXI.DisplayObjectContainer | Phaser.Stage) {
this.objectMap = {};
this.createNode(root, this.objectMap, null, 0);
this._root = this.createNode(root, this.objectMap, null, 0);
}

public empty() { this.objectMap = null; }
Expand All @@ -44,12 +47,14 @@ export class ObjectTreeModel {
parent,
};

if (isLeaf) return;

level += 1;
for (let i = 0, n = child.children.length; i < n; i++) {
this.createNode(child.children[i], map, node, level);
if (!isLeaf) {
level += 1;
for (let i = 0, n = child.children.length; i < n; i++) {
this.createNode(child.children[i], map, node, level);
}
}

return node;
}

public filter(filter: string) {
Expand Down

0 comments on commit bc03092

Please sign in to comment.