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

@@ -149,14 +149,19 @@ export class TileMap {
}
behavesLikeFloor(x, y) {
console.log("behavesLikeFloor???", { x, y });
x |= 0;
y |= 0;
if (x < 0 || x >= this.width || y < 0 || y >= this.height) {
console.log(" behavesLikeFloor: YES");
return true;
}
return this.tiles[y][x].isFloorlike();
const result = this.tiles[y][x].isFloorlike();
console.log(result ? " YES" : " NOPE");
return result;
}
/**

View File

@@ -1,7 +1,7 @@
import { mustBe, mustBeString } from "../utils/mustbe.js";
import shallowCopy from "../utils/shallowCopy.js";
import { TileOptions } from "../utils/tileOptionsParser.js";
import { Orientation, Vector2i } from "./ascii_types.js";
import { Orientation } from "./ascii_types.js";
/** @typedef {string} TileTypeId - a string with a length of 1 */
@@ -145,7 +145,7 @@ export class Tile {
"REQUIRED_ symbol encountered in Tile constructor. ",
"REQUIRED_ is a placeholder, and cannot be used as a value directly",
].join("\n"),
{ key, val, options: properties },
{ key, val, properties },
);
throw new Error("Incomplete data in constructor. Args may not contain a data placeholder");
}
@@ -198,7 +198,6 @@ export class Tile {
//
// Normalize Orientation.
//
if (this.orientation !== undefined && typeof this.orientation === "string") {
const valueMap = {
north: Orientation.NORTH,
@@ -210,7 +209,7 @@ export class Tile {
}
//
// Tiles are not necessarily required to have an ID, but if they have one, it must be string or number
// Tiles are not required to have IDs, but IDs must be numbers or strings
if (this.id !== undefined) {
mustBe(this.id, "number", "string");
}
@@ -234,8 +233,8 @@ export class Tile {
}
/** @returns {Tile} */
static createEncounterStartPoint() {
return this.fromChar(TileChars.ENCOUNTER_START_POINT);
static createEncounterStartPoint(encounterId) {
return this.fromChar(TileChars.ENCOUNTER_START_POINT, { encounterId });
}
/** @returns {Tile} */
@@ -270,7 +269,7 @@ export class Tile {
// Normalize options into a TileOptions object,
//
if (!(options instanceof TileOptions)) {
options = TileOptions.fromObject(options);
options = TileOptions.fromObject(typeId, options);
}
let optionPos = 0;
@@ -278,7 +277,7 @@ export class Tile {
const getOption = (name) => options.getValue(name, optionPos++);
for (let [key, val] of Object.entries(typeInfo)) {
//
const fetchFromOption = typeof val === "symbol" && val.descript.startsWith("REQUIRED_");
const fetchFromOption = typeof val === "symbol" && val.description.startsWith("REQUIRED_");
creationArgs[key] = fetchFromOption ? getOption(key) : shallowCopy(val);
}
@@ -287,7 +286,7 @@ export class Tile {
}
clone() {
return new this.constructor(this);
return new Tile(this.typeId, this);
}
isWallLike() {
@@ -303,6 +302,10 @@ export class Tile {
}
isFloorlike() {
if (this.typeId === TileChars.FLOOR) {
return true;
}
if (this.is === TileChars.FLOOR) {
return true;
}
@@ -318,7 +321,3 @@ export class Tile {
return this.typeId === TileChars.FLOOR;
}
}
if (Math.PI < 0 && TileOptions && Orientation && Vector2i) {
("STFU Linda");
}

0
frontend/cellular_automata_map_generator.html Normal file → Executable file
View File

View File

@@ -1,5 +1,5 @@
import { CharType, TileMap } from "./ascii_tile_map";
import { Tile } from "./ascii_tile_types";
import { Tile, TileChars } from "./ascii_tile_types";
import { Orientation } from "./ascii_types";
class DungeonGenerator {
@@ -312,7 +312,16 @@ class DungeonGenerator {
addPortals() {
let traversableTileCount = this.map.getFloorlikeTileCount();
const result = this.map.getAllTraversableTilesConnectedTo(/** TODO PlayerPos */);
//
// Find the player's start point, and let this be the
// bases of area 0
const [x, y] = this.map.forEach((tile, x, y) => {
if (tile.typeId === TileChars.PLAYER_START_POINT) {
return [x, y];
}
});
const result = this.map.getAllTraversableTilesConnectedTo(x, y);
if (result.size === traversableTileCount) {
// There are no isolated areas, return
@@ -381,7 +390,7 @@ class DungeonGenerator {
for (let i = 0; i < encouterCount; i++) {
const pos = floorTiles[this.random(0, floorTiles.length - 1)];
if (this.map.tiles[pos.y][pos.x].isFloor()) {
this.map.tiles[pos.y][pos.x] = Tile.createEncounterStartPoint();
this.map.tiles[pos.y][pos.x] = Tile.createEncounterStartPoint("PLACEHOLDER_ENCOUNTER_ID");
// TODO: Add encounter to the dungeon's "roaming entities" array.
}
}
@@ -401,7 +410,8 @@ class DungeonGenerator {
}
}
let currentDungeon = "";
/** @type {string} */
window.currentDungeon = "";
window.generateDungeon = () => {
const width = parseInt(document.getElementById("width").value);
@@ -409,9 +419,9 @@ window.generateDungeon = () => {
const roomCount = parseInt(document.getElementById("roomCount").value);
const generator = new DungeonGenerator(width, height, roomCount);
currentDungeon = generator.generate();
window.currentDungeon = generator.generate();
document.getElementById("dungeonDisplay").textContent = currentDungeon;
document.getElementById("dungeonDisplay").textContent = window.currentDungeon;
};
window.downloadDungeon = () => {

0
frontend/progen.scss Normal file → Executable file
View File