fix: add/remove from list and room
This commit is contained in:
parent
24f944d762
commit
0f61faabb4
|
@ -127,6 +127,7 @@ export class EntityList extends decorate(class {}) {
|
|||
if (AVOCADO_SERVER) {
|
||||
this._entitiesJustRemoved.push(entity);
|
||||
}
|
||||
entity.removeFromList();
|
||||
delete this._entities[uuid];
|
||||
this._flatEntities.splice(this._flatEntities.indexOf(entity), 1);
|
||||
this._entityTickers.splice(this._entityTickers.indexOf(entity.tick), 1);
|
||||
|
|
|
@ -95,6 +95,12 @@ export class Listed extends Trait {
|
|||
methods() {
|
||||
return {
|
||||
|
||||
removeFromList: () => {
|
||||
this.removeQuadTreeNodes();
|
||||
this.entity.list = undefined;
|
||||
this.entity.emit('removedFromList');
|
||||
},
|
||||
|
||||
setIntoList: (list) => {
|
||||
this.entity.list = list;
|
||||
this.addQuadTreeNodes();
|
||||
|
|
|
@ -108,6 +108,12 @@ export class Physical extends decorate(Trait) {
|
|||
}
|
||||
},
|
||||
|
||||
removedFromRoom: (room) => {
|
||||
if (this._body) {
|
||||
this.removeFromWorld();
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ export class Room extends decorate(Resource) {
|
|||
}
|
||||
|
||||
onEntityAddedToRoom(entity) {
|
||||
entity.setRoom(this);
|
||||
entity.setIntoRoom(this);
|
||||
if (AVOCADO_CLIENT) {
|
||||
const queuedPackets = this.queuedEntityPackets[entity.instanceUuid];
|
||||
for (let i = 0; i < queuedPackets.length; i++) {
|
||||
|
@ -129,6 +129,7 @@ export class Room extends decorate(Resource) {
|
|||
}
|
||||
|
||||
onEntityRemovedFromRoom(entity) {
|
||||
entity.removeFromRoom();
|
||||
this.emit('entityRemoved', entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,13 @@ export class Roomed extends Trait {
|
|||
methods() {
|
||||
return {
|
||||
|
||||
setRoom: (room) => {
|
||||
removeFromRoom: () => {
|
||||
const room = this.entity.room;
|
||||
this.entity.room = undefined;
|
||||
this.entity.emit('removedFromRoom', room);
|
||||
},
|
||||
|
||||
setIntoRoom: (room) => {
|
||||
this.entity.room = room;
|
||||
this.entity.emit('addedToRoom');
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user