/** * 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 ); this.guis = []; this.buildGUISubscription = null; this.meshDeletedSubscription = null; this.meshSelectedSubscription = null; this.meshDeselectedSubscription = null; this.newEntitySubscription = null; }; GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype); GameLib.System.GUI.prototype.constructor = GameLib.System.GUI; GameLib.System.GUI.prototype.start = function() { this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI); this.guis.map(function(gui){ gui.domElement.instance.parentElement.appendChild(gui.instance.domElement); }); 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 ) }; GameLib.System.GUI.prototype.buildGUI = function(data) { 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){ gui.domElement.instance.parentElement.removeChild(gui.instance.domElement); }); this.buildGUISubscription.remove(); this.meshDeletedSubscription.remove(); this.meshSelectedSubscription.remove(); this.meshDeselectedSubscription.remove(); this.newEntitySubscription.remove(); this.guis = []; };