Skip to content

Commit

Permalink
removed circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Sep 3, 2021
1 parent 5c20468 commit 0b65e3e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
45 changes: 16 additions & 29 deletions src/data/inspector-data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { BooleanPropertyEditor } from '../editor-view/properties/editors/boolean/boolean-property-editor';
import { NumberPropertyEditor } from '../editor-view/properties/editors/number/number-property-editor';
import { PointPropertyEditor } from '../editor-view/properties/editors/point/point-property-editor';
import { StringPropertyEditor } from '../editor-view/properties/editors/string/string-property-editor';

export type InspectableTypes = 'string' | 'number' | 'boolean' | 'point' | 'default';

export interface InspectorPropertyModel {
Expand All @@ -13,30 +8,22 @@ export interface InspectorPropertyModel {
}

export class InspectorData {
private readonly editors: Record<InspectableTypes, string> = {
// basic types
string: StringPropertyEditor.tagName,
number: NumberPropertyEditor.tagName,
boolean: BooleanPropertyEditor.tagName,

// PIXI/Phaser types
point: PointPropertyEditor.tagName,

// default
default: StringPropertyEditor.tagName,
};

public readonly inspectableProperties: InspectorPropertyModel[] = [
{ name: '__type', label: 'type', typeHint: 'string', data: { readonly: true } },
{ name: 'name', typeHint: 'string' },
{ name: 'position', typeHint: 'point' },
{ name: 'scale', typeHint: 'point', data: { step: 0.1 } },
{ name: 'pivot', typeHint: 'point' },
{ name: 'anchor', typeHint: 'point', data: { step: 0.1 } },
{ name: 'alpha', typeHint: 'number', data: { min: 0, max: 1, step: 0.1 } },
{ name: 'visible', typeHint: 'boolean' },
{ name: 'angle', typeHint: 'number', data: { readonly: true } },
];
private readonly editors: Partial<Record<InspectableTypes, string>> = {};

public addEditors(editors: Partial<Record<InspectableTypes, string>>) {
Object.keys(editors).forEach(e => this.editors[e] = editors[e]);
}

public readonly inspectableProperties: InspectorPropertyModel[] = [];

public addInspectableProperties(properties: InspectorPropertyModel[]) {
const iproperties = this.inspectableProperties;
properties.forEach(prop => {
const i = iproperties.findIndex(e => e.name === prop.name);
if (i < 0) iproperties.push(prop);
else iproperties.splice(i, 1, prop);
});
}

public findEditorFor(value: any, data: InspectorPropertyModel) {
// TODO what abount null / undefined values?
Expand Down
32 changes: 32 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { BooleanPropertyEditor } from 'editor-view/properties/editors/boolean/boolean-property-editor';
import { NumberPropertyEditor } from 'editor-view/properties/editors/number/number-property-editor';
import { PointPropertyEditor } from 'editor-view/properties/editors/point/point-property-editor';
import { StringPropertyEditor } from 'editor-view/properties/editors/string/string-property-editor';
import Phaser from 'phaser-ce';
import { Editor } from './core/editor';
import { EditorView } from './editor-view/editor-view';
Expand All @@ -13,6 +17,7 @@ export class Plugin extends Phaser.Plugin {

const scene = new SceneView(game, group, game.stage);
this.setupActions(scene);
this.setupInspectorData();

const editorView = document.createElement(EditorView.tagName) as EditorView;
document.body.appendChild(editorView);
Expand All @@ -27,6 +32,33 @@ export class Plugin extends Phaser.Plugin {
Editor.actions.setContainer('#phred-game-container');
}

private setupInspectorData() {
Editor.inspectorData.addEditors({
// basic types
string: StringPropertyEditor.tagName,
number: NumberPropertyEditor.tagName,
boolean: BooleanPropertyEditor.tagName,

// PIXI/Phaser types
point: PointPropertyEditor.tagName,

// default
default: StringPropertyEditor.tagName,
});

Editor.inspectorData.addInspectableProperties([
{ name: '__type', label: 'type', typeHint: 'string', data: { readonly: true } },
{ name: 'name', typeHint: 'string' },
{ name: 'position', typeHint: 'point' },
{ name: 'scale', typeHint: 'point', data: { step: 0.1 } },
{ name: 'pivot', typeHint: 'point' },
{ name: 'anchor', typeHint: 'point', data: { step: 0.1 } },
{ name: 'alpha', typeHint: 'number', data: { min: 0, max: 1, step: 0.1 } },
{ name: 'visible', typeHint: 'boolean' },
{ name: 'angle', typeHint: 'number', data: { readonly: true } },
]);
}

private setupActions(scene: SceneView) {
const { history, prefs } = Editor;
Editor.actions.add(
Expand Down

0 comments on commit 0b65e3e

Please sign in to comment.