r3-legacy/src/game-lib-system-gui.js

1831 lines
50 KiB
JavaScript
Raw Normal View History

2017-06-19 15:54:02 +02:00
/**
* System takes care of updating all the entities (based on their component data)
* @param apiSystem GameLib.API.System
* @constructor
*/
GameLib.System.GUI = function(
apiSystem
) {
GameLib.System.call(
this,
apiSystem
);
2017-06-29 15:23:50 +02:00
this.guis = [];
2017-08-23 17:53:06 +02:00
this.components = [];
/**
* When we want to show a specific set of components - we backup the current components and then restore them
* later when we are done.
* @type {null}
*/
2017-08-24 22:20:40 +02:00
this.backupComponents = [];
2017-08-23 17:53:06 +02:00
this.exclusiveMode = false;
2017-06-29 15:23:50 +02:00
this.buildGUISubscription = null;
this.meshDeletedSubscription = null;
this.meshSelectedSubscription = null;
this.meshDeselectedSubscription = null;
this.newEntitySubscription = null;
this.meshSelectionObjects = {};
2017-06-19 15:54:02 +02:00
};
GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype);
GameLib.System.GUI.prototype.constructor = GameLib.System.GUI;
GameLib.System.GUI.prototype.start = function() {
GameLib.System.prototype.start.call(this);
2017-06-29 15:23:50 +02:00
this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
2017-06-19 15:54:02 +02:00
/**
* Add some GUI behaviour
*/
dat.GUI.prototype.removeEmtpyFolders = function() {
for (var property in this.__folders) {
if (this.__folders.hasOwnProperty(property)){
var folder = this.__folders[property];
if (folder.__listening.length === 0) {
folder.close();
this.__ul.removeChild(folder.domElement.parentNode);
delete this.__folders[property];
this.onResize();
}
}
}
};
dat.GUI.prototype.listen = function(controller) {
const init = this.__listening.length === 0;
this.__listening.push(controller);
delete this.closed;
Object.defineProperty(this, 'closed', {
get: function() {
return this.params.closed;
},
set: function(v) {
2017-09-05 05:22:52 +02:00
// console.log('override here too');
this.params.closed = v;
if (this.params.closed) {
this.dom.addClass(this.__ul, 'closed');
cancelAnimationFrame(this.animationId);
} else {
this.dom.removeClass(this.__ul, 'closed');
this.updateDisplaysCallback = function() {
/**
* We store the animationFrameId so we can remove this callback later
*/
this.animationId = requestAnimationFrame(this.updateDisplaysCallback.bind(this));
this.__listening.map(function(controller){
controller.updateDisplay();
});
}.bind(this);
this.animationId = requestAnimationFrame(this.updateDisplaysCallback);
}
// For browsers that aren't going to respect the CSS transition,
// Lets just check our height against the window height right off
// the bat.
this.onResize();
if (this.__closeButton) {
this.__closeButton.innerHTML = v ? 'Open Controls' : 'Close Controls';
}
},
configurable: true
});
};
dat.GUI.prototype.removeAllFolders = function() {
for (var property in this.__folders) {
if (this.__folders.hasOwnProperty(property)){
var folder = this.__folders[property];
/**
* Theres a big 'TODO' in the controller remove() function to actually remove the listener
* That's what we are going to do now.. - because it really fucks with the framerate eventually
*/
cancelAnimationFrame(folder.animationId);
folder.__controllers.map(
function(controller) {
controller.remove();
}
);
folder.__controllers = [];
folder.__listening = [];
/**
* Call UpdateDisplays with
*/
folder.close();
this.__ul.removeChild(folder.domElement.parentNode);
delete this.__folders[property];
this.onResize();
}
}
};
2017-06-29 15:23:50 +02:00
this.guis.map(function(gui){
2017-06-19 15:54:02 +02:00
gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
2017-06-29 15:23:50 +02:00
});
this.buildGUISubscription = this.subscribe(
GameLib.Event.BUILD_GUI,
this.buildGUI
);
this.meshDeletedSubscription = this.subscribe(
2017-10-27 15:03:16 +02:00
GameLib.Event.REMOVE_MESH,
2017-06-29 15:23:50 +02:00
this.meshDeleted
);
this.meshSelectedSubscription = this.subscribe(
GameLib.Event.MESH_SELECTED,
2017-08-23 17:53:06 +02:00
this.meshSelected
2017-06-29 15:23:50 +02:00
);
this.meshDeselectedSubscription = this.subscribe(
GameLib.Event.MESH_DESELECTED,
2017-08-23 17:53:06 +02:00
this.meshDeslected
2017-06-29 15:23:50 +02:00
);
this.newEntitySubscription = this.subscribe(
GameLib.Event.NEW_ENTITY,
this.newEntity
2017-08-23 17:53:06 +02:00
);
this.componentRemovedSubscription = this.subscribe(
2017-10-27 15:03:16 +02:00
GameLib.Event.REMOVE_COMPONENT,
2017-08-23 17:53:06 +02:00
this.removeComponent
)
};
GameLib.System.GUI.prototype.onChange = function(property, subProperty, affected) {
return function(value) {
affected.map(function(component){
component[property][subProperty] = value;
2017-10-03 14:50:34 +02:00
if (component instanceof GameLib.D3.Mesh && property === 'rotation') {
component.useQuaternion = false;
}
if (component instanceof GameLib.D3.Mesh && property === 'quaternion') {
component.useQuaternion = true;
}
if (typeof component[property].updateInstance === 'function') {
2017-11-05 15:53:23 +01:00
component[property].updateInstance(property);
} else if (typeof component[property][subProperty].updateInstance === 'function') {
2017-11-05 15:53:23 +01:00
component[property][subProperty].updateInstance(subProperty);
} else {
2017-11-05 15:53:23 +01:00
component.updateInstance(property);
}
});
}
};
2017-09-10 13:10:49 +02:00
GameLib.System.GUI.prototype.controller = function(folder, object, property, subProperty, step, listen, affected, min, max) {
2017-09-10 13:10:49 +02:00
if (GameLib.Utils.UndefinedOrNull(min)) {
2017-11-10 19:04:26 +01:00
min = -1000;
2017-09-10 13:10:49 +02:00
}
if (GameLib.Utils.UndefinedOrNull(max)) {
2017-11-10 19:04:26 +01:00
max = 1000;
2017-09-10 13:10:49 +02:00
}
if (
// property === 'chassisConnectionPointLocal' ||
property === 'axleLocal' ||
property === 'directionLocal'
) {
min = -1;
max = 1;
step = 1;
}
var handle = folder.add(
object[property],
subProperty,
min,
max,
step
).name(property + '.' + subProperty);
handle.onChange(this.onChange(property, subProperty, affected));
if (listen) {
handle.listen();
}
return handle;
};
GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, componentTemplate, property) {
var step = 0.1;
var object = componentTemplate.template;
var listen = false;
if (componentTemplate.affected.length === 1) {
/**
* If the template only affects a single object - put the handle on this so we can listen for changes
*/
object = componentTemplate.affected[0];
listen = true;
}
var affected = componentTemplate.affected;
this.controller(folder, object, property, 'x', step, listen, affected);
this.controller(folder, object, property, 'y', step, listen, affected);
this.controller(folder, object, property, 'z', step, listen, affected);
this.controller(folder, object, property, 'w', step, listen, affected);
2017-09-10 13:10:49 +02:00
this.controller(folder, object, property, 'angle', 0.001, listen, affected, -Math.PI, Math.PI);
2017-09-05 13:18:10 +02:00
folder.add(
object[property]['axis'],
'x',
-1,
1,
0.01
2017-09-10 13:10:49 +02:00
).name('quaternion.axis.x').onChange(
2017-09-05 13:18:10 +02:00
function(value) {
affected.map(function(component){
2017-10-03 14:50:34 +02:00
component.useQuaternion = true;
2017-09-05 13:18:10 +02:00
component[property]['axis'].x = Number(value);
component.updateInstance();
})
}
);
2017-09-05 13:18:10 +02:00
folder.add(
object[property]['axis'],
'y',
-1,
1,
0.01
2017-09-10 13:10:49 +02:00
).name('quaternion.axis.y').onChange(
2017-09-05 13:18:10 +02:00
function(value) {
affected.map(function(component){
2017-10-03 14:50:34 +02:00
component.useQuaternion = true;
2017-09-05 13:18:10 +02:00
component[property]['axis'].y = Number(value);
component.updateInstance();
})
}
);
folder.add(
object[property]['axis'],
'z',
-1,
1,
0.01
2017-09-10 13:10:49 +02:00
).name('quaternion.axis.z').onChange(
2017-09-05 13:18:10 +02:00
function(value) {
affected.map(function(component){
2017-10-03 14:50:34 +02:00
component.useQuaternion = true;
2017-09-05 13:18:10 +02:00
component[property]['axis'].z = Number(value);
component.updateInstance();
})
}
);
};
GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemplate, property) {
2017-08-23 17:53:06 +02:00
2017-09-29 06:09:47 +02:00
var step = 0.01;
2017-08-23 17:53:06 +02:00
var object = componentTemplate.template;
var listen = false;
if (componentTemplate.affected.length === 1) {
/**
* If the template only affects a single object - put the handle on this so we can listen for changes
*/
object = componentTemplate.affected[0];
listen = true;
}
var affected = componentTemplate.affected;
2017-08-23 17:53:06 +02:00
var controllers = [];
2017-08-23 17:53:06 +02:00
if (GameLib.Utils.isVector4(object[property])) {
controllers.push(this.controller(folder, object, property, 'w', step, listen, affected));
2017-08-23 17:53:06 +02:00
}
controllers.push(this.controller(folder, object, property, 'x', step, listen, affected));
controllers.push(this.controller(folder, object, property, 'y', step, listen, affected));
2017-08-23 17:53:06 +02:00
if (
GameLib.Utils.isVector3(object[property]) ||
GameLib.Utils.isVector4(object[property])
2017-08-23 17:53:06 +02:00
) {
controllers.push(this.controller(folder, object, property, 'z', step, listen, affected));
2017-08-23 17:53:06 +02:00
}
2017-08-23 17:53:06 +02:00
};
/**
* Builds an Entity Selection control
* @param folder
* @param componentTemplate
*/
2017-09-05 13:18:10 +02:00
GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, componentTemplate, property) {
var constructor = null;
if (property === 'parentEntity') {
constructor = GameLib.Entity;
}
if (property === 'parentMesh') {
constructor = GameLib.D3.Mesh;
2017-09-05 13:18:10 +02:00
}
2017-08-23 17:53:06 +02:00
if (property === 'parentWorld') {
constructor = GameLib.D3.PhysicsWorld;
}
if (property === 'parentScene') {
constructor = GameLib.D3.Scene;
}
var options = GameLib.EntityManager.Instance.queryComponents(constructor).reduce(
2017-09-05 13:18:10 +02:00
function(result, object) {
result[object.name] = object;
2017-08-23 17:53:06 +02:00
return result;
},
{
'none' : null
}
);
var object = componentTemplate.template;
var affected = componentTemplate.affected;
2017-09-05 13:18:10 +02:00
folder.add(object, property, options).listen().onChange(
2017-08-23 17:53:06 +02:00
function(value) {
2017-09-05 13:18:10 +02:00
var newComponent = null;
2017-08-23 17:53:06 +02:00
2017-09-05 13:18:10 +02:00
if (value !== 'null') {
newComponent = GameLib.EntityManager.Instance.findComponentById(value);
}
2017-08-23 17:53:06 +02:00
2017-09-05 13:18:10 +02:00
affected.map(
function(component) {
2017-08-23 17:53:06 +02:00
2017-09-05 13:18:10 +02:00
component[property] = newComponent;
2017-08-23 17:53:06 +02:00
2017-09-05 13:18:10 +02:00
if (property === 'parentEntity') {
GameLib.Event.Emit(
GameLib.Event.PARENT_ENTITY_CHANGE,
{
originalEntity : this.initialValue,
newEntity : newComponent,
object : component
}
);
}
2017-08-23 17:53:06 +02:00
if (property === 'parentWorld') {
GameLib.Event.Emit(
GameLib.Event.PARENT_WORLD_CHANGE,
{
originalWorld : this.initialValue,
newWorld : newComponent,
object : component
}
)
}
if (property === 'parentScene') {
GameLib.Event.Emit(
GameLib.Event.PARENT_SCENE_CHANGE,
{
originalScene: this.initialValue,
newScene: newComponent,
object: component
}
);
}
2017-09-05 13:18:10 +02:00
}.bind(this)
);
if (property === 'parentEntity') {
GameLib.Event.Emit(
GameLib.Event.BUILD_GUI,
null
);
}
this.initialValue = newComponent;
2017-08-23 17:53:06 +02:00
}
);
};
GameLib.System.GUI.prototype.buildArrayManagerControl = function(
folder,
componentTemplate,
property
2017-08-23 17:53:06 +02:00
) {
var constructors = componentTemplate.template.linkedObjects[property];
if (constructors instanceof Array) {
/**
* All good
*/
} else {
/**
* There is a data mismatch
*/
console.error('data mismatch - something not an array');
return;
}
var object = componentTemplate.template;
var array = object[property];
var addArrayItem = function(item, index){
var name = 'invalid item';
if (item && item.name) {
name = item.name;
}
var controller = folder.add(
{
'remove' : function() {
componentTemplate.affected.map(function(component){
component[property].splice(index, 1);
folder.remove(controller);
});
}
},
'remove'
).name('remove ' + property + '[' + index + '] - ' + name);
folder.updateDisplay();
};
array.map(addArrayItem);
2017-10-27 10:09:34 +02:00
var idObject = {};
var selectionObject = GameLib.EntityManager.Instance.queryComponents(constructors).reduce(
function(result, component) {
result[component.name] = component;
2017-10-27 10:09:34 +02:00
idObject[component.id] = component;
return result;
},
{
'none' : null
}
);
var activeSelection = {
component: null,
add: function () {
componentTemplate.affected.map(function (component) {
if (component[property].indexOf(activeSelection.component) === -1) {
component[property].push(activeSelection.component);
2017-09-05 05:22:52 +02:00
GameLib.Event.Emit(
GameLib.Event.ARRAY_ITEM_ADDED,
{
component : component,
property : property,
item : activeSelection.component
}
);
// addArrayItem(activeSelection.component, component[property].length - 1);
}
});
GameLib.Event.Emit(
GameLib.Event.BUILD_GUI
);
}
};
folder.add(activeSelection, 'component', selectionObject).name('select ' + property).onChange(
function(value){
if (value === 'null') {
activeSelection['component'] = null;
} else {
2017-10-27 10:09:34 +02:00
activeSelection['component'] = idObject[value];
}
}
).listen();
folder.add(activeSelection, 'add').name('add to ' + property);
2017-08-23 17:53:06 +02:00
};
2017-08-24 22:20:40 +02:00
GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTemplate, property) {
2017-08-23 17:53:06 +02:00
2017-08-24 22:20:40 +02:00
var object = componentTemplate.template;
var tempObject = {
hexColor : object[property].toHex()
};
2017-08-24 22:20:40 +02:00
folder.addColor(
tempObject,
2017-08-24 22:20:40 +02:00
'hexColor'
).name(property).listen().onChange(
function(value) {
componentTemplate.affected.map(
function(component) {
component[property].fromHex(value);
component[property].updateInstance(property);
2017-08-24 22:20:40 +02:00
}
)
}
);
folder.add(
tempObject,
'hexColor'
).name(property).listen().onChange(
function(value) {
componentTemplate.affected.map(
function(component) {
component[property].fromHex(value);
component[property].updateInstance(property);
}
)
}
)
2017-08-24 22:20:40 +02:00
};
GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemplate, property) {
/**
* We need to discover the constructor for this component
*/
var constructor = null;
if (componentTemplate.template[property]) {
constructor = componentTemplate.template[property].constructor;
} else {
if (componentTemplate.template.linkedObjects[property]) {
constructor = componentTemplate.template.linkedObjects[property];
}
}
2017-08-24 22:20:40 +02:00
var object = componentTemplate.template;
var objects = GameLib.EntityManager.Instance.queryComponents(constructor);
2017-08-23 17:53:06 +02:00
2017-10-27 10:09:34 +02:00
var idObject = {};
2017-08-23 17:53:06 +02:00
var options = objects.reduce(
function(result, obj) {
result[obj.name] = obj;
2017-10-27 10:09:34 +02:00
idObject[obj.id] = obj;
2017-08-23 17:53:06 +02:00
return result;
},
{
'none' : null
}
);
folder.add(
object,
property,
options
).name(property).listen().onChange(
2017-08-24 22:20:40 +02:00
function (value) {
2017-08-23 17:53:06 +02:00
2017-08-24 22:20:40 +02:00
var newComponent = null;
2017-08-23 17:53:06 +02:00
2017-08-24 22:20:40 +02:00
if (value !== 'null') {
2017-10-27 10:09:34 +02:00
newComponent = idObject[value];
2017-08-24 22:20:40 +02:00
}
2017-08-23 17:53:06 +02:00
2017-08-24 22:20:40 +02:00
componentTemplate.affected.map(
function(component) {
component[property] = newComponent;
component.updateInstance();
}
);
2017-08-23 17:53:06 +02:00
2017-08-24 22:20:40 +02:00
this.initialValue = newComponent;
}
2017-08-23 17:53:06 +02:00
);
};
GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, property) {
var object = componentTemplate.template;
2017-08-24 22:20:40 +02:00
var listen = false;
if (componentTemplate.affected.length === 1) {
/**
* If the template only affects a single object - put the handle on this so we can listen for changes
*/
object = componentTemplate.affected[0];
2017-08-24 22:20:40 +02:00
listen = true;
}
2017-08-23 17:53:06 +02:00
var componentType = componentTemplate.componentType;
var controllers = [];
2017-08-23 17:53:06 +02:00
if (
GameLib.Utils.isString(object[property]) ||
GameLib.Utils.isBoolean(object[property])
) {
controllers.push(folder.add(object, property));
2017-08-23 17:53:06 +02:00
}
if (GameLib.Utils.isNumber(object[property])) {
var grain = 0.001;
if (object.grain) {
grain = object.grain;
}
if (property === 'systemType') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'animation' : GameLib.System.SYSTEM_TYPE_ANIMATION,
'gui' : GameLib.System.SYSTEM_TYPE_GUI,
'input' : GameLib.System.SYSTEM_TYPE_INPUT,
'render' : GameLib.System.SYSTEM_TYPE_RENDER,
'storage' : GameLib.System.SYSTEM_TYPE_STORAGE,
'linking' : GameLib.System.SYSTEM_TYPE_LINKING,
'physics' : GameLib.System.SYSTEM_TYPE_PHYSICS,
'custom code' : GameLib.System.SYSTEM_TYPE_CUSTOM
2017-08-23 17:53:06 +02:00
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
2017-11-13 15:22:08 +01:00
} else if (property === 'opacityType') {
controllers.push(
folder.add(
object,
property,
{
'constant': GameLib.D3.Particle.OPACITY_TYPE_CONSTANT,
'decrease': GameLib.D3.Particle.OPACITY_TYPE_DECREASE_LINEAR,
'increase': GameLib.D3.Particle.OPACITY_TYPE_INCREASE_LINEAR
}
)
);
} else if (property === 'positionOffsetType') {
2017-11-13 07:28:51 +01:00
controllers.push(
folder.add(
object,
property,
{
'constant': GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT,
'random': GameLib.D3.Particle.POSITION_OFFSET_TYPE_RANDOM,
'function': GameLib.D3.Particle.POSITION_OFFSET_TYPE_FUNCTION
}
)
);
} else if (property === 'directionType') {
controllers.push(
folder.add(
object,
property,
{
'constant': GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT,
'random': GameLib.D3.Particle.DIRECTION_TYPE_RANDOM,
'function': GameLib.D3.Particle.DIRECTION_TYPE_FUNCTION
}
)
);
} else if (property === 'scaleType') {
controllers.push(
folder.add(
object,
property,
{
'constant': GameLib.D3.Particle.SCALE_TYPE_CONSTANT,
'linear': GameLib.D3.Particle.SCALE_TYPE_LINEAR,
'exponential': GameLib.D3.Particle.SCALE_TYPE_EXPONENTIAL,
'random': GameLib.D3.Particle.SCALE_TYPE_RANDOM,
2017-11-13 15:06:59 +01:00
'random (x = y)': GameLib.D3.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y,
2017-11-13 07:28:51 +01:00
'function': GameLib.D3.Particle.SCALE_TYPE_FUNCTION
}
)
);
} else if (property === 'rotationType') {
controllers.push(
folder.add(
object,
property,
{
'constant': GameLib.D3.Particle.ROTATION_TYPE_CONSTANT,
'random': GameLib.D3.Particle.ROTATION_TYPE_RANDOM,
'function': GameLib.D3.Particle.ROTATION_TYPE_FUNCTION
}
)
);
} else if (property === 'broadphaseType') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'naive': GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE,
'grid': GameLib.D3.Image.BROADPHASE_TYPE_GRID,
'sap': GameLib.D3.Image.BROADPHASE_TYPE_SAP
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
2017-09-05 05:22:52 +02:00
} else if (property === 'solverType') {
controllers.push(
folder.add(
object,
property,
{
'gs': GameLib.D3.Solver.GS_SOLVER,
'split': GameLib.D3.Solver.SPLIT_SOLVER
}
)
);
} else if (property === 'meshType') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'normal' : GameLib.D3.Mesh.MESH_TYPE_NORMAL,
'curve' : GameLib.D3.Mesh.MESH_TYPE_CURVE,
'skinned' : GameLib.D3.Mesh.MESH_TYPE_SKINNED,
'plane' : GameLib.D3.Mesh.MESH_TYPE_PLANE,
2017-09-05 05:22:52 +02:00
'sphere' : GameLib.D3.Mesh.MESH_TYPE_SPHERE,
'box' : GameLib.D3.Mesh.MESH_TYPE_BOX,
'cylinder' : GameLib.D3.Mesh.MESH_TYPE_CYLINDER,
'text' : GameLib.D3.Mesh.MESH_TYPE_TEXT
2017-08-23 17:53:06 +02:00
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'cameraType') {
controllers.push(
folder.add(
object,
property,
{
'perspective' : GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE,
'orthographic' : GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL
}
)
);
} else if (property === 'materialType') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'standard': GameLib.D3.Material.MATERIAL_TYPE_STANDARD,
'basic': GameLib.D3.Material.MATERIAL_TYPE_BASIC,
'phong': GameLib.D3.Material.MATERIAL_TYPE_PHONG,
'points': GameLib.D3.Material.MATERIAL_TYPE_POINTS,
'line basic' : GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC
2017-08-23 17:53:06 +02:00
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'side') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'double': GameLib.D3.Material.TYPE_DOUBLE_SIDE,
'front': GameLib.D3.Material.TYPE_FRONT_SIDE,
'back': GameLib.D3.Material.TYPE_BACK_SIDE
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'combine') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'multiply': GameLib.D3.Material.TYPE_MULTIPLY_OPERATION,
'mix': GameLib.D3.Material.TYPE_MIX_OPERATION,
'add': GameLib.D3.Material.TYPE_ADD_OPERATION
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'vertexColors') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'none': GameLib.D3.Material.TYPE_NO_COLORS,
'face': GameLib.D3.Material.TYPE_FACE_COLORS,
'vertex': GameLib.D3.Material.TYPE_VERTEX_COLORS
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'blending') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'normal': GameLib.D3.Material.TYPE_NORMAL_BLENDING,
'additive': GameLib.D3.Material.TYPE_ADDITIVE_BLENDING,
'subtractive': GameLib.D3.Material.TYPE_SUBTRACTIVE_BLENDING,
'multiply': GameLib.D3.Material.TYPE_MULTIPLY_BLENDING
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'blendSrc') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
2017-08-24 22:20:40 +02:00
property,
{
'zero': GameLib.D3.Material.TYPE_ZERO_FACTOR,
'one': GameLib.D3.Material.TYPE_ONE_FACTOR,
'source color': GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,
'one minus source color': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,
'source alpha': GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,
'one minus source alpha': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,
'destination alpha': GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,
'one minus destination alpha': GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,
'destination color': GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,
'one minus destination color': GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,
'source alpha saturate': GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR
}
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'blendDst') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'zero': GameLib.D3.Material.TYPE_ZERO_FACTOR,
'one': GameLib.D3.Material.TYPE_ONE_FACTOR,
'source color': GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,
'one minus source color': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,
'source alpha': GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,
'one minus source alpha': GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,
'destination alpha': GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,
'one minus destination alpha': GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,
'destination color': GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,
'one minus destination color': GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,
'source alpha saturate': GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'blendEquation') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'add': GameLib.D3.Material.TYPE_ADD_EQUATION,
'subtract': GameLib.D3.Material.TYPE_SUBTRACT_EQUATION,
'reverse subtract': GameLib.D3.Material.TYPE_REVERSE_SUBTRACT_EQUATION,
'min': GameLib.D3.Material.TYPE_MIN_EQUATION,
'max': GameLib.D3.Material.TYPE_MAX_EQUATION
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'depthFunc') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'never': GameLib.D3.Material.TYPE_NEVER_DEPTH,
'always': GameLib.D3.Material.TYPE_ALWAYS_DEPTH,
'less depth': GameLib.D3.Material.TYPE_LESS_DEPTH,
'less equal depth': GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH,
'equal depth': GameLib.D3.Material.TYPE_EQUAL_DEPTH,
'greated equal depth': GameLib.D3.Material.TYPE_GREATER_EQUAL_DEPTH,
'greated depth': GameLib.D3.Material.TYPE_GREATER_DEPTH,
'not equal depth': GameLib.D3.Material.TYPE_NOT_EQUAL_DEPTH
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'wrapS') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'repeat': GameLib.D3.Texture.TYPE_REPEAT_WRAPPING,
'clamp': GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING,
'mirrored repeat': GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'wrapT') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'repeat': GameLib.D3.Texture.TYPE_REPEAT_WRAPPING,
'clamp': GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING,
'mirrored repeat': GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'format') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'alpha': GameLib.D3.Texture.TYPE_ALPHA_FORMAT,
'rgb': GameLib.D3.Texture.TYPE_RGB_FORMAT,
'rgba': GameLib.D3.Texture.TYPE_RGBA_FORMAT,
'luminance': GameLib.D3.Texture.TYPE_LUMINANCE_FORMAT,
'luminance alpha': GameLib.D3.Texture.TYPE_LUMINANCE_ALPHA_FORMAT,
'depth': GameLib.D3.Texture.TYPE_DEPTH_FORMAT
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'mapping') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'uv': GameLib.D3.Texture.TYPE_UV_MAPPING,
'cube reflection': GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING,
'cube refraction': GameLib.D3.Texture.TYPE_CUBE_REFRACTION_MAPPING,
'equi rectangular reflection': GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING,
'equi rectangular refraction': GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING,
'spherical reflection': GameLib.D3.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING,
'cube uv reflection': GameLib.D3.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING,
'cube uv refraction': GameLib.D3.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'magFilter') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'nearest': GameLib.D3.Texture.TYPE_NEAREST_FILTER,
'nearest mipmap nearest': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,
'nearest mipmap linear': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,
'linear': GameLib.D3.Texture.TYPE_LINEAR_FILTER,
'linear mipmap nearest': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,
'linear mipmap linear': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'minFilter') {
controllers.push(
2017-08-24 22:20:40 +02:00
folder.add(
object,
property,
{
'nearest': GameLib.D3.Texture.TYPE_NEAREST_FILTER,
'nearest mipmap nearest': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,
'nearest mipmap linear': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,
'linear': GameLib.D3.Texture.TYPE_LINEAR_FILTER,
'linear mipmap nearest': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,
'linear mipmap linear': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER
}
)
2017-08-23 17:53:06 +02:00
);
} else if (componentType === GameLib.Component.COMPONENT_TEXTURE && property === 'typeId') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'normal': GameLib.D3.Texture.TEXTURE_TYPE_NORMAL,
2017-10-23 14:52:35 +02:00
'cube': GameLib.D3.Texture.TEXTURE_TYPE_CUBE,
'canvas': GameLib.D3.Texture.TEXTURE_TYPE_CANVAS
2017-08-23 17:53:06 +02:00
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'textureType') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'unsigned byte': GameLib.D3.Texture.TYPE_UNSIGNED_BYTE,
'byte': GameLib.D3.Texture.TYPE_BYTE,
'short': GameLib.D3.Texture.TYPE_SHORT,
'unsigned short': GameLib.D3.Texture.TYPE_UNSIGNED_SHORT,
'int': GameLib.D3.Texture.TYPE_INT,
'unsigned int': GameLib.D3.Texture.TYPE_UNSIGNED_INT,
'float': GameLib.D3.Texture.TYPE_FLOAT,
'half float': GameLib.D3.Texture.TYPE_HALF_FLOAT
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'encoding') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'linear': GameLib.D3.Texture.TYPE_LINEAR_ENCODING,
'srgb': GameLib.D3.Texture.TYPE_SRGB_ENCODING,
'gamma': GameLib.D3.Texture.TYPE_GAMMA_ENCODING,
'rgbe': GameLib.D3.Texture.TYPE_RGBE_ENCODING,
'log luv': GameLib.D3.Texture.TYPE_LOG_LUV_ENCODING,
'rgbm7': GameLib.D3.Texture.TYPE_RGBM7_ENCODING,
'rgbm16': GameLib.D3.Texture.TYPE_RGBM16_ENCODING,
'rgbd': GameLib.D3.Texture.TYPE_RGBD_ENCODING
}
2017-08-24 22:20:40 +02:00
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'lightType') {
controllers.push(
2017-08-23 17:53:06 +02:00
folder.add(
object,
property,
{
'ambient': GameLib.D3.Light.LIGHT_TYPE_AMBIENT,
'directional': GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL,
'spot': GameLib.D3.Light.LIGHT_TYPE_SPOT,
'point': GameLib.D3.Light.LIGHT_TYPE_POINT
}
2017-08-24 22:20:40 +02:00
)
);
} else if (property === 'eventId') {
var options = {};
for (var i = 0; i < 200; i++) {
try {
options[GameLib.Event.GetEventName(i)] = i;
} catch (error) {
}
}
controllers.push(
2017-08-24 22:20:40 +02:00
folder.add(
object,
property,
options
)
2017-08-23 17:53:06 +02:00
);
} else if (property === 'functionType') {
controllers.push(
folder.add(
object,
property,
{
'rotation': GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION,
'translation': GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION,
'scale': GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE
}
)
);
} else {
2017-08-23 17:53:06 +02:00
/**
* Try to guess a scale for this property
*/
if (
property === 'opacity' ||
2017-11-13 15:22:08 +01:00
property === 'opacityFactor' ||
2017-08-23 17:53:06 +02:00
property === 'metalness' ||
property === 'roughness'
) {
controllers.push(folder.add(object, property, 0, 1.0, 0.001));
2017-08-23 17:53:06 +02:00
} else if (
property === 'shininess' ||
property === 'fov'
) {
controllers.push(folder.add(object, property, -255, 255, 1));
2017-08-23 17:53:06 +02:00
} else if (
2017-09-05 13:18:10 +02:00
property === 'aspect' ||
property === 'wireframeLineWidth' ||
property === 'lineWidth'
2017-09-01 17:06:04 +02:00
) {
controllers.push(folder.add(object, property, 0, 5, 0.001));
2017-08-23 17:53:06 +02:00
} else if (
property === 'bumpScale' ||
property === 'normalScale' ||
property === 'displacementScale' ||
2017-09-01 17:06:04 +02:00
property === 'heightMapScale' ||
property === 'intensity'
) {
controllers.push(folder.add(object, property, -10, 10, 0.001));
} else if (
property === 'minX' ||
property === 'minY' ||
property === 'minZ' ||
property === 'maxX' ||
property === 'maxY' ||
2017-10-05 14:35:22 +02:00
property === 'maxZ' ||
property === 'offsetX'
) {
2017-11-10 19:04:26 +01:00
controllers.push(folder.add(object, property, -1000, 1000, 0.01));
2017-09-01 17:06:04 +02:00
} else if (
2017-08-23 17:53:06 +02:00
property === 'widthSegments' ||
2017-09-05 05:22:52 +02:00
property === 'radiusSegments' ||
2017-11-05 15:53:23 +01:00
property === 'heightSegments' ||
property === 'particlesPerSecond'
2017-08-23 17:53:06 +02:00
) {
controllers.push(folder.add(object, property, 1, 1000, 1));
2017-08-23 17:53:06 +02:00
} else if (
property === 'width' ||
property === 'height' ||
2017-09-05 13:18:10 +02:00
property === 'depth' ||
property === 'radius'
2017-08-23 17:53:06 +02:00
) {
2017-10-30 16:30:00 +01:00
controllers.push(folder.add(object, property, 0, 1000, 0.1));
2017-08-23 17:53:06 +02:00
} else if (
property === 'near' ||
property === 'distanceGrain' ||
property === 'envMapIntensity'
) {
controllers.push(folder.add(object, property, -10, 100, 0.001));
} else if (
property === 'bumpScale'
) {
controllers.push(folder.add(object, property, 0, 20, 0.001));
2017-08-23 17:53:06 +02:00
} else if (
property === 'heightOffset' ||
property === 'rotationFactor'
) {
controllers.push(folder.add(object, property, -100, 100, 0.001));
2017-09-05 05:22:52 +02:00
} else if (
property === 'friction'
2017-09-05 05:22:52 +02:00
) {
controllers.push(folder.add(object, property, 0, 1000, 0.01));
2017-10-30 16:30:00 +01:00
} else if (
property === 'radiusTop' ||
property === 'radiusBottom'
) {
controllers.push(folder.add(object, property, 0, 100, 0.1));
} else if (
property === 'mass'
) {
controllers.push(folder.add(object, property, 0, 1000, 0.1));
2017-09-29 07:00:37 +02:00
} else if (
property === 'sensitivity'
) {
controllers.push(folder.add(object, property, 1, 50, 1));
} else if (
2017-09-05 13:18:10 +02:00
property === 'thetaLength' ||
property === 'angle'
2017-09-05 05:22:52 +02:00
) {
controllers.push(folder.add(object, property, -Math.PI * 2, Math.PI * 2, 0.01));
} else {
2017-11-05 15:53:23 +01:00
controllers.push(folder.add(object, property, -1000, 1000, 0.1));
2017-08-23 17:53:06 +02:00
}
}
}
controllers.map(
function(controller) {
2017-08-24 22:20:40 +02:00
2017-08-23 17:53:06 +02:00
if (property === 'name') {
controller.onFinishChange(
2017-08-24 22:20:40 +02:00
function(__handle, __folder) {
2017-08-23 17:53:06 +02:00
return function(value) {
2017-08-24 22:20:40 +02:00
2017-08-23 17:53:06 +02:00
componentTemplate.affected.map(
function(component){
component[property] = value;
2017-11-05 15:53:23 +01:00
component.updateInstance(property);
2017-08-23 17:53:06 +02:00
}
);
2017-08-24 22:20:40 +02:00
var li = __folder.domElement.getElementsByClassName('title')[0];
li.innerHTML = value;
2017-08-23 17:53:06 +02:00
}
}(controller, folder)
2017-08-23 17:53:06 +02:00
);
} else {
controller.onChange(
2017-08-23 17:53:06 +02:00
function (value) {
if (typeof this.initialValue === 'number') {
value = Number(value);
}
componentTemplate.affected.map(
function(component){
component[property] = value;
2017-11-05 15:53:23 +01:00
component.updateInstance(property);
2017-08-23 17:53:06 +02:00
}
);
}
);
}
2017-08-24 22:20:40 +02:00
if (listen) {
controller.listen();
2017-08-24 22:20:40 +02:00
}
2017-08-23 17:53:06 +02:00
}
);
};
/**
* Push the mesh to our backup components, if in exclusiveMode (menu at top is selected),
* otherwise, just to our normal components
* @param data
*/
GameLib.System.GUI.prototype.meshSelected = function(data) {
if (this.exclusiveMode) {
GameLib.Utils.PushUnique(this.backupComponents, data.mesh);
} else {
GameLib.Utils.PushUnique(this.components, data.mesh);
}
};
/**
* Same as selected above, but removes the mesh from the components
* @param data
*/
GameLib.System.GUI.prototype.meshDeslected = function(data) {
var index = -1;
if (this.exclusiveMode) {
index = this.backupComponents.indexOf(data.mesh);
if (index !== -1) {
this.backupComponents.splice(index, 1);
}
} else {
index = this.components.indexOf(data.mesh);
if (index !== -1) {
this.components.splice(index, 1);
}
}
2017-06-19 15:54:02 +02:00
};
2017-08-23 17:53:06 +02:00
/**
* This function responds to the BUILD_GUI event, data contains the components to build a GUI for data.
*
* If we send data with components - go into exclusive mode, backup the currently selected components and rebuild the gui
*
* If we send data without components - go out of exclusive mode, restore the backup of the currently selected components
* and rebuild based on the meshes
*
* If we don't send any data (null or undefined) - some parameters changed and just rebuild the gui.
*
2017-08-23 17:53:06 +02:00
* @param data
*/
2017-06-29 15:23:50 +02:00
GameLib.System.GUI.prototype.buildGUI = function(data) {
2017-06-19 15:54:02 +02:00
2017-06-29 15:23:50 +02:00
this.guis.map(function(gui){
/**
2017-08-23 17:53:06 +02:00
* First, start fresh - remove all folders
*/
gui.instance.destroy();
2017-08-23 17:53:06 +02:00
gui.removeAllFolders();
// gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
2017-08-23 17:53:06 +02:00
if (data) {
if (data.components) {
/**
* Check if we are not already in exclusive mode, because we only want to make a backup if
* it does not already exist
2017-08-23 17:53:06 +02:00
*/
if (!this.exclusiveMode) {
this.exclusiveMode = true;
/**
* Backup the current selection
*/
this.backupComponents = this.components.map(
function(component) {
return component;
}
);
}
2017-08-23 17:53:06 +02:00
this.components = data.components.map(
function(component) {
return component;
}
);
2017-08-23 17:53:06 +02:00
} else {
2017-06-29 15:23:50 +02:00
if (this.exclusiveMode) {
this.exclusiveMode = false;
2017-08-23 17:53:06 +02:00
/**
* Time to restore the backup
*/
this.components = this.backupComponents.map(
function(component) {
return component;
}
)
} else {
console.log('we are already not in mesh select mode - not doing anything with the backup');
}
2017-08-23 17:53:06 +02:00
}
}
2017-06-29 15:23:50 +02:00
/**
2017-08-23 17:53:06 +02:00
* For all mesh components - (if not in exclusive mode) - try to discover all materials, textures, etc
*/
2017-08-23 17:53:06 +02:00
if (!this.exclusiveMode) {
/**
* We first remove everything which is not a Mesh
*/
this.components = this.components.filter(
function (component) {
return (component instanceof GameLib.D3.Mesh);
}
);
}
/**
* Check if we have components to build a GUI for
*/
if (GameLib.Utils.UndefinedOrNull(this.components.length) || this.components.length < 1) {
2017-09-01 13:14:14 +02:00
// console.log('no components selected');
2017-08-23 17:53:06 +02:00
return;
}
/**
* Now continue to discover materials, textures, images etc. children of this component
*/
if (!this.exclusiveMode) {
this.components = this.components.reduce(
function(result, component) {
var components = component.getChildrenComponents();
GameLib.Utils.PushUnique(result, component);
components.map(function(component){
GameLib.Utils.PushUnique(result, component);
});
return result;
}.bind(this),
[]
);
}
/**
* Sort the components by component type
*/
2017-08-23 17:53:06 +02:00
this.components.sort(
function(a, b) {
if (a.componentType > b.componentType) {
return 1;
}
if (a.componentType < b.componentType) {
return -1;
}
return 0;
}
);
/**
* Split the components into groups of componentType
*/
2017-08-23 17:53:06 +02:00
var componentGroups = this.components.reduce(
function(result, component) {
var componentData = result.pop();
if (component.componentType === componentData.componentType) {
/**
* This is the first component
*/
componentData.components.push(component);
result.push(componentData);
return result;
}
2017-06-29 15:23:50 +02:00
if (component.componentType !== componentData.componentType) {
result.push(componentData);
result.push({
componentType : component.componentType,
components:[component]
});
return result;
}
2017-06-29 15:23:50 +02:00
},
[
{
2017-08-23 17:53:06 +02:00
componentType : this.components[0].componentType,
components : []
}
]
);
2017-06-29 15:23:50 +02:00
2017-08-23 17:53:06 +02:00
/**
* We have all the components split into groups - now add the individual components
*/
this.components.map(
function(component) {
/**
* Check for possible duplicates
* @type {boolean}
*/
var duplicate = false;
componentGroups.map(function(componentGroup){
if (
componentGroup.componentType === component.componentType &&
componentGroup.components.length === 1 &&
componentGroup.components[0] === component
) {
duplicate = true;
}
});
if (!duplicate) {
GameLib.Utils.PushUnique(
componentGroups,
{
componentType : component.componentType,
components : [component]
}
);
}
}
);
/**
* componentGroups should now contain the whole list of stuff we want to build GUI for.
*/
componentGroups.map(
2017-06-29 15:23:50 +02:00
function(componentGroup){
if (componentGroup.components.length < 1) {
console.warn('invalid number of components');
}
var templateObject = {
template : {
/**
* Doing this here is just to put parentEntity at the top of the gui
*/
'parentEntity' : componentGroup.components[0].parentEntity
},
affected : [componentGroup.components[0]],
componentType : componentGroup.componentType
};
for (var property in componentGroup.components[0]) {
if (
componentGroup.components[0].hasOwnProperty(property) ||
typeof componentGroup.components[0][property] === 'function'
) {
if (typeof componentGroup.components[0][property] === 'function') {
templateObject.template[property] = function(__property) {
return function() {
this.affected.map(
function(component) {
component[__property].bind(component)();
}
)
}.bind(templateObject);
}(property);
} else {
templateObject.template[property] = componentGroup.components[0][property];
}
}
}
var componentTemplate = componentGroup.components.reduce(
function(result, component) {
if (component === componentGroup.components[0]) {
/**
* This is the first component, just return
*/
return result;
}
/**
* Now start to filter out the properties
*/
for (var property in component) {
if (
component.hasOwnProperty(property)
) {
if (!result.template.hasOwnProperty(property)) {
continue;
}
if (
result.template[property] instanceof GameLib.Vector2 ||
result.template[property] instanceof GameLib.Vector3 ||
result.template[property] instanceof GameLib.Vector4 ||
result.template[property] instanceof GameLib.Quaternion
) {
if (!result.template[property].equals(component[property])) {
delete result.template[property];
}
continue;
}
if (result.template[property] !== component[property]) {
delete result.template[property];
}
}
}
/**
* Store the affected component
*/
result.affected.push(component);
return result;
},
templateObject
);
/**
* componentTemplate now contains for this particular component type group - all
* the properties which are modifiable, and also the objects affected by this property changes
*/
var name;
if (GameLib.Utils.UndefinedOrNull(componentTemplate.template.name)) {
2017-08-23 17:53:06 +02:00
name = GameLib.Component.GetComponentName(componentTemplate.componentType) + ' (All Selected (' + componentTemplate.affected.length + '))';
} else {
name = componentTemplate.template.name;
}
var folder = gui.addFolder(name);
if (!folder) {
2017-08-23 17:53:06 +02:00
return;
}
for (var templateProperty in componentTemplate.template) {
if (
componentTemplate.template.hasOwnProperty(templateProperty) ||
typeof (componentTemplate.template[templateProperty]) === 'function'
) {
if (typeof (componentTemplate.template[templateProperty]) === 'function') {
folder.add(componentTemplate.template, templateProperty);
continue;
}
/**
* We only want to affect runtime vectors because their onchange will execute updateInstance()
*/
if (
componentTemplate.template[templateProperty] instanceof GameLib.Vector2 ||
componentTemplate.template[templateProperty] instanceof GameLib.Vector3 ||
componentTemplate.template[templateProperty] instanceof GameLib.Vector4
) {
this.buildVectorControl(folder, componentTemplate, templateProperty);
continue;
}
if (componentTemplate.template[templateProperty] instanceof GameLib.Quaternion) {
this.buildQuaternionControl(folder, componentTemplate, templateProperty);
2017-08-23 17:53:06 +02:00
}
2017-09-05 13:18:10 +02:00
if (
templateProperty === 'parentEntity' ||
templateProperty === 'parentWorld' ||
templateProperty === 'parentMesh' ||
templateProperty === 'parentScene'
2017-09-05 13:18:10 +02:00
) {
this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
continue;
}
2017-08-23 17:53:06 +02:00
if (componentTemplate.template[templateProperty] instanceof Array) {
if (
templateProperty === 'vertices' ||
templateProperty === 'faces'
) {
continue;
}
if (
componentTemplate.template.linkedObjects &&
componentTemplate.template.linkedObjects[templateProperty] instanceof Array
) {
this.buildArrayManagerControl(folder, componentTemplate, templateProperty);
}
2017-08-23 17:53:06 +02:00
continue;
}
2017-08-24 22:20:40 +02:00
if (componentTemplate.template[templateProperty] instanceof GameLib.Color) {
this.buildColorControl(folder, componentTemplate, templateProperty);
continue;
}
2017-08-23 17:53:06 +02:00
if (typeof componentTemplate.template[templateProperty] === 'object') {
2017-08-24 22:20:40 +02:00
if (
componentTemplate.template[templateProperty] instanceof GameLib.Component ||
(
componentTemplate.template.linkedObjects &&
componentTemplate.template.linkedObjects[templateProperty]
)
) {
2017-08-24 22:20:40 +02:00
this.buildSelectControl(folder, componentTemplate, templateProperty)
} else {
//TODO: maybe start including some other types of objects
//console.log('ignored : ' + templateProperty);
}
2017-08-23 17:53:06 +02:00
continue;
}
this.buildControl(folder, componentTemplate, templateProperty);
// if (
// component.linkedObjects &&
// component.linkedObjects[property]
// ) {
// if (property === 'parentEntity') {
// this.buildEntitySelectionControlFromArray(
// folder,
// component,
// property,
// entityManager
// )
// } else if (component.linkedObjects[property] instanceof Array) {
// this.buildArrayManager(
// folder,
// component,
// property,
// component.linkedObjects[property],
// entityManager
// )
// } else {
// this.buildSelectControl(folder, component, property, entityManager, component.linkedObjects[property]);
// }
//
// } else if (typeof (component[property]) === 'object') {
//
// if (this.isColor(component[property])) {
// this.buildControl(folder, component, property);
// } else {
// //console.log('ignored: ' + property);
// }
// } else {
// this.buildControl(folder, component, property, entityManager);
// }
}
}
2017-08-23 17:53:06 +02:00
}.bind(this)
);
2017-08-23 17:53:06 +02:00
}.bind(this));
2017-06-29 15:23:50 +02:00
};
GameLib.System.GUI.prototype.meshDeleted = function(data) {
2017-06-29 15:23:50 +02:00
2017-08-23 17:53:06 +02:00
data.meshes.map(function(mesh){
this.meshDeslected({
mesh : mesh
})
}.bind(this));
2017-08-23 17:53:06 +02:00
this.buildGUI(null);
};
2017-08-23 17:53:06 +02:00
GameLib.System.GUI.prototype.removeComponent = function(data) {
2017-08-23 17:53:06 +02:00
var index = this.backupComponents.indexOf(data.component);
if (index !== -1) {
this.backupComponents.splice(index, 1);
}
2017-08-23 17:53:06 +02:00
index = this.components.indexOf(data.component);
if (index !== -1) {
this.components.splice(index, 1);
}
};
2017-06-29 15:23:50 +02:00
GameLib.System.GUI.prototype.newEntity = function(data) {
};
GameLib.System.GUI.prototype.stop = function() {
GameLib.System.prototype.stop.call(this);
2017-06-29 15:23:50 +02:00
this.guis.map(function(gui){
2017-06-19 15:54:02 +02:00
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement);
2017-06-29 15:23:50 +02:00
});
delete dat.GUI.removeEmtpyFolders;
delete dat.GUI.removeAllFolders;
2017-06-29 15:23:50 +02:00
this.buildGUISubscription.remove();
this.meshDeletedSubscription.remove();
this.meshSelectedSubscription.remove();
this.meshDeselectedSubscription.remove();
this.newEntitySubscription.remove();
2017-08-23 17:53:06 +02:00
this.componentRemovedSubscription.remove();
2017-06-29 15:23:50 +02:00
this.guis = [];
2017-06-19 15:54:02 +02:00
};