/** * Stats component for displaying some render statistics (framerate, memory consumption, etc) * @param statisticsRuntime * @param apiStats * @constructor */ GameLib.Stats = function( statisticsRuntime, apiStats ) { this.stats = statisticsRuntime; this.stats.isNotStatsThrow(); if (GameLib.Utils.UndefinedOrNull(apiStats)) { apiStats = {}; } GameLib.API.Stats.call( this, apiStats.id, apiStats.name, apiStats.domElement, apiStats.parentEntity ); GameLib.Component.call( this, { 'domElement': GameLib.DomElement } ); }; GameLib.Stats.prototype = Object.create(GameLib.Component.prototype); GameLib.Stats.prototype.constructor = GameLib.Stats; /** * Creates a helper instance */ GameLib.Stats.prototype.createInstance = function() { this.instance = this.stats.instance(); this.resize(); this.domElement.instance.parentElement.appendChild(this.instance.dom); GameLib.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ GameLib.Stats.prototype.updateInstance = function() { this.instance = new this.stats(); }; /** * Converts a GameLib.Stats to a new GameLib.API.Stats * @returns {GameLib.API.Stats} */ GameLib.Stats.prototype.toApiObject = function() { return new GameLib.API.Stats( this.id, this.name, GameLib.Utils.IdOrNull(this.domElement), GameLib.Utils.IdOrNull(this.parentEntity) ); }; /** * Converts from an Object Stats to a GameLib.Stats * @param statisticsRuntime GameLib.StatisticsRuntime * @param objectStats Object * @returns {GameLib.Stats} * @constructor */ GameLib.Stats.FromObject = function(statisticsRuntime, objectStats) { var apiStats = GameLib.API.Stats.FromObject(objectStats); return new GameLib.Stats( statisticsRuntime, apiStats ); }; GameLib.Stats.prototype.resize = function() { console.log('override stats resize per implementation'); }; GameLib.Stats.prototype.start = function() { this.instance.begin(); }; GameLib.Stats.prototype.end = function() { this.instance.end(); };