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

119 lines
2.4 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 = [];
this.buildGUISubscription = null;
this.meshDeletedSubscription = null;
this.meshSelectedSubscription = null;
this.meshDeselectedSubscription = null;
this.newEntitySubscription = null;
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) {
};
GameLib.System.GUI.prototype.meshDeslected = function(data) {
};
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
};