From 3320999693316eef56a4496e07acda378dd19130 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 3 Jan 2021 21:42:48 -0600 Subject: [PATCH] refactor: proper private variables --- packages/entity/src/traits/alive.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/entity/src/traits/alive.js b/packages/entity/src/traits/alive.js index c10217a..560f711 100644 --- a/packages/entity/src/traits/alive.js +++ b/packages/entity/src/traits/alive.js @@ -27,16 +27,22 @@ const decorate = compose( export default (latus) => class Alive extends decorate(Trait) { + #context; + + #deathActions; + + #deathCondition; + constructor(...args) { super(...args); - this._context = new Context( + this.#context = new Context( { entity: [this.entity, 'entity'], }, latus, ); - this._deathActions = new Actions(compile(this.params.deathActions, latus)); - this._deathCondition = compile(this.params.deathCondition, latus); + this.#deathActions = new Actions(compile(this.params.deathActions, latus)); + this.#deathCondition = compile(this.params.deathCondition, latus); } acceptPacket(packet) { @@ -141,7 +147,7 @@ export default (latus) => class Alive extends decorate(Trait) { } destroy() { - this._context.destroy(); + this.#context.destroy(); } get life() { @@ -180,7 +186,7 @@ export default (latus) => class Alive extends decorate(Trait) { return; } this.entity.isDying = true; - await this.entity.addTickingPromise(this._deathActions.tickingPromise(this._context)); + await this.entity.addTickingPromise(this.#deathActions.tickingPromise(this.#context)); await Promise.all(this.entity.invokeHookFlat('died')); this.entity.destroy(); }, @@ -208,7 +214,7 @@ export default (latus) => class Alive extends decorate(Trait) { tick() { if ('client' !== SIDE) { - if (!this.entity.isDying && this._deathCondition(this._context)) { + if (!this.entity.isDying && this.#deathCondition(this.#context)) { this.entity.forceDeath(); } }