UNPKG

nodito

Version:

Una librería para aprender juegos por turnos en node.

68 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class User { constructor(id = "", token = "", sendToClient = ((x) => x)) { this.id = id; this.token = token; this.sendToClient = sendToClient; this.lastSeen = new Date(); this.name = ""; this._player = null; } get player() { return this._player; } set player(value) { this._player = value; } playGame(msg) { if (this.player) { this.player.playGame(msg); } } getName() { return this.name; } setName(x) { this.name = x; } setRoom(x) { if (this.player) { this.player.setRoom(x); } } getId() { return this.id; } getToken() { return this.token; } send(msg) { this.sendToClient(msg); } toClient(turn = false) { return { id: this.getId(), name: this.getName(), playing: this.player && this.player.isPlaying(), turn: turn ? this.player && this.player.getTurn() : {}, }; } sendStatus() { if (this.player) { this.player.sendStatus(); } } markLastSeen() { this.lastSeen = new Date(); } secondsFromLastSeen() { const now = new Date(); return Math.abs(now.getTime() - this.lastSeen.getTime()) / 1000; } isPlaying() { return this.player && this.player.isPlaying(); } } exports.User = User; //# sourceMappingURL=User.js.map