r3-legacy/src/game-lib-d3-stats.js

86 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-05-16 11:50:06 +02:00
/**
* 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;
2017-06-16 15:49:53 +02:00
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_STATS,
{
'domElement': GameLib.DomElement
}
);
2017-05-16 11:50:06 +02:00
};
GameLib.D3.Stats.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Stats.prototype.constructor = GameLib.D3.Stats;
2017-05-22 11:34:18 +02:00
GameLib.D3.Stats.prototype.resize = function() {
console.log('override stats resize per implementation');
};
2017-05-16 11:50:06 +02:00
/**
* Creates a helper instance
*/
2017-06-28 17:09:06 +02:00
GameLib.D3.Stats.prototype.createInstance = function() {
2017-10-23 14:52:35 +02:00
this.instance = this.stats();
2017-10-29 16:28:13 +01:00
this.resize();
this.domElement.instance.parentElement.appendChild(this.instance.dom);
2017-10-23 14:52:35 +02:00
GameLib.Component.prototype.createInstance.call(this);
2017-05-16 11:50:06 +02:00
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Stats.prototype.updateInstance = function() {
2017-06-28 17:09:06 +02:00
this.instance = new this.stats();
2017-05-16 11:50:06 +02:00
};
2017-08-24 22:20:40 +02:00
GameLib.D3.Stats.prototype.start = function() {
this.instance.begin();
};
GameLib.D3.Stats.prototype.end = function() {
this.instance.end();
};