Removing useless group callbacks at the World level
This commit is contained in:
parent
7410cc8a4b
commit
f6458a8335
@ -149,26 +149,6 @@ export class IoSocketController {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sendUpdateGroupEvent(group: Group): void {
|
|
||||||
// Let's get the room of the group. To do this, let's get anyone in the group and find its room.
|
|
||||||
// Note: this is suboptimal
|
|
||||||
const userId = group.getUsers()[0].id;
|
|
||||||
const client: ExSocketInterface = this.searchClientByIdOrFail(userId);
|
|
||||||
const roomId = client.roomId;
|
|
||||||
this.Io.in(roomId).emit(SockerIoEvent.GROUP_CREATE_UPDATE, {
|
|
||||||
position: group.getPosition(),
|
|
||||||
groupId: group.getId()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private sendDeleteGroupEvent(uuid: string, lastUser: User): void {
|
|
||||||
// Let's get the room of the group. To do this, let's get anyone in the group and find its room.
|
|
||||||
const userId = lastUser.id;
|
|
||||||
const client: ExSocketInterface = this.searchClientByIdOrFail(userId);
|
|
||||||
const roomId = client.roomId;
|
|
||||||
this.Io.in(roomId).emit(SockerIoEvent.GROUP_DELETE, uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
ioConnection() {
|
ioConnection() {
|
||||||
this.Io.on(SockerIoEvent.CONNECTION, (socket: Socket) => {
|
this.Io.on(SockerIoEvent.CONNECTION, (socket: Socket) => {
|
||||||
const client : ExSocketInterface = socket as ExSocketInterface;
|
const client : ExSocketInterface = socket as ExSocketInterface;
|
||||||
@ -498,11 +478,7 @@ export class IoSocketController {
|
|||||||
this.connectedUser(user1, group);
|
this.connectedUser(user1, group);
|
||||||
}, (user1: string, group: Group) => {
|
}, (user1: string, group: Group) => {
|
||||||
this.disConnectedUser(user1, group);
|
this.disConnectedUser(user1, group);
|
||||||
}, MINIMUM_DISTANCE, GROUP_RADIUS, (group: Group) => {
|
}, MINIMUM_DISTANCE, GROUP_RADIUS, (thing: Movable, listener: User) => {
|
||||||
//this.sendUpdateGroupEvent(group);
|
|
||||||
}, (groupUuid: string, lastUser: User) => {
|
|
||||||
//this.sendDeleteGroupEvent(groupUuid, lastUser);
|
|
||||||
}, (thing: Movable, listener: User) => {
|
|
||||||
const clientListener = this.searchClientByIdOrFail(listener.id);
|
const clientListener = this.searchClientByIdOrFail(listener.id);
|
||||||
if (thing instanceof User) {
|
if (thing instanceof User) {
|
||||||
const clientUser = this.searchClientByIdOrFail(thing.id);
|
const clientUser = this.searchClientByIdOrFail(thing.id);
|
||||||
|
@ -14,10 +14,6 @@ import {Movable} from "_Model/Movable";
|
|||||||
export type ConnectCallback = (user: string, group: Group) => void;
|
export type ConnectCallback = (user: string, group: Group) => void;
|
||||||
export type DisconnectCallback = (user: string, group: Group) => void;
|
export type DisconnectCallback = (user: string, group: Group) => void;
|
||||||
|
|
||||||
// callback called when a group is created or moved or changes users
|
|
||||||
export type GroupUpdatedCallback = (group: Group) => void;
|
|
||||||
export type GroupDeletedCallback = (uuid: string, lastUser: User) => void;
|
|
||||||
|
|
||||||
export class World {
|
export class World {
|
||||||
private readonly minDistance: number;
|
private readonly minDistance: number;
|
||||||
private readonly groupRadius: number;
|
private readonly groupRadius: number;
|
||||||
@ -28,8 +24,6 @@ export class World {
|
|||||||
|
|
||||||
private readonly connectCallback: ConnectCallback;
|
private readonly connectCallback: ConnectCallback;
|
||||||
private readonly disconnectCallback: DisconnectCallback;
|
private readonly disconnectCallback: DisconnectCallback;
|
||||||
private readonly groupUpdatedCallback: GroupUpdatedCallback;
|
|
||||||
private readonly groupDeletedCallback: GroupDeletedCallback;
|
|
||||||
|
|
||||||
private itemsState: Map<number, unknown> = new Map<number, unknown>();
|
private itemsState: Map<number, unknown> = new Map<number, unknown>();
|
||||||
|
|
||||||
@ -39,8 +33,6 @@ export class World {
|
|||||||
disconnectCallback: DisconnectCallback,
|
disconnectCallback: DisconnectCallback,
|
||||||
minDistance: number,
|
minDistance: number,
|
||||||
groupRadius: number,
|
groupRadius: number,
|
||||||
groupUpdatedCallback: GroupUpdatedCallback,
|
|
||||||
groupDeletedCallback: GroupDeletedCallback,
|
|
||||||
onEnters: EntersCallback,
|
onEnters: EntersCallback,
|
||||||
onMoves: MovesCallback,
|
onMoves: MovesCallback,
|
||||||
onLeaves: LeavesCallback)
|
onLeaves: LeavesCallback)
|
||||||
@ -51,8 +43,6 @@ export class World {
|
|||||||
this.disconnectCallback = disconnectCallback;
|
this.disconnectCallback = disconnectCallback;
|
||||||
this.minDistance = minDistance;
|
this.minDistance = minDistance;
|
||||||
this.groupRadius = groupRadius;
|
this.groupRadius = groupRadius;
|
||||||
this.groupUpdatedCallback = groupUpdatedCallback;
|
|
||||||
this.groupDeletedCallback = groupDeletedCallback;
|
|
||||||
// A zone is 10 sprites wide.
|
// A zone is 10 sprites wide.
|
||||||
this.positionNotifier = new PositionNotifier(320, 320, onEnters, onMoves, onLeaves);
|
this.positionNotifier = new PositionNotifier(320, 320, onEnters, onMoves, onLeaves);
|
||||||
}
|
}
|
||||||
@ -138,7 +128,6 @@ export class World {
|
|||||||
// At the very end, if the user is part of a group, let's call the callback to update group position
|
// At the very end, if the user is part of a group, let's call the callback to update group position
|
||||||
if (typeof user.group !== 'undefined') {
|
if (typeof user.group !== 'undefined') {
|
||||||
this.positionNotifier.updatePosition(user.group, user.group.getPosition(), oldGroupPosition ? oldGroupPosition : user.group.getPosition());
|
this.positionNotifier.updatePosition(user.group, user.group.getPosition(), oldGroupPosition ? oldGroupPosition : user.group.getPosition());
|
||||||
//this.groupUpdatedCallback(user.group);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +163,6 @@ export class World {
|
|||||||
}
|
}
|
||||||
group.leave(user);
|
group.leave(user);
|
||||||
if (group.isEmpty()) {
|
if (group.isEmpty()) {
|
||||||
//this.groupDeletedCallback(group.getId(), user);
|
|
||||||
this.positionNotifier.leave(group);
|
this.positionNotifier.leave(group);
|
||||||
group.destroy();
|
group.destroy();
|
||||||
if (!this.groups.has(group)) {
|
if (!this.groups.has(group)) {
|
||||||
@ -183,7 +171,6 @@ export class World {
|
|||||||
this.groups.delete(group);
|
this.groups.delete(group);
|
||||||
} else {
|
} else {
|
||||||
this.positionNotifier.updatePosition(group, group.getPosition(), group.getPosition());
|
this.positionNotifier.updatePosition(group, group.getPosition(), group.getPosition());
|
||||||
//this.groupUpdatedCallback(group);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ describe("World", () => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {}, () => {}, () => {});
|
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
||||||
|
|
||||||
world.join({ userId: "foo" }, new Point(100, 100));
|
world.join({ userId: "foo" }, new Point(100, 100));
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ describe("World", () => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {}, () => {}, () => {});
|
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
||||||
|
|
||||||
world.join({ userId: "foo" }, new Point(100, 100));
|
world.join({ userId: "foo" }, new Point(100, 100));
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ describe("World", () => {
|
|||||||
disconnectCallNumber++;
|
disconnectCallNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {}, () => {}, () => {});
|
const world = new World(connect, disconnect, 160, 160, () => {}, () => {}, () => {});
|
||||||
|
|
||||||
world.join({ userId: "foo" }, new Point(100, 100));
|
world.join({ userId: "foo" }, new Point(100, 100));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user