78 lines
1.6 KiB
JavaScript
78 lines
1.6 KiB
JavaScript
|
/**
|
||
|
* 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;
|
||
|
|
||
|
GameLib.Component.call(
|
||
|
this,
|
||
|
GameLib.Component.COMPONENT_STATS,
|
||
|
{
|
||
|
'domElement': GameLib.DomElement
|
||
|
},
|
||
|
null,
|
||
|
parentEntity
|
||
|
);
|
||
|
|
||
|
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;
|
||
|
|
||
|
this.instance = this.createInstance();
|
||
|
};
|
||
|
|
||
|
GameLib.D3.Stats.prototype = Object.create(GameLib.Component.prototype);
|
||
|
GameLib.D3.Stats.prototype.constructor = GameLib.D3.Stats;
|
||
|
|
||
|
/**
|
||
|
* Creates a helper instance
|
||
|
* @param update
|
||
|
*/
|
||
|
GameLib.D3.Stats.prototype.createInstance = function(update) {
|
||
|
|
||
|
var instance = null;
|
||
|
|
||
|
if (update) {
|
||
|
this.instance = new this.stats();
|
||
|
instance = this.instance;
|
||
|
} else {
|
||
|
instance = new this.stats();
|
||
|
}
|
||
|
|
||
|
return instance;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Updates the instance with the current state
|
||
|
*/
|
||
|
GameLib.D3.Stats.prototype.updateInstance = function() {
|
||
|
this.instance = this.createInstance(true);
|
||
|
};
|