File perms
This commit is contained in:
@@ -56,7 +56,8 @@ export class Game {
|
||||
this._random = new Xorshift32(rngSeed);
|
||||
}
|
||||
|
||||
getPlayer(username) {
|
||||
getPlayerByUsername(username) {
|
||||
console.log("GETTING PLAYER: `%s`", username);
|
||||
return this._players.get(username);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Portal } from "./portal";
|
||||
/** @typedef {import("./portal.js").Portal} Portal */
|
||||
|
||||
/**
|
||||
* Location in the world.
|
||||
@@ -9,37 +9,38 @@ import { Portal } from "./portal";
|
||||
* or magical portals to distant locations.
|
||||
*/
|
||||
export class Location {
|
||||
/** @protected @type string */
|
||||
_id;
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
/** @protected @type {string} */
|
||||
_id;
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
/** @protected @type string */
|
||||
_name;
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
/** @protected @type {string} */
|
||||
_name;
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
/** @protected @type string */
|
||||
_description;
|
||||
get description() {
|
||||
return this._description;
|
||||
}
|
||||
/** @protected @type {string} */
|
||||
_description;
|
||||
get description() {
|
||||
return this._description;
|
||||
}
|
||||
|
||||
/** @protected @type {Map<string,Portal>} */
|
||||
_portals = new Map();
|
||||
get portals() {
|
||||
return this._portals;
|
||||
}
|
||||
/** @protected @type {Map<string,Portal>} */
|
||||
_portals = new Map();
|
||||
get portals() {
|
||||
return this._portals;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
constructor(id, name, description) {
|
||||
this._id = id;
|
||||
this._name = name;
|
||||
this._description = description;
|
||||
}
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {string} name
|
||||
* @param {string} description
|
||||
*/
|
||||
constructor(id, name, description) {
|
||||
this._id = id;
|
||||
this._name = name;
|
||||
this._description = description;
|
||||
}
|
||||
}
|
||||
|
||||
const l = new Location("foo", "bar", "baz");
|
||||
|
||||
@@ -10,35 +10,27 @@ export class Session {
|
||||
_websocket;
|
||||
|
||||
/** @protected @type {Scene} */
|
||||
_scene;
|
||||
_currentScene;
|
||||
|
||||
/** @readonly @constant @type {Scene} */
|
||||
/** @readonly @type {Scene} */
|
||||
get scene() {
|
||||
return this._scene;
|
||||
return this._currentScene;
|
||||
}
|
||||
|
||||
/** @type {Player} */
|
||||
/** @constant @type {Player} */
|
||||
_player;
|
||||
|
||||
/**
|
||||
* The player that owns this session.
|
||||
* This value is undefined until the player has logged in,
|
||||
* and after that it is _constant_
|
||||
*
|
||||
* @constant @type {Player}
|
||||
*/
|
||||
get player() {
|
||||
return this._player;
|
||||
}
|
||||
|
||||
/** @param {Player} player */
|
||||
set player(player) {
|
||||
if (player instanceof Player) {
|
||||
this._player = player;
|
||||
return;
|
||||
}
|
||||
|
||||
if (player === null) {
|
||||
this._player = null;
|
||||
return;
|
||||
}
|
||||
|
||||
throw Error(`Can only set player to null or instance of Player, but received ${typeof player}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {WebSocket} websocket
|
||||
*/
|
||||
@@ -54,10 +46,30 @@ export class Session {
|
||||
if (!(scene instanceof Scene)) {
|
||||
throw new Error(`Expected instance of Scene, got a ${typeof scene}: >>${scene}<<`);
|
||||
}
|
||||
this._scene = scene;
|
||||
this._currentScene = scene;
|
||||
scene.execute(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* May only be called when the current player property has not yet been populated.
|
||||
* May only called once.
|
||||
*
|
||||
* @param {Player} player
|
||||
*/
|
||||
setPlayer(player) {
|
||||
if (player instanceof Player) {
|
||||
this._player = player;
|
||||
return;
|
||||
}
|
||||
|
||||
if (player === null) {
|
||||
this._player = null;
|
||||
return;
|
||||
}
|
||||
|
||||
throw Error(`Can only set player to null or instance of Player, but received ${typeof player}`);
|
||||
}
|
||||
|
||||
/** Close the session and websocket */
|
||||
close() {
|
||||
if (this._websocket) {
|
||||
@@ -65,7 +77,7 @@ export class Session {
|
||||
this._websocket = null;
|
||||
}
|
||||
this._player = null;
|
||||
this._scene = null;
|
||||
this._currentScene = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user