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 = [];
|
|
|
|
|
|
|
|
this.buildGUISubscription = null;
|
|
|
|
|
|
|
|
this.meshDeletedSubscription = null;
|
|
|
|
|
|
|
|
this.meshSelectedSubscription = null;
|
|
|
|
|
|
|
|
this.meshDeselectedSubscription = null;
|
|
|
|
|
|
|
|
this.newEntitySubscription = null;
|
|
|
|
|
2017-06-30 12:06:55 +02:00
|
|
|
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() {
|
|
|
|
|
2017-06-29 15:23:50 +02:00
|
|
|
this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
|
2017-06-19 15:54:02 +02:00
|
|
|
|
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(
|
|
|
|
GameLib.Event.MESH_DELETED,
|
|
|
|
this.meshDeleted
|
|
|
|
);
|
|
|
|
|
|
|
|
this.meshSelectedSubscription = this.subscribe(
|
|
|
|
GameLib.Event.MESH_SELECTED,
|
|
|
|
this.meshSelected
|
|
|
|
);
|
|
|
|
|
|
|
|
this.meshDeselectedSubscription = this.subscribe(
|
|
|
|
GameLib.Event.MESH_DESELECTED,
|
|
|
|
this.meshDeslected
|
|
|
|
);
|
|
|
|
|
|
|
|
this.newEntitySubscription = this.subscribe(
|
|
|
|
GameLib.Event.NEW_ENTITY,
|
|
|
|
this.newEntity
|
|
|
|
)
|
2017-06-19 15:54:02 +02:00
|
|
|
};
|
|
|
|
|
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){
|
|
|
|
gui.objects = [];
|
|
|
|
|
|
|
|
if (
|
|
|
|
data.components &&
|
|
|
|
data.components.length > 0
|
|
|
|
) {
|
|
|
|
gui.objects = data.components;
|
|
|
|
}
|
|
|
|
|
|
|
|
gui.build(GameLib.EntityManager.Instance);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.System.GUI.prototype.meshDeleted = function(data) {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.System.GUI.prototype.meshSelected = function(data) {
|
|
|
|
|
2017-06-30 12:06:55 +02:00
|
|
|
var mesh = data.mesh;
|
|
|
|
|
|
|
|
var objectsToAdd = [];
|
|
|
|
|
|
|
|
this.guis.map(
|
|
|
|
function(gui) {
|
|
|
|
if (mesh.parentEntity) {
|
|
|
|
GameLib.Utils.PushUnique(objectsToAdd, mesh.parentEntity);
|
|
|
|
}
|
|
|
|
objectsToAdd.push(mesh);
|
|
|
|
mesh.materials.map(
|
|
|
|
function(material){
|
|
|
|
GameLib.Utils.PushUnique(objectsToAdd, material);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
mesh.materials.map(
|
|
|
|
function(material){
|
|
|
|
for (var property in material.linkedObjects) {
|
|
|
|
if (
|
|
|
|
material.linkedObjects.hasOwnProperty(property) &&
|
|
|
|
material.hasOwnProperty(property) &&
|
|
|
|
material[property] &&
|
|
|
|
property !== 'parentEntity'
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GameLib.Utils.PushUnique(objectsToAdd, material[property]);
|
|
|
|
for (var tProperty in material[property].linkedObjects) {
|
|
|
|
if (
|
|
|
|
material[property].linkedObjects.hasOwnProperty(tProperty) &&
|
|
|
|
material[property].hasOwnProperty(tProperty) &&
|
|
|
|
material[property][tProperty] &&
|
|
|
|
tProperty !== 'parentEntity'
|
|
|
|
) {
|
|
|
|
GameLib.Utils.PushUnique(objectsToAdd, material[property][tProperty]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.guis.map(function(gui){
|
|
|
|
objectsToAdd.map(function(object){
|
|
|
|
gui.addObject(object);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
gui.build(GameLib.EntityManager.Instance);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.meshSelectionObjects[mesh.id] = objectsToAdd;
|
2017-06-29 15:23:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.System.GUI.prototype.meshDeslected = function(data) {
|
|
|
|
|
2017-06-30 12:06:55 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.meshSelectionObjects[data.mesh.id])) {
|
|
|
|
console.warn('selected mesh data not available');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.guis.map(
|
|
|
|
function(gui) {
|
|
|
|
this.meshSelectionObjects[data.mesh.id].map(function(object){
|
|
|
|
gui.removeObject(object);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
gui.build(GameLib.EntityManager.Instance);
|
|
|
|
}.bind(this)
|
|
|
|
)
|
|
|
|
|
2017-06-29 15:23:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.System.GUI.prototype.newEntity = function(data) {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.System.GUI.prototype.stop = function() {
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
this.buildGUISubscription.remove();
|
|
|
|
|
|
|
|
this.meshDeletedSubscription.remove();
|
|
|
|
|
|
|
|
this.meshSelectedSubscription.remove();
|
|
|
|
|
|
|
|
this.meshDeselectedSubscription.remove();
|
|
|
|
|
|
|
|
this.newEntitySubscription.remove();
|
|
|
|
|
|
|
|
this.guis = [];
|
2017-06-19 15:54:02 +02:00
|
|
|
};
|
|
|
|
|