implement toJSON and fromJSON methods
This commit is contained in:
parent
0a24c009ad
commit
4b5a05f57b
1 changed files with 16 additions and 0 deletions
|
|
@ -12,4 +12,20 @@ export class Player {
|
|||
this.socket = socket;
|
||||
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;
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue