BIG WIP of refactoring my work in TS
This commit is contained in:
parent
af5d2a5a97
commit
fbfc208129
12 changed files with 274 additions and 11 deletions
18
back/src/Model/Websocket/Group.ts
Normal file
18
back/src/Model/Websocket/Group.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import {MessageUserPosition} from "./MessageUserPosition";
|
||||
export class Group {
|
||||
static readonly MAX_PER_GROUP = 4;
|
||||
|
||||
users: MessageUserPosition[];
|
||||
|
||||
constructor(users: MessageUserPosition[]) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
getUsers(): MessageUserPosition[] {
|
||||
return this.users;
|
||||
}
|
||||
|
||||
isFull(): boolean {
|
||||
return this.users.length >= Group.MAX_PER_GROUP;
|
||||
}
|
||||
}
|
|
@ -2,8 +2,7 @@ export class Message {
|
|||
userId: string;
|
||||
roomId: string;
|
||||
|
||||
constructor(message: string) {
|
||||
let data = JSON.parse(message);
|
||||
constructor(data: any) {
|
||||
if(!data.userId || !data.roomId){
|
||||
throw Error("userId or roomId cannot be null");
|
||||
}
|
||||
|
|
|
@ -24,9 +24,8 @@ export class Point implements PointInterface{
|
|||
export class MessageUserPosition extends Message{
|
||||
position: PointInterface;
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
let data = JSON.parse(message);
|
||||
constructor(data: any) {
|
||||
super(data);
|
||||
this.position = new Point(data.position.x, data.position.y);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue