Skip to content

Commit

Permalink
using contructor names for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Sep 17, 2021
1 parent d9bfbe4 commit 138b488
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/data/phaser-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ export class PhaserMeta {

private readonly defaultType: PhaserObjectType = { name: 'Unknown', icon: 'fa-question' };

public getType(t: number) { return t in this.sceneObjects ? this.sceneObjects[t] : this.defaultType; }
public getType(obj: PIXI.DisplayObject) {
const t = obj.type;
const type = t in this.sceneObjects ? this.sceneObjects[t] : this.defaultType;
const ctorName = obj.constructor.name;
const name = ctorName && ctorName.length > 0 ? ctorName : type.name;
return Object.assign({}, type, { name });
}
}
5 changes: 3 additions & 2 deletions src/editor-view/object-tree/model/object-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export class ObjectTreeModel {
}

private createNode(child: PIXI.DisplayObject, map: Record<number, ObjectMapItemModel>, parent: ObjectMapItemModel, level: number) {
const type = Editor.meta.getType(child.type);
child.__instanceId = IdUtil.genIntId();
if (!child.__instanceId) child.__instanceId = IdUtil.genIntId();
const type = Editor.meta.getType(child);
child.__type = type.name;

const isLeaf = !(child.children && child.children.length > 0);
const node = map[child.__instanceId] = {
obj: child,
Expand Down
5 changes: 4 additions & 1 deletion src/editor.window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ export class EditorWindow {
icon: 'fa-terminal',
shortcut: 'ctrl+alt+p',
command: () => {
if (Editor.data.selectedObject)
if (Editor.data.selectedObject) {
console.info(Editor.data.selectedObject);
console.log(Editor.data.selectedObject.constructor.name);
console.log((Editor.data.selectedObject as any).prototype);
}
}
},
{
Expand Down

0 comments on commit 138b488

Please sign in to comment.