fix: (setInto|removeFrom)(Layer|List|Room)
This commit is contained in:
parent
fb781dc955
commit
e90ce0ecca
|
@ -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) => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
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');
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user