60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
|
/**
|
||
|
* Statistics
|
||
|
* @param id
|
||
|
* @param name
|
||
|
* @param statisticsType
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.StatisticsRuntime = function(
|
||
|
id,
|
||
|
name,
|
||
|
statisticsType
|
||
|
) {
|
||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||
|
id = GameLib.Utils.RandomId();
|
||
|
}
|
||
|
this.id = id;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||
|
name = 'Statistics (' + id + ')';
|
||
|
}
|
||
|
this.name = name;
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(statisticsType)) {
|
||
|
statisticsType = GameLib.StatisticsRuntime.TYPE_STATS;
|
||
|
}
|
||
|
this.statisticsType = statisticsType;
|
||
|
|
||
|
this.createInstance();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* GameLib.StatisticsRuntime Types
|
||
|
* @type {number}
|
||
|
*/
|
||
|
GameLib.StatisticsRuntime.TYPE_STATS = 0x1;
|
||
|
|
||
|
GameLib.StatisticsRuntime.prototype.createInstance = function() {
|
||
|
if (this.statisticsType === GameLib.StatisticsRuntime.TYPE_STATS) {
|
||
|
this.instance = Stats;
|
||
|
} else {
|
||
|
this.instance = null;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
GameLib.StatisticsRuntime.prototype.updateInstance = function(property) {
|
||
|
if (property === 'statisticsType') {
|
||
|
this.createInstance();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Logs a warning and throws an error if not cannon
|
||
|
*/
|
||
|
GameLib.StatisticsRuntime.prototype.isNotStatsThrow = function() {
|
||
|
if (this.instance !== Stats) {
|
||
|
console.error('Only stats supported');
|
||
|
throw new Error('Only stats supported');
|
||
|
}
|
||
|
};
|