From f14ec9e09f6f057f428a10db6185e9456d941943 Mon Sep 17 00:00:00 2001 From: Kim Ravn Hansen Date: Mon, 13 Oct 2025 15:54:15 +0200 Subject: [PATCH] Bookkeeping and tweaking --- models/game.js | 13 +++++++------ models/portal.js | 26 ++++++++++++-------------- models/session.js | 4 ++-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/models/game.js b/models/game.js index 6194a17..82bdfe6 100755 --- a/models/game.js +++ b/models/game.js @@ -9,10 +9,13 @@ import { isIdSane, miniUid } from "../utils/id.js"; import { Xorshift32 } from "../utils/random.js"; -import { Character } from "./character.js"; -import { ItemAttributes, ItemBlueprint } from "./item.js"; +import { ItemBlueprint } from "./item.js"; import { Player } from "./player.js"; +/** @typedef {import("./character.js").Character} Character */ +/** @typedef {import("./item.js").ItemAttributes} ItemAttributes */ +/** @typedef {import("./item.js").ItemBlueprint} ItemBlueprint */ + export class Game { _counter = 1_000_000; @@ -117,10 +120,8 @@ export class Game { */ getItemBlueprint(blueprintId) { if (!isIdSane(blueprintId)) { - throw new Error(`blueprintId >>${blueprintId}<< is insane!`); + throw new Error(`blueprintId >>${blueprintId}<< is not a valid id`); } - const tpl = this._itemBlueprints.get(blueprintId); - - return tpl || undefined; + return this._itemBlueprints.get(blueprintId); } } diff --git a/models/portal.js b/models/portal.js index f861cc5..264b250 100755 --- a/models/portal.js +++ b/models/portal.js @@ -4,22 +4,20 @@ * Example: two adjacent rooms connected by a door: * Room A has a portal to Room B, and * Room B has a portal to Room A. - * - * @todo Add encounters to portals */ export class Portal { - /** - * Target Location. - */ - _targetLocationId; + /** + * Target Location. + */ + _targetLocationId; - /** - * Description shown to the player when they inspect the portal from the source location. - */ - _description; + /** + * Description shown to the player when they inspect the portal from the source location. + */ + _description; - /** - * Description shown to the player when they traverse the portal. - */ - _traversalDescription; + /** + * Description shown to the player when they traverse the portal. + */ + _traversalDescription; } diff --git a/models/session.js b/models/session.js index dcfa728..4ed3b95 100755 --- a/models/session.js +++ b/models/session.js @@ -1,10 +1,10 @@ -import WebSocket from "ws"; import { Player } from "./player.js"; import { mustBeString, mustBe } from "../utils/mustbe.js"; import { Scene } from "../scenes/scene.js"; -import { gGame } from "./globals.js"; import { formatMessage, MessageType } from "../utils/messages.js"; +/** @typedef {import("ws").WebSocket} WebSocket */ + export class Session { /** @type {WebSocket} */ _websocket;