merge state debug dumper

This commit is contained in:
Kistaro Windrider 2025-02-22 19:48:00 -08:00
parent 8bf7f0f151
commit 234a42b1e3
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -89,6 +89,72 @@ class Knife {
}
}
}
showDebug(merged: Record<number, number>) {
if (true) {
let out = "";
let errors: string[] = [];
const size = this.#regions.size;
for (let y = 0; y < size.h; y++) {
for (let x = 0; x < size.w; x++) {
const loc = new Point(x, y);
out += (() => {
if (this.#sealedWalls.get(loc)) {
return "█";
}
if (this.#map.get(loc).architecture == Architecture.Wall) {
return "#";
}
let r = this.#regions.get(loc);
if(typeof r === "number") {
const resolved = merged[r];
if (typeof resolved === "number") {
r = resolved;
} else {
errors.push(`${loc} is region ${r}, not found in merged`)
}
// 0...9 and lowercase
if (r < 36) {
return r.toString(36)
}
// uppercase
r -= 26;
if (r < 36) {
return r.toString(36).toUpperCase()
}
// Greek lowercase
r -= 36;
if (r < 25) {
return String.fromCodePoint(r + 0x3b1);
}
// Greek uppercase (there is a hole at 0x3a2)
r -= 25;
if (r < 17) {
return String.fromCodePoint(r + 0x391);
}
r -= 17;
if (r < 7) {
return String.fromCodePoint(r + 0x3a3);
}
// Hebrew
r -= 7
if (r < 27) {
return String.fromCodePoint(r+0x5d0);
}
// give up
return "?"
}
return "."; // room without region
})();
}
out += "\n";
}
console.log(out);
if (errors.length > 0) {
console.log(`uh-oh: \n\t${errors.join("\n\t")}`);
}
}
}
}
export function generateMap(): LoadedNewMap {