refactor: always use Trait::initialize

This commit is contained in:
cha0s 2019-03-19 11:25:42 -05:00
parent 3b50c134d0
commit 2952e4edf4
5 changed files with 13 additions and 19 deletions

View File

@ -27,8 +27,7 @@ class AnimatedBase extends Trait {
}; };
} }
constructor(entity, params, state) { initialize() {
super(...arguments);
this.sprite = undefined; this.sprite = undefined;
this.frameCount = this.params.get('frameCount'); this.frameCount = this.params.get('frameCount');
this.frameRate = this.params.get('frameRate'); this.frameRate = this.params.get('frameRate');
@ -49,7 +48,7 @@ class AnimatedBase extends Trait {
} }
loadSpriteImageIfPossible() { loadSpriteImageIfPossible() {
if (!('container' in this.entity)) { if (!this.entity.container) {
return; return;
} }
if (!this.image) { if (!this.image) {

View File

@ -24,8 +24,7 @@ class DirectionalBase extends Trait {
}; };
} }
constructor(entity, params, state) { initialize() {
super(...arguments);
this.directionCount = this.params.get('directionCount'); this.directionCount = this.params.get('directionCount');
} }

View File

@ -8,11 +8,6 @@ const decorate = compose(
class ExistentBase extends Trait { class ExistentBase extends Trait {
constructor(...args) {
super(...args);
this._isTicking = this.params.get('isTicking');
}
static defaultParams() { static defaultParams() {
return { return {
isTicking: true, isTicking: true,
@ -25,6 +20,10 @@ class ExistentBase extends Trait {
}; };
} }
initialize() {
this._isTicking = this.params.get('isTicking');
}
get isTicking() { get isTicking() {
return this._isTicking; return this._isTicking;
} }

View File

@ -14,15 +14,11 @@ class GraphicalBase extends Trait {
}; };
} }
constructor(...args) { initialize() {
super(...args);
if (hasGraphics) { if (hasGraphics) {
this._container = new Container(); this._container = new Container();
} }
this.trackPosition = this.params.get('trackPosition'); this.trackPosition = this.params.get('trackPosition');
}
initialize() {
if (this.shouldSynchronizePosition()) { if (this.shouldSynchronizePosition()) {
this.synchronizePosition(); this.synchronizePosition();
} }
@ -33,11 +29,13 @@ class GraphicalBase extends Trait {
} }
shouldSynchronizePosition() { shouldSynchronizePosition() {
return hasGraphics && this.trackPosition && 'position' in this.entity; return hasGraphics && this.trackPosition;
} }
synchronizePosition() { synchronizePosition() {
this.entity.container.position = this.entity.position; if ('position' in this.entity) {
this.entity.container.position = this.entity.position;
}
} }
listeners() { listeners() {

View File

@ -17,8 +17,7 @@ class MobileBase extends Trait {
}; };
} }
constructor(...args) { initialize() {
super(...args);
this.requestedMovement = [0, 0]; this.requestedMovement = [0, 0];
} }