-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8ac759
commit ac46882
Showing
3 changed files
with
56 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,82 @@ | ||
export type InspectableTypes = 'string' | 'text' | 'number' | 'boolean' | 'point' | 'rect' | 'default'; | ||
export type InspectableType = 'string' | 'text' | 'number' | 'boolean' | 'point' | 'rect' | 'default'; | ||
|
||
export interface InspectorPropertyModel { | ||
name: string; | ||
typeHint: InspectableTypes; | ||
typeHint: InspectableType; | ||
data?: any; | ||
label?: string; | ||
} | ||
|
||
export interface ObjectInspectorModel { | ||
export interface ObjectPropertiesModel { | ||
title: string; | ||
properties: string[]; | ||
} | ||
|
||
|
||
export class InspectorData { | ||
private readonly editors: Partial<Record<InspectableTypes, string>> = {}; | ||
/** Editors for each type of data ({@link InspectableType}). */ | ||
private readonly typeEditors: Partial<Record<InspectableType, string>> = {}; | ||
|
||
public addEditors(editors: Partial<Record<InspectableTypes, string>>) { | ||
Object.keys(editors).forEach(e => this.editors[e] = editors[e]); | ||
/** | ||
* Add editors for {@link InspectableType}. | ||
* @param editors A map of editors for each {@link InspectableType} | ||
*/ | ||
public addTypeEditors(editors: Partial<Record<InspectableType, string>>) { | ||
Object.keys(editors).forEach(e => this.typeEditors[e] = editors[e]); | ||
} | ||
|
||
public getEditorFor(data: InspectorPropertyModel) { | ||
return data.typeHint in this.editors | ||
? this.editors[data.typeHint] | ||
: this.editors.default; | ||
/** | ||
* Get the editor for the given {@link InspectableType} | ||
* @param type The {@link InspectableType} to get the editor for | ||
*/ | ||
public getEditorForType(type: InspectableType) { | ||
return type in this.typeEditors | ||
? this.typeEditors[type] | ||
: this.typeEditors.default; | ||
} | ||
|
||
/** A register of properties from PIXI/Phaser objects that can be inspectable. */ | ||
private readonly inspectableProperties: Record<string, InspectorPropertyModel> = {}; | ||
|
||
/** | ||
* Adds a list of inspectable properties from PIXI/Phaser objects. | ||
* @param properties The list of properties to add. | ||
*/ | ||
public addInspectableProperties(properties: InspectorPropertyModel[]) { | ||
properties.forEach(prop => this.inspectableProperties[prop.name] = prop); | ||
} | ||
|
||
/** | ||
* Gets the {@link InspectorPropertyModel} related to the given property name. | ||
* @param name The name of the property to get the inspector for. | ||
*/ | ||
public getInspectableProperty(name: string) { | ||
if (name in this.inspectableProperties) | ||
return this.inspectableProperties[name]; | ||
throw `Could not find inspectable editor for property ${name}`; | ||
} | ||
|
||
private readonly inspectorProperties: Record<string, ObjectInspectorModel[]> = {}; | ||
|
||
public addInspectorProperties(type: string, inspectors: ObjectInspectorModel[]) { | ||
this.inspectorProperties[type] = inspectors; | ||
/** Properties that should be inspected when an object of the related type is selected on the editor */ | ||
private readonly objectProperties: Record<string, ObjectPropertiesModel[]> = {}; | ||
|
||
/** | ||
* Add properties to be shown in the Inspector when an object of the given type is selected on | ||
* the editor. | ||
* @param type The exact object type name to have the properties | ||
* @param properties The properties to show in the Inspector | ||
*/ | ||
public addObjectProperties(type: string, properties: ObjectPropertiesModel[]) { | ||
this.objectProperties[type] = properties; | ||
} | ||
|
||
public getInspectorPropertiesForType(type: string) { | ||
return type in this.inspectorProperties | ||
? this.inspectorProperties[type] | ||
: this.inspectorProperties.default; | ||
/** | ||
* Gets the properties that should be inspected for the given type. | ||
* @param type The type to get the properties for | ||
*/ | ||
public getObjectPropertiesForType(type: string) { | ||
return type in this.objectProperties | ||
? this.objectProperties[type] | ||
: this.objectProperties.default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters