Add a bare bones Player class, with socket and name data

This commit is contained in:
Oliver-Akins 2022-01-09 01:20:43 -06:00
parent 8f671d33cf
commit 1edd3a042e

View 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.");
};
};
};