- Position message send will be on format : message : userId : user identification roomId: room identification position: position of user in map x: user x position on map y: user y position on map - Create Point object and interface to have position x and y of user in map.
39 lines
817 B
TypeScript
39 lines
817 B
TypeScript
import {Message} from "./Message";
|
|
import {PointInterface} from "./PointInterface";
|
|
|
|
export class Point implements PointInterface{
|
|
x: number;
|
|
y: number;
|
|
|
|
constructor(x : number, y : number) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
toJson(){
|
|
return {
|
|
x : this.x,
|
|
y: this.y
|
|
}
|
|
}
|
|
}
|
|
|
|
export class MessageUserPosition extends Message{
|
|
position: PointInterface
|
|
|
|
constructor(message: string) {
|
|
super(message);
|
|
let data = JSON.parse(message);
|
|
this.position = new Point(data.position.x, data.position.y);
|
|
}
|
|
|
|
toString() {
|
|
return JSON.stringify(
|
|
Object.assign(
|
|
super.toJson(),
|
|
{
|
|
position: this.position.toJson()
|
|
})
|
|
);
|
|
}
|
|
} |