0
0
Fork 0

implement toJSON and fromJSON methods

This commit is contained in:
Oliver-Akins 2021-01-05 17:00:38 -07:00
parent 0a24c009ad
commit 4b5a05f57b

View file

@ -12,4 +12,20 @@ export class Player {
this.socket = socket; this.socket = socket;
this.isHost = isHost; this.isHost = isHost;
}; };
public toJSON(): datastorePlayer {
return {
name: this.name,
host: this.isHost,
team: this.team,
role: this.role,
};
};
public static fromJSON(data: datastorePlayer, socket: Socket): Player {
let player = new this(data.name, socket, data.host);
player.role = data.role;
player.team = data.team;
return player;
};
}; };