transformice.js
Version:
Node.js client for Transformice with full Typescript support.
78 lines (77 loc) • 2.67 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
/** Represents a room. */
var Room = /** @class */ (function (_super) {
__extends(Room, _super);
/**
* @hidden
*/
function Room(client, isPublic, name, language) {
var _this = _super.call(this, client) || this;
_this.client = client;
_this.name = name;
_this.playerList = [];
_this.isPublic = isPublic;
_this.language = language;
_this.isTribeHouse = name.charCodeAt(1) === 3;
return _this;
}
Room.prototype.getPlayer = function (value) {
if (typeof value === "number")
return this.playerList.find(function (p) { return p.pcode === value; });
else if (typeof value === "string")
return this.playerList.find(function (p) { return p.name === value; });
};
/**
* Removes player from playerList.
*
* @hidden
*/
Room.prototype.removePlayer = function (pcode) {
var index = this.playerList.findIndex(function (p) { return p.pcode === pcode; });
if (index === -1)
return;
return this.playerList.splice(index, 1)[0];
};
/**
* Add player to player list
*/
Room.prototype.addPlayer = function (player) {
var exists = this.playerList.some(function (p) { return p.pcode === player.pcode; });
if (exists)
return;
this.playerList.push(player);
};
/**
* Adds or updates the player in room playerList.
*
* @hidden
*/
Room.prototype.updatePlayer = function (player) {
var playerToUpdate = this.getPlayer(player.pcode);
playerToUpdate = player;
return playerToUpdate;
};
/**
* Sends a message to the room.
*/
Room.prototype.sendMessage = function (message) {
this.client.sendRoomMessage(message);
};
return Room;
}(_1.Base));
exports.default = Room;
;