Skip to content

Commit

Permalink
refresh object tree button
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Dec 15, 2021
1 parent 5993405 commit fc81454
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
4 changes: 4 additions & 0 deletions example/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ function create() {
sprite.pivot.set(0, 20);

plugin.show();

setTimeout(() => {
sprite.parent.removeChild(sprite);
}, 2000);
}

function el(x, y, w, h, parent, name) {
Expand Down
1 change: 1 addition & 0 deletions src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export class Actions {
public static readonly HELP = 'HELP';
public static readonly SELECT_PARENT = 'SELECT_PARENT';
public static readonly LOCK_SELECTION = 'LOCK_SELECTION';
public static readonly REFRESH_OBJECT_TREE = 'REFRESH_OBJECT_TREE';
}
6 changes: 6 additions & 0 deletions src/core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ class EditorClass {
icon: 'fa-level-up-alt',
toggle: true,
category: 'object-tree',
},
{
id: Actions.REFRESH_OBJECT_TREE,
tooltip: 'Refresh',
icon: 'fa-sync-alt',
category: 'object-tree',
}
);

Expand Down
26 changes: 18 additions & 8 deletions src/editor-view/object-tree/inspector/object-tree-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import './object-tree-inspector.scss';
export class ObjectTreeInspector extends Inspector {
public static readonly tagName = 'phred-object-tree-inspector';

private root: Container;
private readonly model: ObjectTreeModel = new ObjectTreeModel();

public init(game: Phaser.Game, side: Side) {
Expand All @@ -26,27 +27,36 @@ export class ObjectTreeInspector extends Inspector {
Editor.data.onPropertyChanged.add(this.onPropertyChanged, this);
Editor.data.onObjectLocked.add(this.onObjectLocked, this);

this.addAction(Editor.actions.getAction(Actions.REFRESH_OBJECT_TREE), 'right');
this.addAction(Editor.actions.getAction(Actions.LOCK_SELECTION), 'right', LockObjectActionButton.tagName);
this.addAction(Editor.actions.getAction(Actions.SELECT_PARENT), 'right');

Editor.actions.setActionCommand(
Actions.REFRESH_OBJECT_TREE,
() => this.setRoot(this.root)
);
}

public enable(config: PluginConfig) { this.setRoot(config.root); }

public disable() {
this.model.empty();

const emptyContent = this.contentElement.cloneNode(false);
this.replaceChild(emptyContent, this.contentElement);
this.contentElement = emptyContent as HTMLElement;
}
public disable() { this.clear(); }

private setRoot(root: PIXI.DisplayObjectContainer | Phaser.Stage) {
this.root = root;
this.clear();
this.model.create(root);
for (let i = 0, n = root.children.length; i < n; i++) {
this.createNode(root.children[i], this.contentElement, this.model);
}
}

private clear() {
this.model.empty();

const emptyContent = this.contentElement.cloneNode(false);
this.replaceChild(emptyContent, this.contentElement);
this.contentElement = emptyContent as HTMLElement;
}

private createNode(obj: PIXI.DisplayObject, parent: HTMLElement, model: ObjectTreeModel) {
// if (obj.__locked) return;
const m = model.getById(obj.__instanceId);
Expand Down

0 comments on commit fc81454

Please sign in to comment.