fix: add/remove from list and room

This commit is contained in:
cha0s 2019-05-26 12:03:24 -05:00
parent 24f944d762
commit 0f61faabb4
5 changed files with 22 additions and 2 deletions

View File

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

View File

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

View File

@ -108,6 +108,12 @@ export class Physical extends decorate(Trait) {
}
},
removedFromRoom: (room) => {
if (this._body) {
this.removeFromWorld();
}
},
};
}

View File

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

View File

@ -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');
},