Add a bare bones Player class, with socket and name data
This commit is contained in:
parent
8f671d33cf
commit
1edd3a042e
1 changed files with 26 additions and 0 deletions
26
server/src/objects/Player.ts
Normal file
26
server/src/objects/Player.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { PlayerData } from "common";
|
||||
import { Socket } from "socket.io";
|
||||
|
||||
export class Player {
|
||||
readonly name: string;
|
||||
|
||||
|
||||
constructor(socket: Socket, data: PlayerData) {
|
||||
this.name = data.name;
|
||||
this._socket = socket
|
||||
};
|
||||
|
||||
|
||||
// The player's socket data
|
||||
private _socket: Socket;
|
||||
|
||||
/** The socket that can be used to communicate directly with the player */
|
||||
get socket() { return this._socket };
|
||||
set socket(value: Socket) {
|
||||
if (!this._socket.connected) {
|
||||
this._socket = value;
|
||||
} else {
|
||||
throw Error("Cannot overwrite a player's socket that is connected.");
|
||||
};
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue