/** * Stats component for displaying some render statistics (framerate, memory consumption, etc) * @param gui * @param id * @param name * @param domElement * @param parentEntity * @constructor */ GameLib.GUI = function( gui, id, name, domElement, parentEntity ) { if (GameLib.Utils.UndefinedOrNull(gui)) { throw new Error('Need Stats object') } this.gui = gui; GameLib.Component.call( this, GameLib.Component.COMPONENT_GUI, { 'domElement': GameLib.DomElement }, null, parentEntity ); if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'GUI (' + id + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(domElement)) { console.warn('Need a DOM element for stats'); throw new Error('Need a DOM element for stats'); } this.domElement = domElement; this.instance = this.createInstance(); }; GameLib.GUI.prototype = Object.create(GameLib.Component.prototype); GameLib.GUI.prototype.constructor = GameLib.GUI; /** * Creates a helper instance * @param update */ GameLib.GUI.prototype.createInstance = function(update) { var instance = null; if (update) { this.instance = new this.gui( { autoPlace: false } ); instance = this.instance; } else { instance = new this.gui( { autoPlace: false } ); } return instance; }; /** * Updates the instance with the current state */ GameLib.GUI.prototype.updateInstance = function() { this.instance = this.createInstance(true); };