|
@@ -5,14 +5,14 @@ module INSPECTOR {
|
|
/**
|
|
/**
|
|
* Format the value of the given property of the given object.
|
|
* Format the value of the given property of the given object.
|
|
*/
|
|
*/
|
|
- public static format(obj: any, prop:string) : string {
|
|
|
|
|
|
+ public static format(obj: any, prop: string): string {
|
|
// Get original value;
|
|
// Get original value;
|
|
let value = obj[prop];
|
|
let value = obj[prop];
|
|
// test if type PrimitiveAlignment is available (only included in canvas2d)
|
|
// test if type PrimitiveAlignment is available (only included in canvas2d)
|
|
- if (BABYLON.PrimitiveAlignment) {
|
|
|
|
|
|
+ if (BABYLON.PrimitiveAlignment) {
|
|
if (obj instanceof BABYLON.PrimitiveAlignment) {
|
|
if (obj instanceof BABYLON.PrimitiveAlignment) {
|
|
if (prop === 'horizontal') {
|
|
if (prop === 'horizontal') {
|
|
- switch(value) {
|
|
|
|
|
|
+ switch (value) {
|
|
case BABYLON.PrimitiveAlignment.AlignLeft:
|
|
case BABYLON.PrimitiveAlignment.AlignLeft:
|
|
return 'left';
|
|
return 'left';
|
|
case BABYLON.PrimitiveAlignment.AlignRight:
|
|
case BABYLON.PrimitiveAlignment.AlignRight:
|
|
@@ -23,7 +23,7 @@ module INSPECTOR {
|
|
return 'stretch';
|
|
return 'stretch';
|
|
}
|
|
}
|
|
} else if (prop === 'vertical') {
|
|
} else if (prop === 'vertical') {
|
|
- switch(value) {
|
|
|
|
|
|
+ switch (value) {
|
|
case BABYLON.PrimitiveAlignment.AlignTop:
|
|
case BABYLON.PrimitiveAlignment.AlignTop:
|
|
return 'top';
|
|
return 'top';
|
|
case BABYLON.PrimitiveAlignment.AlignBottom:
|
|
case BABYLON.PrimitiveAlignment.AlignBottom:
|
|
@@ -54,66 +54,69 @@ module INSPECTOR {
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
export class PropertyLine {
|
|
export class PropertyLine {
|
|
-
|
|
|
|
|
|
+
|
|
// The property can be of any type (Property internally can have any type), relative to this._obj
|
|
// The property can be of any type (Property internally can have any type), relative to this._obj
|
|
- private _property : Property;
|
|
|
|
|
|
+ private _property: Property;
|
|
//The HTML element corresponding to this line
|
|
//The HTML element corresponding to this line
|
|
- private _div : HTMLElement;
|
|
|
|
|
|
+ private _div: HTMLElement;
|
|
// The div containing the value to display. Used to update dynamically the property
|
|
// The div containing the value to display. Used to update dynamically the property
|
|
- private _valueDiv : HTMLElement;
|
|
|
|
|
|
+ private _valueDiv: HTMLElement;
|
|
// If the type is complex, this property will have child to update
|
|
// If the type is complex, this property will have child to update
|
|
- private _children : Array<PropertyLine> = [];
|
|
|
|
|
|
+ private _children: Array<PropertyLine> = [];
|
|
// Array representing the simple type. All others are considered 'complex'
|
|
// Array representing the simple type. All others are considered 'complex'
|
|
private static _SIMPLE_TYPE = ['number', 'string', 'boolean'];
|
|
private static _SIMPLE_TYPE = ['number', 'string', 'boolean'];
|
|
// The number of pixel at each children step
|
|
// The number of pixel at each children step
|
|
private static _MARGIN_LEFT = 15;
|
|
private static _MARGIN_LEFT = 15;
|
|
// The margin-left used to display to row
|
|
// The margin-left used to display to row
|
|
- private _level : number;
|
|
|
|
|
|
+ private _level: number;
|
|
/** The list of viewer element displayed at the end of the line (color, texture...) */
|
|
/** The list of viewer element displayed at the end of the line (color, texture...) */
|
|
- private _elements : Array<BasicElement> = [];
|
|
|
|
|
|
+ private _elements: Array<BasicElement> = [];
|
|
/** The property parent of this one. Used to update the value of this property and to retrieve the correct object */
|
|
/** The property parent of this one. Used to update the value of this property and to retrieve the correct object */
|
|
- private _parent : PropertyLine;
|
|
|
|
|
|
+ private _parent: PropertyLine;
|
|
/** The input element to display if this property is 'simple' in order to update it */
|
|
/** The input element to display if this property is 'simple' in order to update it */
|
|
- private _input : HTMLInputElement;
|
|
|
|
|
|
+ private _input: HTMLInputElement;
|
|
/** Display input handler (stored to be removed afterwards) */
|
|
/** Display input handler (stored to be removed afterwards) */
|
|
- private _displayInputHandler : EventListener;
|
|
|
|
|
|
+ private _displayInputHandler: EventListener;
|
|
/** Handler used to validate the input by pressing 'enter' */
|
|
/** Handler used to validate the input by pressing 'enter' */
|
|
- private _validateInputHandler : EventListener;
|
|
|
|
-
|
|
|
|
- constructor(prop : Property, parent?: PropertyLine, level:number=0) {
|
|
|
|
|
|
+ private _validateInputHandler: EventListener;
|
|
|
|
+ /** Handler used to validate the input by pressing 'esc' */
|
|
|
|
+ private _escapeInputHandler: EventListener;
|
|
|
|
+
|
|
|
|
+ constructor(prop: Property, parent?: PropertyLine, level: number = 0) {
|
|
this._property = prop;
|
|
this._property = prop;
|
|
- this._level = level;
|
|
|
|
- this._parent = parent;
|
|
|
|
-
|
|
|
|
|
|
+ this._level = level;
|
|
|
|
+ this._parent = parent;
|
|
|
|
+
|
|
this._div = Helpers.CreateDiv('row');
|
|
this._div = Helpers.CreateDiv('row');
|
|
this._div.style.marginLeft = `${this._level}px`;
|
|
this._div.style.marginLeft = `${this._level}px`;
|
|
-
|
|
|
|
|
|
+
|
|
// Property name
|
|
// Property name
|
|
- let propName : HTMLElement = Helpers.CreateDiv('prop-name', this._div);
|
|
|
|
|
|
+ let propName: HTMLElement = Helpers.CreateDiv('prop-name', this._div);
|
|
propName.textContent = `${this.name}`;
|
|
propName.textContent = `${this.name}`;
|
|
|
|
|
|
// Value
|
|
// Value
|
|
this._valueDiv = Helpers.CreateDiv('prop-value', this._div);
|
|
this._valueDiv = Helpers.CreateDiv('prop-value', this._div);
|
|
this._valueDiv.textContent = this._displayValueContent() || '-'; // Init value text node
|
|
this._valueDiv.textContent = this._displayValueContent() || '-'; // Init value text node
|
|
-
|
|
|
|
|
|
+
|
|
this._createElements();
|
|
this._createElements();
|
|
-
|
|
|
|
|
|
+
|
|
for (let elem of this._elements) {
|
|
for (let elem of this._elements) {
|
|
this._valueDiv.appendChild(elem.toHtml());
|
|
this._valueDiv.appendChild(elem.toHtml());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
this._updateValue();
|
|
this._updateValue();
|
|
|
|
|
|
// If the property type is not simple, add click event to unfold its children
|
|
// If the property type is not simple, add click event to unfold its children
|
|
- if (!this._isSimple()) {
|
|
|
|
|
|
+ if (!this._isSimple()) {
|
|
this._valueDiv.classList.add('clickable');
|
|
this._valueDiv.classList.add('clickable');
|
|
this._valueDiv.addEventListener('click', this._addDetails.bind(this));
|
|
this._valueDiv.addEventListener('click', this._addDetails.bind(this));
|
|
} else {
|
|
} else {
|
|
this._initInput();
|
|
this._initInput();
|
|
this._valueDiv.addEventListener('click', this._displayInputHandler);
|
|
this._valueDiv.addEventListener('click', this._displayInputHandler);
|
|
this._input.addEventListener('keypress', this._validateInputHandler);
|
|
this._input.addEventListener('keypress', this._validateInputHandler);
|
|
|
|
+ this._input.addEventListener('keydown', this._escapeInputHandler);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// Add this property to the scheduler
|
|
// Add this property to the scheduler
|
|
Scheduler.getInstance().add(this);
|
|
Scheduler.getInstance().add(this);
|
|
}
|
|
}
|
|
@@ -124,21 +127,22 @@ module INSPECTOR {
|
|
* - enters updates the property
|
|
* - enters updates the property
|
|
*/
|
|
*/
|
|
private _initInput() {
|
|
private _initInput() {
|
|
-
|
|
|
|
|
|
+
|
|
// Create the input element
|
|
// Create the input element
|
|
this._input = document.createElement('input') as HTMLInputElement;
|
|
this._input = document.createElement('input') as HTMLInputElement;
|
|
this._input.setAttribute('type', 'text');
|
|
this._input.setAttribute('type', 'text');
|
|
|
|
|
|
// if the property is 'simple', add an event listener to create an input
|
|
// if the property is 'simple', add an event listener to create an input
|
|
- this._displayInputHandler = this._displayInput.bind(this);
|
|
|
|
|
|
+ this._displayInputHandler = this._displayInput.bind(this);
|
|
this._validateInputHandler = this._validateInput.bind(this);
|
|
this._validateInputHandler = this._validateInput.bind(this);
|
|
|
|
+ this._escapeInputHandler = this._escapeInput.bind(this);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* On enter : validates the new value and removes the input
|
|
* On enter : validates the new value and removes the input
|
|
* On escape : removes the input
|
|
* On escape : removes the input
|
|
*/
|
|
*/
|
|
- private _validateInput(e : KeyboardEvent) {
|
|
|
|
|
|
+ private _validateInput(e: KeyboardEvent) {
|
|
if (e.keyCode == 13) {
|
|
if (e.keyCode == 13) {
|
|
// Enter : validate the new value
|
|
// Enter : validate the new value
|
|
let newValue = this._input.value;
|
|
let newValue = this._input.value;
|
|
@@ -148,8 +152,18 @@ module INSPECTOR {
|
|
this.update();
|
|
this.update();
|
|
// resume scheduler
|
|
// resume scheduler
|
|
Scheduler.getInstance().pause = false;
|
|
Scheduler.getInstance().pause = false;
|
|
-
|
|
|
|
- } else if (e.keyCode == 27) {
|
|
|
|
|
|
+
|
|
|
|
+ } else if (e.keyCode == 27) {
|
|
|
|
+ // Esc : remove input
|
|
|
|
+ this.update();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * On escape : removes the input
|
|
|
|
+ */
|
|
|
|
+ private _escapeInput(e: KeyboardEvent) {
|
|
|
|
+ if (e.keyCode == 27) {
|
|
// Esc : remove input
|
|
// Esc : remove input
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
@@ -162,7 +176,7 @@ module INSPECTOR {
|
|
// restore elements
|
|
// restore elements
|
|
for (let elem of this._elements) {
|
|
for (let elem of this._elements) {
|
|
this._valueDiv.appendChild(elem.toHtml());
|
|
this._valueDiv.appendChild(elem.toHtml());
|
|
- }
|
|
|
|
|
|
+ }
|
|
this._valueDiv.addEventListener('click', this._displayInputHandler);
|
|
this._valueDiv.addEventListener('click', this._displayInputHandler);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -176,7 +190,7 @@ module INSPECTOR {
|
|
this._valueDiv.textContent = "";
|
|
this._valueDiv.textContent = "";
|
|
this._input.value = valueTxt;
|
|
this._input.value = valueTxt;
|
|
this._valueDiv.appendChild(this._input);
|
|
this._valueDiv.appendChild(this._input);
|
|
-
|
|
|
|
|
|
+
|
|
// Pause the scheduler
|
|
// Pause the scheduler
|
|
Scheduler.getInstance().pause = true;
|
|
Scheduler.getInstance().pause = true;
|
|
}
|
|
}
|
|
@@ -190,76 +204,76 @@ module INSPECTOR {
|
|
if (this._parent) {
|
|
if (this._parent) {
|
|
this._property.obj = this._parent.updateObject();
|
|
this._property.obj = this._parent.updateObject();
|
|
}
|
|
}
|
|
- return this._property.value;
|
|
|
|
|
|
+ return this._property.value;
|
|
}
|
|
}
|
|
|
|
|
|
// Returns the property name
|
|
// Returns the property name
|
|
- public get name() : string {
|
|
|
|
|
|
+ public get name(): string {
|
|
return this._property.name;
|
|
return this._property.name;
|
|
}
|
|
}
|
|
|
|
|
|
// Returns the value of the property
|
|
// Returns the value of the property
|
|
- public get value() : any {
|
|
|
|
|
|
+ public get value(): any {
|
|
return PropertyFormatter.format(this._property.obj, this._property.name);
|
|
return PropertyFormatter.format(this._property.obj, this._property.name);
|
|
}
|
|
}
|
|
|
|
|
|
// Returns the type of the property
|
|
// Returns the type of the property
|
|
- public get type() : string {
|
|
|
|
|
|
+ public get type(): string {
|
|
return this._property.type;
|
|
return this._property.type;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Creates elements that wil be displayed on a property line, depending on the
|
|
* Creates elements that wil be displayed on a property line, depending on the
|
|
* type of the property.
|
|
* type of the property.
|
|
*/
|
|
*/
|
|
private _createElements() {
|
|
private _createElements() {
|
|
-
|
|
|
|
|
|
+
|
|
// Colors
|
|
// Colors
|
|
- if (this.type == 'Color3' ||this.type == 'Color4') {
|
|
|
|
|
|
+ if (this.type == 'Color3' || this.type == 'Color4') {
|
|
this._elements.push(new ColorElement(this.value));
|
|
this._elements.push(new ColorElement(this.value));
|
|
- }
|
|
|
|
|
|
+ }
|
|
// Texture
|
|
// Texture
|
|
if (this.type == 'Texture') {
|
|
if (this.type == 'Texture') {
|
|
this._elements.push(new TextureElement(this.value));
|
|
this._elements.push(new TextureElement(this.value));
|
|
- }
|
|
|
|
|
|
+ }
|
|
// HDR Texture
|
|
// HDR Texture
|
|
if (this.type == 'HDRCubeTexture') {
|
|
if (this.type == 'HDRCubeTexture') {
|
|
this._elements.push(new HDRCubeTextureElement(this.value));
|
|
this._elements.push(new HDRCubeTextureElement(this.value));
|
|
- }
|
|
|
|
|
|
+ }
|
|
if (this.type == 'CubeTexture') {
|
|
if (this.type == 'CubeTexture') {
|
|
this._elements.push(new CubeTextureElement(this.value));
|
|
this._elements.push(new CubeTextureElement(this.value));
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// Returns the text displayed on the left of the property name :
|
|
// Returns the text displayed on the left of the property name :
|
|
// - If the type is simple, display its value
|
|
// - If the type is simple, display its value
|
|
// - If the type is complex, but instance of Vector2, Size, display the type and its tostring
|
|
// - If the type is complex, but instance of Vector2, Size, display the type and its tostring
|
|
// - If the type is another one, display the Type
|
|
// - If the type is another one, display the Type
|
|
- private _displayValueContent () {
|
|
|
|
-
|
|
|
|
|
|
+ private _displayValueContent() {
|
|
|
|
+
|
|
let value = this.value;
|
|
let value = this.value;
|
|
// If the value is a number, truncate it if needed
|
|
// If the value is a number, truncate it if needed
|
|
if (typeof value === 'number') {
|
|
if (typeof value === 'number') {
|
|
- return Helpers.Trunc(value);
|
|
|
|
- }
|
|
|
|
|
|
+ return Helpers.Trunc(value);
|
|
|
|
+ }
|
|
// If it's a string or a boolean, display its value
|
|
// If it's a string or a boolean, display its value
|
|
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
- return value;
|
|
|
|
- }
|
|
|
|
|
|
+ return value;
|
|
|
|
+ }
|
|
return PROPERTIES.format(value);
|
|
return PROPERTIES.format(value);
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/** Delete properly this property line.
|
|
/** Delete properly this property line.
|
|
* Removes itself from the scheduler.
|
|
* Removes itself from the scheduler.
|
|
* Dispose all viewer element (color, texture...)
|
|
* Dispose all viewer element (color, texture...)
|
|
*/
|
|
*/
|
|
public dispose() {
|
|
public dispose() {
|
|
// console.log('delete properties', this.name);
|
|
// console.log('delete properties', this.name);
|
|
- Scheduler.getInstance().remove(this);
|
|
|
|
|
|
+ Scheduler.getInstance().remove(this);
|
|
for (let child of this._children) {
|
|
for (let child of this._children) {
|
|
// console.log('delete properties', child.name);
|
|
// console.log('delete properties', child.name);
|
|
- Scheduler.getInstance().remove(child);
|
|
|
|
|
|
+ Scheduler.getInstance().remove(child);
|
|
}
|
|
}
|
|
for (let elem of this._elements) {
|
|
for (let elem of this._elements) {
|
|
elem.dispose();
|
|
elem.dispose();
|
|
@@ -281,20 +295,20 @@ module INSPECTOR {
|
|
elem.update(this.value);
|
|
elem.update(this.value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Update the property division with the new property value.
|
|
* Update the property division with the new property value.
|
|
* If this property is complex, update its child, otherwise update its text content
|
|
* If this property is complex, update its child, otherwise update its text content
|
|
*/
|
|
*/
|
|
- public update() {
|
|
|
|
- this._removeInputWithoutValidating();
|
|
|
|
- this._updateValue();
|
|
|
|
|
|
+ public update() {
|
|
|
|
+ this._removeInputWithoutValidating();
|
|
|
|
+ this._updateValue();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns true if the given instance is a simple type
|
|
* Returns true if the given instance is a simple type
|
|
*/
|
|
*/
|
|
- private static _IS_TYPE_SIMPLE(inst:any) {
|
|
|
|
|
|
+ private static _IS_TYPE_SIMPLE(inst: any) {
|
|
let type = Helpers.GET_TYPE(inst);
|
|
let type = Helpers.GET_TYPE(inst);
|
|
return PropertyLine._SIMPLE_TYPE.indexOf(type) != -1;
|
|
return PropertyLine._SIMPLE_TYPE.indexOf(type) != -1;
|
|
}
|
|
}
|
|
@@ -303,21 +317,21 @@ module INSPECTOR {
|
|
* Returns true if the type of this property is simple, false otherwise.
|
|
* Returns true if the type of this property is simple, false otherwise.
|
|
* Returns true if the value is null
|
|
* Returns true if the value is null
|
|
*/
|
|
*/
|
|
- private _isSimple() : boolean {
|
|
|
|
|
|
+ private _isSimple(): boolean {
|
|
if (this.value != null && this.type !== 'type_not_defined') {
|
|
if (this.value != null && this.type !== 'type_not_defined') {
|
|
if (PropertyLine._SIMPLE_TYPE.indexOf(this.type) == -1) {
|
|
if (PropertyLine._SIMPLE_TYPE.indexOf(this.type) == -1) {
|
|
// complex type : return the type name
|
|
// complex type : return the type name
|
|
return false;
|
|
return false;
|
|
} else {
|
|
} else {
|
|
// simple type : return value
|
|
// simple type : return value
|
|
- return true;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public toHtml() : HTMLElement {
|
|
|
|
|
|
+ public toHtml(): HTMLElement {
|
|
return this._div;
|
|
return this._div;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -325,7 +339,7 @@ module INSPECTOR {
|
|
* Add sub properties in case of a complex type
|
|
* Add sub properties in case of a complex type
|
|
*/
|
|
*/
|
|
private _addDetails() {
|
|
private _addDetails() {
|
|
- if (this._div.classList.contains('unfolded')) {
|
|
|
|
|
|
+ if (this._div.classList.contains('unfolded')) {
|
|
// Remove class unfolded
|
|
// Remove class unfolded
|
|
this._div.classList.remove('unfolded');
|
|
this._div.classList.remove('unfolded');
|
|
// remove html children
|
|
// remove html children
|
|
@@ -335,23 +349,23 @@ module INSPECTOR {
|
|
} else {
|
|
} else {
|
|
// if children does not exists, generate it
|
|
// if children does not exists, generate it
|
|
this._div.classList.toggle('unfolded');
|
|
this._div.classList.toggle('unfolded');
|
|
- if (this._children.length ==0) {
|
|
|
|
|
|
+ if (this._children.length == 0) {
|
|
let objToDetail = this.value;
|
|
let objToDetail = this.value;
|
|
let propToDisplay = PROPERTIES[Helpers.GET_TYPE(objToDetail)].properties.reverse();
|
|
let propToDisplay = PROPERTIES[Helpers.GET_TYPE(objToDetail)].properties.reverse();
|
|
let propertyLine = null;
|
|
let propertyLine = null;
|
|
-
|
|
|
|
|
|
+
|
|
for (let prop of propToDisplay) {
|
|
for (let prop of propToDisplay) {
|
|
let infos = new Property(prop, this._property.value);
|
|
let infos = new Property(prop, this._property.value);
|
|
- let child = new PropertyLine(infos, this, this._level+PropertyLine._MARGIN_LEFT);
|
|
|
|
|
|
+ let child = new PropertyLine(infos, this, this._level + PropertyLine._MARGIN_LEFT);
|
|
this._children.push(child);
|
|
this._children.push(child);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
// otherwise display it
|
|
// otherwise display it
|
|
for (let child of this._children) {
|
|
for (let child of this._children) {
|
|
this._div.parentNode.insertBefore(child.toHtml(), this._div.nextSibling);
|
|
this._div.parentNode.insertBefore(child.toHtml(), this._div.nextSibling);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|