/** * Stats component for displaying some render statistics (framerate, memory consumption, etc) * @param stats * @param id * @param name * @param domElement * @param parentEntity * @constructor */ GameLib.D3.Stats = function( stats, id, name, domElement, parentEntity ) { if (GameLib.Utils.UndefinedOrNull(stats)) { throw new Error('Need Stats object') } this.stats = stats; if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Stats (' + 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; if (GameLib.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } this.parentEntity = parentEntity; GameLib.Component.call( this, GameLib.Component.COMPONENT_STATS, { 'domElement': GameLib.DomElement } ); }; GameLib.D3.Stats.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.Stats.prototype.constructor = GameLib.D3.Stats; GameLib.D3.Stats.prototype.resize = function() { console.log('override stats resize per implementation'); }; /** * Creates a helper instance */ GameLib.D3.Stats.prototype.createInstance = function() { this.instance = this.stats(); this.resize(); this.domElement.instance.parentElement.appendChild(this.instance.dom); GameLib.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ GameLib.D3.Stats.prototype.updateInstance = function() { this.instance = new this.stats(); }; GameLib.D3.Stats.prototype.start = function() { this.instance.begin(); }; GameLib.D3.Stats.prototype.end = function() { this.instance.end(); };