refactor: more sensible traitAdded interface
This commit is contained in:
parent
01b5598379
commit
880f428f3a
|
@ -125,7 +125,7 @@ export class Traits {
|
|||
this._setInstanceState(type, instance);
|
||||
// Track trait.
|
||||
this.traits_PRIVATE[type] = instance;
|
||||
this.entity_PRIVATE.emit('traitAdded', instance);
|
||||
this.entity_PRIVATE.emit('traitAdded', type, instance);
|
||||
}
|
||||
|
||||
addTraits(traits) {
|
||||
|
|
|
@ -177,11 +177,11 @@ class AnimatedBase extends Trait {
|
|||
}
|
||||
animation.tick(elapsed);
|
||||
},
|
||||
traitAdded: (trait) => {
|
||||
traitAdded: (type) => {
|
||||
if (-1 === [
|
||||
'animated',
|
||||
'graphical',
|
||||
].indexOf(trait.constructor.type())) {
|
||||
].indexOf(type)) {
|
||||
return;
|
||||
}
|
||||
this.loadAnimations();
|
||||
|
|
|
@ -19,9 +19,6 @@ class GraphicalBase extends Trait {
|
|||
this._container = new Container();
|
||||
}
|
||||
this.trackPosition = this.params.get('trackPosition');
|
||||
if (this.shouldSynchronizePosition()) {
|
||||
this.synchronizePosition();
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
@ -49,8 +46,11 @@ class GraphicalBase extends Trait {
|
|||
listeners() {
|
||||
const listeners = {};
|
||||
if (this.shouldSynchronizePosition()) {
|
||||
listeners.traitAdded = (trait) => {
|
||||
if ('positioned' !== trait.constructor.type()) {
|
||||
listeners.traitAdded = (type) => {
|
||||
if (-1 === [
|
||||
'graphical',
|
||||
'positioned',
|
||||
].indexOf(type)) {
|
||||
return;
|
||||
}
|
||||
this.synchronizePosition();
|
||||
|
|
|
@ -100,11 +100,11 @@ class PicturedBase extends Trait {
|
|||
this.hideImage(oldKey);
|
||||
this.showImage(this.entity.currentImage);
|
||||
},
|
||||
traitAdded: (trait) => {
|
||||
traitAdded: (type) => {
|
||||
if (-1 === [
|
||||
'graphical',
|
||||
'pictured',
|
||||
].indexOf(trait.constructor.type())) {
|
||||
].indexOf(type)) {
|
||||
return;
|
||||
}
|
||||
this.loadImagesIfPossible();
|
||||
|
|
Loading…
Reference in New Issue
Block a user