From 83c33f670ef300ab1d8517f8f8d4c20f729262d8 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 25 Apr 2019 00:49:22 -0500 Subject: [PATCH] perf: use clone instead of fromJSON --- common/combat/vulnerable.trait.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/common/combat/vulnerable.trait.js b/common/combat/vulnerable.trait.js index 09d17b0..208987a 100644 --- a/common/combat/vulnerable.trait.js +++ b/common/combat/vulnerable.trait.js @@ -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); } }