File perms

This commit is contained in:
Kim Ravn Hansen
2025-10-15 12:28:14 +02:00
parent e12dfd0981
commit 59d73955d0
21 changed files with 202 additions and 111 deletions

View File

@@ -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;
}
/**