2020-04-04 12:42:02 +02:00
|
|
|
import {Message} from "./Message";
|
2020-04-04 16:25:03 +02:00
|
|
|
import {PointInterface} from "./PointInterface";
|
|
|
|
|
|
|
|
export class Point implements PointInterface{
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
|
|
|
|
constructor(x : number, y : number) {
|
2020-04-04 17:22:02 +02:00
|
|
|
if(!x || !y){
|
2020-04-04 17:56:43 +02:00
|
|
|
throw Error("position x and y cannot be null");
|
2020-04-04 17:22:02 +02:00
|
|
|
}
|
2020-04-04 16:25:03 +02:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
toJson(){
|
|
|
|
return {
|
|
|
|
x : this.x,
|
|
|
|
y: this.y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-04 12:42:02 +02:00
|
|
|
|
|
|
|
export class MessageUserPosition extends Message{
|
2020-04-04 16:25:03 +02:00
|
|
|
position: PointInterface
|
2020-04-04 12:42:02 +02:00
|
|
|
|
|
|
|
constructor(message: string) {
|
|
|
|
super(message);
|
|
|
|
let data = JSON.parse(message);
|
2020-04-04 16:25:03 +02:00
|
|
|
this.position = new Point(data.position.x, data.position.y);
|
2020-04-04 12:42:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
toString() {
|
|
|
|
return JSON.stringify(
|
|
|
|
Object.assign(
|
|
|
|
super.toJson(),
|
|
|
|
{
|
2020-04-04 16:25:03 +02:00
|
|
|
position: this.position.toJson()
|
2020-04-04 12:42:02 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|