perf: use clone instead of fromJSON

This commit is contained in:
cha0s 2019-04-25 00:49:22 -05:00
parent 284f67279b
commit 83c33f670e

View File

@ -47,8 +47,9 @@ export class Vulnerable extends Trait {
this._isHydrating = false;
this._isInvulnerable = false;
this.locks = new Map();
this._tookDamageActionsJSON = this.params.get('tookDamageActions').toJS();
this.tookDamageActions = [];
const tookDamageActionsJSON = this.params.get('tookDamageActions').toJS();
this._tookDamageActions = behaviorItemFromJSON(tookDamageActionsJSON);
this.tookDamageActionsList = [];
}
hydrate() {
@ -90,17 +91,14 @@ export class Vulnerable extends Trait {
const context = createContext();
context.add('entity', this.entity);
context.add('damage', damage);
const actions = behaviorItemFromJSON(
this._tookDamageActionsJSON
);
const tuple = {
context,
actions,
};
this.tookDamageActions.push(tuple);
const Actions = this._tookDamageActions.constructor;
const actions = new Actions();
actions.clone(this._tookDamageActions);
const tuple = {context, actions};
this.tookDamageActionsList.push(tuple);
actions.on('actionsFinished', () => {
const index = this.tookDamageActions.indexOf(tuple);
this.tookDamageActions.splice(tuple);
const index = this.tookDamageActionsList.indexOf(tuple);
this.tookDamageActionsList.splice(tuple);
});
}
@ -212,8 +210,8 @@ export class Vulnerable extends Trait {
tick(elapsed) {
if (AVOCADO_CLIENT) {
for (let i = 0; i < this.tookDamageActions.length; ++i) {
const {context, actions} = this.tookDamageActions[i];
for (let i = 0; i < this.tookDamageActionsList.length; ++i) {
const {context, actions} = this.tookDamageActionsList[i];
actions.tick(context, elapsed);
}
}