From 2952e4edf429dd6e99105f714b5bc51f916cfa81 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 19 Mar 2019 11:25:42 -0500 Subject: [PATCH] refactor: always use Trait::initialize --- packages/entity/traits/animated.js | 5 ++--- packages/entity/traits/directional.js | 3 +-- packages/entity/traits/existent.js | 9 ++++----- packages/entity/traits/graphical.js | 12 +++++------- packages/entity/traits/mobile.js | 3 +-- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/packages/entity/traits/animated.js b/packages/entity/traits/animated.js index c5349e5..3330adc 100644 --- a/packages/entity/traits/animated.js +++ b/packages/entity/traits/animated.js @@ -27,8 +27,7 @@ class AnimatedBase extends Trait { }; } - constructor(entity, params, state) { - super(...arguments); + initialize() { this.sprite = undefined; this.frameCount = this.params.get('frameCount'); this.frameRate = this.params.get('frameRate'); @@ -49,7 +48,7 @@ class AnimatedBase extends Trait { } loadSpriteImageIfPossible() { - if (!('container' in this.entity)) { + if (!this.entity.container) { return; } if (!this.image) { diff --git a/packages/entity/traits/directional.js b/packages/entity/traits/directional.js index a45aad2..894e0fc 100644 --- a/packages/entity/traits/directional.js +++ b/packages/entity/traits/directional.js @@ -24,8 +24,7 @@ class DirectionalBase extends Trait { }; } - constructor(entity, params, state) { - super(...arguments); + initialize() { this.directionCount = this.params.get('directionCount'); } diff --git a/packages/entity/traits/existent.js b/packages/entity/traits/existent.js index d5ce9b8..f6412cb 100644 --- a/packages/entity/traits/existent.js +++ b/packages/entity/traits/existent.js @@ -8,11 +8,6 @@ const decorate = compose( class ExistentBase extends Trait { - constructor(...args) { - super(...args); - this._isTicking = this.params.get('isTicking'); - } - static defaultParams() { return { isTicking: true, @@ -25,6 +20,10 @@ class ExistentBase extends Trait { }; } + initialize() { + this._isTicking = this.params.get('isTicking'); + } + get isTicking() { return this._isTicking; } diff --git a/packages/entity/traits/graphical.js b/packages/entity/traits/graphical.js index e725328..2966151 100644 --- a/packages/entity/traits/graphical.js +++ b/packages/entity/traits/graphical.js @@ -14,15 +14,11 @@ class GraphicalBase extends Trait { }; } - constructor(...args) { - super(...args); + initialize() { if (hasGraphics) { this._container = new Container(); } this.trackPosition = this.params.get('trackPosition'); - } - - initialize() { if (this.shouldSynchronizePosition()) { this.synchronizePosition(); } @@ -33,11 +29,13 @@ class GraphicalBase extends Trait { } shouldSynchronizePosition() { - return hasGraphics && this.trackPosition && 'position' in this.entity; + return hasGraphics && this.trackPosition; } synchronizePosition() { - this.entity.container.position = this.entity.position; + if ('position' in this.entity) { + this.entity.container.position = this.entity.position; + } } listeners() { diff --git a/packages/entity/traits/mobile.js b/packages/entity/traits/mobile.js index 3eb397c..5d54223 100644 --- a/packages/entity/traits/mobile.js +++ b/packages/entity/traits/mobile.js @@ -17,8 +17,7 @@ class MobileBase extends Trait { }; } - constructor(...args) { - super(...args); + initialize() { this.requestedMovement = [0, 0]; }