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.
This commit is contained in:
Kim Ravn Hansen
2025-10-16 13:47:47 +02:00
parent 218eee1df2
commit 0ee62edb6c
2 changed files with 25 additions and 11 deletions

View File

@@ -25,7 +25,7 @@ import { Vector2i } from "./ascii_types.js";
* @readonly @constant @enum {string} * @readonly @constant @enum {string}
*/ */
export const CharType = { export const CharType = {
SYSTEM: "typeId", TYPE_ID: "typeId",
MINIMAP: "minimapChar", MINIMAP: "minimapChar",
MINIMAP_REVEALED: "revealedMinimapChar", MINIMAP_REVEALED: "revealedMinimapChar",
}; };
@@ -98,17 +98,25 @@ export class TileMap {
* @param {CharType} charType * @param {CharType} charType
* @returns {string} * @returns {string}
*/ */
toString(charType = CharType.SYSTEM) { toString(charType = CharType.TYPE_ID) {
const undefinedCharPlaceholder = "?";
let result = ""; let result = "";
let errorCount = 0;
for (let y = 0; y < this.height; y++) { for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) { for (let x = 0; x < this.width; x++) {
const tile = this.tiles[y][x]; const tile = this.tiles[y][x];
result += tile[charType] ?? "Ø"; console.log(tile);
errorCount += tile[charType] === undefined;
result += tile[charType] ?? undefinedCharPlaceholder;
} }
result += "\n"; result += "\n";
} }
if (errorCount > 0) {
console.warn("Could not convert map to string", { errorCount });
}
return result; return result;
} }

View File

@@ -24,19 +24,18 @@ export const TileChars = Object.freeze({
const REQUIRED_ID = Symbol("REQUIRED_ID"); const REQUIRED_ID = Symbol("REQUIRED_ID");
const REQUIRED_ORIENTATION = Symbol("REQUIRED_ORIENTATION"); const REQUIRED_ORIENTATION = Symbol("REQUIRED_ORIENTATION");
const REQUIRED_OCCUPANTS = Symbol("REQUIRED_OCCUPANTS");
/** @type {Record<TileTypeId,Tile>} */ /** @type {Record<TileTypeId,Tile>} */
export const TileTypes = { export const TileTypes = {
[TileChars.FLOOR]: { [TileChars.FLOOR]: {
minimapChar: "·", minimapChar: "·",
traversable: true, isTraversable: true,
}, },
[TileChars.WALL]: { [TileChars.WALL]: {
minimapChar: "█", minimapChar: "█",
minimapColor: "#aaa", minimapColor: "#aaa",
textureId: "wall", textureId: "wall",
traversable: false, isTraversable: false,
looksLikeWall: true, looksLikeWall: true,
}, },
[TileChars.SECRET_PORTAL]: { [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 is: TileChars.FLOOR, // this is actually just a floor tile that is occupied by an encounter when the map is loaded
encounterId: REQUIRED_ID, encounterId: REQUIRED_ID,
textureId: REQUIRED_ID, textureId: REQUIRED_ID,
occupants: REQUIRED_OCCUPANTS,
}, },
[TileChars.PLAYER_START_POINT]: { [TileChars.PLAYER_START_POINT]: {
is: TileChars.FLOOR, is: TileChars.FLOOR,
@@ -100,7 +98,7 @@ export class Tile {
textureId; textureId;
/** @type {number|string} type of encounter located on this tile. May or may not be unique*/ /** @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*/ /** @type {number|string} type of trap located on this tile. May or may not be unique*/
trapType; trapType;
@@ -139,6 +137,11 @@ export class Tile {
// Copy props from properties. // Copy props from properties.
// //
for (const [key, val] of Object.entries(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_")) { if (typeof val === "symbol" && val.description.startsWith("REQUIRED_")) {
console.error( console.error(
[ [
@@ -225,6 +228,9 @@ export class Tile {
if (this.portalTargetId !== undefined) { if (this.portalTargetId !== undefined) {
mustBe(this.portalTargetId, "number", "string"); mustBe(this.portalTargetId, "number", "string");
} }
this.minimapChar ??= this.typeId;
this.revealedMinimapChar ??= this.minimapChar;
} }
/** @returns {Tile} */ /** @returns {Tile} */
@@ -254,9 +260,9 @@ export class Tile {
* @returns {Tile} * @returns {Tile}
*/ */
static fromChar(typeId, options) { static fromChar(typeId, options) {
const typeInfo = TileTypes[typeId]; const prototype = TileTypes[typeId];
if (!typeInfo) { if (!prototype) {
console.log("unknown type id", { typeId }); console.log("unknown type id", { typeId });
throw new Error(`Unknown typeId >>>${typeId}<<<`); throw new Error(`Unknown typeId >>>${typeId}<<<`);
} }
@@ -275,7 +281,7 @@ export class Tile {
let optionPos = 0; let optionPos = 0;
const creationArgs = {}; const creationArgs = {};
const getOption = (name) => options.getValue(name, optionPos++); 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_"); const fetchFromOption = typeof val === "symbol" && val.description.startsWith("REQUIRED_");