Cleanup; pretty
This commit is contained in:
parent
c96b65549f
commit
5c385c520a
5 changed files with 20 additions and 18 deletions
|
@ -224,19 +224,18 @@ export class GameRoom {
|
|||
} else {
|
||||
// If the user is part of a group:
|
||||
// should he leave the group?
|
||||
const leaveIfOutOfRadius = (user: User) => {
|
||||
if (user.group === undefined) {
|
||||
const users = user.group.getUsers().filter((u) => !u.hasFollowers() && !u.following);
|
||||
users.forEach((foreignUser: User) => {
|
||||
if (foreignUser.group === undefined) {
|
||||
return;
|
||||
}
|
||||
const usrPos = user.getPosition();
|
||||
const grpPos = user.group.getPosition();
|
||||
const usrPos = foreignUser.getPosition();
|
||||
const grpPos = foreignUser.group.getPosition();
|
||||
const distance = GameRoom.computeDistanceBetweenPositions(usrPos, grpPos);
|
||||
if (distance > this.groupRadius) {
|
||||
this.leaveGroup(user);
|
||||
this.leaveGroup(foreignUser);
|
||||
}
|
||||
};
|
||||
const users = user.group.getUsers().filter((u) => !u.hasFollowers() && !u.following);
|
||||
users.forEach((foreignUser) => leaveIfOutOfRadius(foreignUser));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ export class Group implements Movable {
|
|||
/**
|
||||
* A group can have at most one person leading the way in it.
|
||||
*/
|
||||
get leader(): User|undefined {
|
||||
get leader(): User | undefined {
|
||||
for (const user of this.users) {
|
||||
if (user.hasFollowers()) {
|
||||
return user;
|
||||
|
|
|
@ -6,7 +6,9 @@ import { PositionNotifier } from "_Model/PositionNotifier";
|
|||
import { ServerDuplexStream } from "grpc";
|
||||
import {
|
||||
BatchMessage,
|
||||
CompanionMessage, FollowAbortMessage, FollowConfirmationMessage,
|
||||
CompanionMessage,
|
||||
FollowAbortMessage,
|
||||
FollowConfirmationMessage,
|
||||
PusherToBackMessage,
|
||||
ServerToClientMessage,
|
||||
SubMessage,
|
||||
|
@ -18,7 +20,7 @@ export type UserSocket = ServerDuplexStream<PusherToBackMessage, ServerToClientM
|
|||
export class User implements Movable {
|
||||
public listenedZones: Set<Zone>;
|
||||
public group?: Group;
|
||||
private _following: User|undefined;
|
||||
private _following: User | undefined;
|
||||
private followedBy: Set<User> = new Set<User>();
|
||||
|
||||
public constructor(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue