werewolf-core
Version:
Are you a WEREWOLF?
51 lines (50 loc) • 1.46 kB
JavaScript
;
var extend = require('extend');
var Effects = (function () {
function Effects() {
this.effects = [];
this.length = 0;
}
Effects.prototype.add = function (e) {
this.effects.push(e);
this.length = this.effects.length;
};
Effects.prototype.removeById = function (id) {
this.effects = this.effects.filter(function (e) { return id !== e.id; });
this.length = this.effects.length;
};
Effects.prototype.get = function (idx) {
if ('number' === typeof idx) {
return this.effects[idx];
}
else {
var l = this.effects.length;
for (var i = 0; i < l; i++) {
var e = this.effects[i];
if (e.id === idx) {
return e;
}
}
return undefined;
}
};
Effects.prototype.ofType = function (t) {
return this.effects.filter(function (_a) {
var type = _a.type;
return t === type;
});
};
Effects.prototype.asArray = function () {
return this.effects.concat([]);
};
Effects.prototype.deepClone = function () {
var ret = new Effects();
for (var _i = 0, _a = this.effects; _i < _a.length; _i++) {
var e = _a[_i];
ret.add(extend(true, {}, e));
}
return ret;
};
return Effects;
}());
exports.Effects = Effects;