Fix Message send to add direction
This commit is contained in:
parent
aba3322188
commit
67c3eaa7f4
4 changed files with 25 additions and 11 deletions
|
@ -4,19 +4,22 @@ import {PointInterface} from "./PointInterface";
|
|||
export class Point implements PointInterface{
|
||||
x: number;
|
||||
y: number;
|
||||
direction: string;
|
||||
|
||||
constructor(x : number, y : number) {
|
||||
constructor(x : number, y : number, direction : string = "none") {
|
||||
if(x === null || y === null){
|
||||
throw Error("position x and y cannot be null");
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
toJson(){
|
||||
return {
|
||||
x : this.x,
|
||||
y: this.y
|
||||
y: this.y,
|
||||
direction: this.direction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +30,7 @@ export class MessageUserPosition extends Message{
|
|||
constructor(message: string) {
|
||||
super(message);
|
||||
let data = JSON.parse(message);
|
||||
this.position = new Point(data.position.x, data.position.y);
|
||||
this.position = new Point(data.position.x, data.position.y, data.position.direction);
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
export interface PointInterface {
|
||||
x: number;
|
||||
y: number;
|
||||
direction: string;
|
||||
toJson() : object;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue