refactor: informing API

This commit is contained in:
cha0s 2022-05-03 04:44:24 -05:00
parent b7dcb30f22
commit 9de78bb35e
3 changed files with 7 additions and 19 deletions

View File

@ -44,14 +44,7 @@ export default (flecks) => {
this.$$synchronizer.cleanPackets();
},
inform: async (socket) => {
if (socket) {
const packets = this.$$synchronizer.packetsFor(this.entity);
if (packets.length > 0) {
await socket.send(['Bundle', packets]);
}
}
},
informedPackets: () => this.$$synchronizer.packetsFor(this.entity),
startInformingAbout: (synchronized) => {
this.$$synchronizer.startSynchronizing(synchronized);

View File

@ -102,13 +102,16 @@ export default class Universe {
async inform() {
for (let i = 0; i < this.$$players.length; ++i) {
this.$$players[i].inform();
const packets = this.$$players[i].entity.informedPackets();
if (packets.length > 0) {
this.$$players[i].socket.send(['Bundle', packets]);
}
}
for (let i = 0; i < this.$$roomsFlat.length; i++) {
this.$$roomsFlat[i].cleanPackets();
}
for (let i = 0; i < this.$$players.length; ++i) {
this.$$players[i].cleanInformingPackets();
this.$$players[i].entity.cleanInformingPackets();
}
}
@ -166,7 +169,7 @@ export default class Universe {
removePlayer(player) {
const {entity} = player;
const room = this.room(entity.currentRoom);
entity.stopInforming(room);
entity.stopInformingAbout(room);
room.removeEntity(entity);
const index = this.$$players.indexOf(player);
if (-1 !== index) {

View File

@ -20,12 +20,4 @@ export default class Player extends decorate(Class) {
socket.once('disconnect', emitRemove);
}
cleanInformingPackets() {
this.entity.cleanInformingPackets();
}
inform() {
this.entity.inform(this.socket);
}
}