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