Removing the Message class and merging it with MessageUserPosition (since it is only ever used it in MessageUserPosition)
Taking advantage of the TypeScript Constructor Assignment too to reduce the amount of code!
This commit is contained in:
parent
3b6ace03fa
commit
b20357c1ee
3 changed files with 5 additions and 47 deletions
|
@ -1,15 +0,0 @@
|
|||
export class Message {
|
||||
userId: string;
|
||||
name: string;
|
||||
character: string;
|
||||
|
||||
constructor(data: any) {
|
||||
if (!data.userId) {
|
||||
console.error("Got invalid message", data);
|
||||
throw Error("userId cannot be null");
|
||||
}
|
||||
this.userId = data.userId;
|
||||
this.name = data.name;
|
||||
this.character = data.character;
|
||||
}
|
||||
}
|
|
@ -2,25 +2,11 @@ import {Message} from "./Message";
|
|||
import {PointInterface} from "./PointInterface";
|
||||
|
||||
export class Point implements PointInterface{
|
||||
x: number;
|
||||
y: number;
|
||||
direction: string;
|
||||
|
||||
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;
|
||||
constructor(public x : number, public y : number, public direction : string = "none") {
|
||||
}
|
||||
}
|
||||
|
||||
export class MessageUserPosition extends Message{
|
||||
position: PointInterface;
|
||||
|
||||
constructor(message: any) {
|
||||
super(message);
|
||||
this.position = new Point(message.position.x, message.position.y, message.position.direction);
|
||||
export class MessageUserPosition {
|
||||
constructor(public userId: string, public name: string, public character: string, public position: PointInterface) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue