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) {
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) {

View File

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

View File

@ -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;
}

View File

@ -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() {

View File

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