From 0ee62edb6c6832aa53940f95c87c564df6159c9f Mon Sep 17 00:00:00 2001 From: Kim Ravn Hansen Date: Thu, 16 Oct 2025 13:47:47 +0200 Subject: [PATCH] this is a commit. it contains changes. they are not atomic. they do not maintain the code in a working state. it is sloppy. yay. --- frontend/ascii_tile_map.js | 14 +++++++++++--- frontend/ascii_tile_types.js | 22 ++++++++++++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/frontend/ascii_tile_map.js b/frontend/ascii_tile_map.js index e8e1b72..2441f1c 100755 --- a/frontend/ascii_tile_map.js +++ b/frontend/ascii_tile_map.js @@ -25,7 +25,7 @@ import { Vector2i } from "./ascii_types.js"; * @readonly @constant @enum {string} */ export const CharType = { - SYSTEM: "typeId", + TYPE_ID: "typeId", MINIMAP: "minimapChar", MINIMAP_REVEALED: "revealedMinimapChar", }; @@ -98,17 +98,25 @@ export class TileMap { * @param {CharType} charType * @returns {string} */ - toString(charType = CharType.SYSTEM) { + toString(charType = CharType.TYPE_ID) { + const undefinedCharPlaceholder = "?"; let result = ""; + let errorCount = 0; for (let y = 0; y < this.height; y++) { for (let x = 0; x < this.width; x++) { const tile = this.tiles[y][x]; - result += tile[charType] ?? "Ø"; + console.log(tile); + errorCount += tile[charType] === undefined; + result += tile[charType] ?? undefinedCharPlaceholder; } result += "\n"; } + if (errorCount > 0) { + console.warn("Could not convert map to string", { errorCount }); + } + return result; } diff --git a/frontend/ascii_tile_types.js b/frontend/ascii_tile_types.js index 14ca02e..3ced65e 100755 --- a/frontend/ascii_tile_types.js +++ b/frontend/ascii_tile_types.js @@ -24,19 +24,18 @@ export const TileChars = Object.freeze({ const REQUIRED_ID = Symbol("REQUIRED_ID"); const REQUIRED_ORIENTATION = Symbol("REQUIRED_ORIENTATION"); -const REQUIRED_OCCUPANTS = Symbol("REQUIRED_OCCUPANTS"); /** @type {Record} */ export const TileTypes = { [TileChars.FLOOR]: { minimapChar: "·", - traversable: true, + isTraversable: true, }, [TileChars.WALL]: { minimapChar: "█", minimapColor: "#aaa", textureId: "wall", - traversable: false, + isTraversable: false, looksLikeWall: true, }, [TileChars.SECRET_PORTAL]: { @@ -58,7 +57,6 @@ export const TileTypes = { is: TileChars.FLOOR, // this is actually just a floor tile that is occupied by an encounter when the map is loaded encounterId: REQUIRED_ID, textureId: REQUIRED_ID, - occupants: REQUIRED_OCCUPANTS, }, [TileChars.PLAYER_START_POINT]: { is: TileChars.FLOOR, @@ -100,7 +98,7 @@ export class Tile { textureId; /** @type {number|string} type of encounter located on this tile. May or may not be unique*/ - encounterType; + encounterId; /** @type {number|string} type of trap located on this tile. May or may not be unique*/ trapType; @@ -139,6 +137,11 @@ export class Tile { // Copy props from properties. // for (const [key, val] of Object.entries(properties)) { + // + // Ensure that we do not have placeholder symbols in the incoming properties + // Placeolder symbols indicate that the data must be supplied externally by + // the creator of the tile + // if (typeof val === "symbol" && val.description.startsWith("REQUIRED_")) { console.error( [ @@ -225,6 +228,9 @@ export class Tile { if (this.portalTargetId !== undefined) { mustBe(this.portalTargetId, "number", "string"); } + + this.minimapChar ??= this.typeId; + this.revealedMinimapChar ??= this.minimapChar; } /** @returns {Tile} */ @@ -254,9 +260,9 @@ export class Tile { * @returns {Tile} */ static fromChar(typeId, options) { - const typeInfo = TileTypes[typeId]; + const prototype = TileTypes[typeId]; - if (!typeInfo) { + if (!prototype) { console.log("unknown type id", { typeId }); throw new Error(`Unknown typeId >>>${typeId}<<<`); } @@ -275,7 +281,7 @@ export class Tile { let optionPos = 0; const creationArgs = {}; const getOption = (name) => options.getValue(name, optionPos++); - for (let [key, val] of Object.entries(typeInfo)) { + for (let [key, val] of Object.entries(prototype)) { // const fetchFromOption = typeof val === "symbol" && val.description.startsWith("REQUIRED_");