cr fixes #1 wip

This commit is contained in:
Hanusiak Piotr
2022-03-09 16:51:11 +01:00
parent 3c74b2b554
commit 3a5aa3c3c5
4 changed files with 25 additions and 13 deletions
+9 -5
View File
@@ -46,7 +46,7 @@ export class GameRoom {
// Users, sorted by ID
private readonly users = new Map<number, User>();
private readonly usersByUuid = new Map<string, User>();
private readonly groups = new Set<Group>();
private readonly groups: Map<number, Group> = new Map<number, Group>();
private readonly admins = new Set<Admin>();
private itemsState = new Map<number, unknown>();
@@ -250,7 +250,7 @@ export class GameRoom {
this.disconnectCallback,
this.positionNotifier
);
this.groups.add(group);
this.groups.set(group.getId(), group);
}
}
} else {
@@ -334,7 +334,7 @@ export class GameRoom {
this.disconnectCallback,
this.positionNotifier
);
this.groups.add(newGroup);
this.groups.set(newGroup.getId(), newGroup);
} else {
this.leaveGroup(user);
}
@@ -381,10 +381,10 @@ export class GameRoom {
group.leave(user);
if (group.isEmpty()) {
group.destroy();
if (!this.groups.has(group)) {
if (!this.groups.has(group.getId())) {
throw new Error(`Could not find group ${group.getId()} referenced by user ${user.id} in World.`);
}
this.groups.delete(group);
this.groups.delete(group.getId());
//todo: is the group garbage collected?
} else {
group.updatePosition();
@@ -664,4 +664,8 @@ export class GameRoom {
const variablesManager = await this.getVariableManager();
return variablesManager.getVariablesForTags(tags);
}
public getGroupById(id: number): Group | undefined {
return this.groups.get(id);
}
}