fix: (setInto|removeFrom)(Layer|List|Room)

This commit is contained in:
cha0s 2019-05-27 07:24:42 -05:00
parent fb781dc955
commit e90ce0ecca
4 changed files with 34 additions and 20 deletions

View File

@ -10,15 +10,13 @@ export class Listed extends Trait {
constructor(entity, params, state) {
super(entity, params, state);
this.entity.list = undefined;
this.entity.list = null;
this.quadTreeAabb = [];
this.quadTreeNodes = [];
}
destroy() {
this.removeQuadTreeNodes();
delete this.entity.list;
this.entity.emit('removedFromList');
this.entity.removeFromList();
}
addQuadTreeNodes() {
@ -96,9 +94,13 @@ export class Listed extends Trait {
return {
removeFromList: () => {
const list = this.entity.list;
if (!list) {
return;
}
this.removeQuadTreeNodes();
this.entity.list = undefined;
this.entity.emit('removedFromList');
this.entity.list = null;
this.entity.emit('removedFromList', list);
},
setIntoList: (list) => {

View File

@ -116,11 +116,12 @@ export class Layer extends decorate(class {}) {
}
onEntityAddedToLayer(entity) {
entity.layer = this;
entity.setIntoLayer(this);
this.emit('entityAdded', entity)
}
onEntityRemovedFromLayer(entity) {
entity.removeFromLayer();
this.emit('entityRemoved', entity);
}

View File

@ -8,21 +8,31 @@ export class Layered extends Trait {
constructor(entity, params, state) {
super(entity, params, state);
this._layer = undefined;
this.entity.layer = null;
}
destroy() {
delete this._layer;
this.entity.emit('removedFromLayer');
this.entity.removeFromLayer();
}
get layer() {
return this._layer;
}
methods() {
return {
set layer(layer) {
this._layer = layer;
this.entity.emit('addedToLayer');
removeFromLayer: () => {
const layer = this.entity.layer;
if (!layer) {
return;
}
this.entity.layer = null;
this.entity.emit('removedFromLayer', layer);
},
setIntoLayer: (layer) => {
this.entity.layer = layer;
this.entity.emit('addedToLayer');
},
};
}
}

View File

@ -7,9 +7,7 @@ export class Roomed extends Trait {
}
destroy() {
const room = this.entity.room;
this.entity.room = null;
this.entity.emit('removedFromRoom', room);
this.entity.removeFromRoom();
}
methods() {
@ -17,7 +15,10 @@ export class Roomed extends Trait {
removeFromRoom: () => {
const room = this.entity.room;
this.entity.room = undefined;
if (!room) {
return;
}
this.entity.room = null;
this.entity.emit('removedFromRoom', room);
},