Switch stone walls to named cardinal connect states.
Drop diagonals; rename assets to thick/thin-stone-wall with suffixes like esw/wne/we/ns, generated from the authored examples for correction.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -1,39 +1,41 @@
/**
* Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
* (cardinals + diagonal corners — 47 valid states).
* Generate thin + thick stone-wall PNGs for the 16 cardinal neighbor masks.
*
* Flat greys only (no texture). Authoritative examples live beside the outputs:
* example-stone-{thin|thick}.png
* example-stone-{thin|thick}-connecting.png E
* example-stone-{thin|thick}-connecting-up.png N
* example-stone-thin-connecting-down.png S (thin)
* example-stone-{thin|thick}-connecting-updown.png N+S
* example-stone-{thin|thick}-connecting-L.png N+E (concave)
* example-stone-thin-connecting-Ldownright.png S+E (concave, thin)
* example-stone-{thin|thick}-connecting-2x2.png N+E+NE (filled)
* example-stone-thin-connecting-T.png E+S+W
* example-stone-thin-connecting-T-upsidedown.png N+E+W
* example-stone-thick-T.png E+S+W (thick)
* Naming: `{key}.png` alone, `{key}-{suffix}.png` when connected.
* Suffixes: n/e/s/w, ns, we, ne/es/sw/wn, esw/wne/swn/nes, nesw.
*
* West variants are X-mirrors. Remaining masks compose from these stamps +
* the L↔2×2 corner-fill delta.
* Examples (shape only, no texture) live in
* client/assets/blocks/_examples/stone-wall/
*
* node client/scripts/generate-stone-wall-sprites.mjs
*/
import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync, existsSync } from "node:fs";
import {
mkdirSync,
writeFileSync,
readdirSync,
unlinkSync,
readFileSync,
existsSync,
cpSync,
rmSync
} from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import {
NeighborBit,
listValidNeighborConnectCornerMasks
cardinalConnectionSuffix,
composeNamedNeighborConnectState
} from "../../shared/world/neighborConnect.js";
const SIZE = 16;
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
const OUT_THICK = join(ROOT, "stone-wall");
const OUT_THIN = join(ROOT, "stone-wall-thin");
const EXAMPLES = join(ROOT, "stone-wall");
const EXAMPLES = join(ROOT, "_examples/stone-wall");
const OUT_THICK = join(ROOT, "thick-stone-wall");
const OUT_THIN = join(ROOT, "thin-stone-wall");
const THICK = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true };
const THIN = { key: "thin-stone-wall", neighborConnect: true, neighborConnectNamed: true };
function crcTable ()
{
@@ -234,93 +236,21 @@ function blit (dst, src)
}
}
/** Pixels where filled differs from concave (the diagonal corner fill). */
function cornerDelta (concave, filled)
{
const deltas = [];
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
const a = getPx(concave, x, y);
const b = getPx(filled, x, y);
if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2]))
{ deltas.push({ x, y, color: b }); }
else if (a[3] > 128 && b[3] <= 128)
{ deltas.push({ x, y, color: [0, 0, 0, 0] }); }
}
}
return deltas;
}
function applyDelta (dst, deltas, mapX, mapY)
{
for (const d of deltas)
{
const x = mapX(d.x);
const y = mapY(d.y);
setPx(dst, x, y, d.color);
}
}
function idX (x)
{ return x; }
function idY (y)
{ return y; }
function flipX (x)
{ return SIZE - 1 - x; }
function flipY (y)
{ return SIZE - 1 - y; }
/**
* Build south-east L by compositing down+east and punching the SE corner using
* the NE L↔2×2 delta rotated 180° in corner space (flipX+flipY of NE delta
* relative to tile — actually SE is flipY of NE region for thin).
*
* Simpler: if we have an authored Ldownright, use it. Otherwise compose.
*/
function composeSEFromNE (ellNE, fillNE, east, south)
{
const out = clearRgba();
blit(out, south);
blit(out, east);
// Remove NE-style fill if any leaked; then we want SE concave by default.
// Punch using mapped NE delta: NE fill region → clear for concave SE.
const delta = cornerDelta(ellNE, fillNE);
for (const d of delta)
{
// Map NE corner (top-right) → SE corner (bottom-right): keep x, flip y.
const x = d.x;
const y = flipY(d.y);
// Only clear / don't apply fill for the concave L.
if (d.color[3] > 128)
{
// Was a fill pixel in 2x2 — ensure concave leaves it empty (or outline).
const src = getPx(ellNE, d.x, d.y);
setPx(out, x, y, src[3] > 128 ? getPx(east, x, Math.min(12, y)) : [0, 0, 0, 0]);
if (src[3] <= 128)
{ setPx(out, x, y, [0, 0, 0, 0]); }
}
}
return out;
}
function fillSEFromNE (ellSE, ellNE, fillNE)
/** Ensure example folder exists; migrate from legacy stone-wall/ if needed. */
function ensureExamples ()
{
const out = copyRgba(ellSE);
const delta = cornerDelta(ellNE, fillNE);
for (const d of delta)
mkdirSync(EXAMPLES, { recursive: true });
const legacy = join(ROOT, "stone-wall");
if (!existsSync(legacy))
{ return; }
for (const name of readdirSync(legacy))
{
const x = d.x;
const y = flipY(d.y);
if (d.color[3] > 128)
{
// Prefer sampling from the SE L's nearby interior.
const sample = getPx(ellSE, Math.min(SIZE - 1, Math.max(0, x - 1)), Math.min(SIZE - 1, Math.max(0, y - 1)));
setPx(out, x, y, sample[3] > 128 ? sample : d.color);
}
if (!name.startsWith("example-") || !name.endsWith(".png"))
{ continue; }
const dest = join(EXAMPLES, name);
if (!existsSync(dest))
{ cpSync(join(legacy, name), dest); }
}
return out;
}
function buildPack (kind)
@@ -328,34 +258,21 @@ function buildPack (kind)
const alone = loadExample(`example-stone-${kind}.png`);
const east = loadExample(`example-stone-${kind}-connecting.png`);
const north = loadExample(`example-stone-${kind}-connecting-up.png`);
const southAuthored = loadExample(`example-stone-${kind}-connecting-down.png`);
const south = loadExample(`example-stone-${kind}-connecting-down.png`);
const ns = loadExample(`example-stone-${kind}-connecting-updown.png`);
const ellNE = loadExample(`example-stone-${kind}-connecting-L.png`);
const fillNE = loadExample(`example-stone-${kind}-connecting-2x2.png`);
const ellSEAuthored = loadExample(`example-stone-${kind}-connecting-Ldownright.png`);
const ellSE = loadExample(`example-stone-${kind}-connecting-Ldownright.png`);
const teeESW = loadExample(`example-stone-${kind}-T.png`)
?? loadExample(`example-stone-${kind}-connecting-T.png`);
const teeNEW = loadExample(`example-stone-${kind}-connecting-T-upsidedown.png`);
if (!alone || !east || !north || !ellNE || !fillNE || !ns)
{ throw new Error(`Missing core ${kind} examples`); }
if (!alone || !east || !north || !ns)
{ throw new Error(`Missing core ${kind} examples in ${EXAMPLES}`); }
const west = mirrorX(east);
const southFinal = southAuthored ?? (() =>
const southFinal = south ?? (() =>
{
// No authored south: alone top + updown shaft through the bottom.
const out = copyRgba(alone);
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
if (y < 2 && opaque(alone, x, y))
{ continue; }
if (opaque(ns, x, y))
{ setPx(out, x, y, getPx(ns, x, y)); }
}
}
// Ensure bottom rows are open shaft from updown.
for (let y = 10; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
@@ -367,45 +284,46 @@ function buildPack (kind)
return out;
})();
const ellSEFinal = ellSEAuthored ?? composeSEFromNE(ellNE, fillNE, east, southFinal);
const fillSE = fillSEFromNE(ellSEFinal, ellNE, fillNE);
const ellNW = mirrorX(ellNE);
const fillNW = mirrorX(fillNE);
const ellNEFinal = ellNE ?? (() =>
{
const out = clearRgba();
blit(out, north);
blit(out, east);
return out;
})();
const ellSEFinal = ellSE ?? (() =>
{
const out = clearRgba();
blit(out, southFinal);
blit(out, east);
return out;
})();
const ellNW = mirrorX(ellNEFinal);
const ellSW = mirrorX(ellSEFinal);
const fillSW = mirrorX(fillSE);
const ew = (() =>
{
const out = clearRgba();
blit(out, east);
blit(out, west);
// Close the center seam: fill any gap on rows that both sides use.
for (let y = 0; y < SIZE; y++)
{
if (!opaque(east, SIZE - 1, y))
{ continue; }
let fill = null;
for (let x = 0; x < SIZE; x++)
for (let x = SIZE - 1; x >= 0; x--)
{
const c = getPx(east, x, y);
if (c[3] > 128)
{ fill = c; }
{ fill = c; break; }
}
if (!fill)
{ continue; }
for (let x = 0; x < SIZE; x++)
{
if (!opaque(out, x, y) && (opaque(east, SIZE - 1, y) || opaque(west, 0, y)))
if (!opaque(out, x, y))
{ setPx(out, x, y, fill); }
}
// Force full row when east template opens to the edge on this row.
if (opaque(east, SIZE - 1, y))
{
for (let x = 0; x < SIZE; x++)
{
if (!opaque(out, x, y))
{ setPx(out, x, y, fill); }
}
}
}
return out;
})();
@@ -433,119 +351,34 @@ function buildPack (kind)
return out;
})();
const teeNWS = mirrorX(teeNES);
/** Exact mask → rgba for authored / derived cardinal templates (no diagonals). */
const byMask = new Map();
byMask.set(0, alone);
byMask.set(NeighborBit.n, north);
byMask.set(NeighborBit.e, east);
byMask.set(NeighborBit.s, southFinal);
byMask.set(NeighborBit.w, west);
byMask.set(NeighborBit.n | NeighborBit.s, ns);
byMask.set(NeighborBit.e | NeighborBit.w, ew);
byMask.set(NeighborBit.n | NeighborBit.e, ellNE);
byMask.set(NeighborBit.n | NeighborBit.w, ellNW);
byMask.set(NeighborBit.s | NeighborBit.e, ellSEFinal);
byMask.set(NeighborBit.s | NeighborBit.w, ellSW);
byMask.set(NeighborBit.e | NeighborBit.s | NeighborBit.w, teeESWFinal);
byMask.set(NeighborBit.n | NeighborBit.e | NeighborBit.w, teeNEWFinal);
byMask.set(NeighborBit.n | NeighborBit.e | NeighborBit.s, teeNES);
byMask.set(NeighborBit.n | NeighborBit.w | NeighborBit.s, teeNWS);
byMask.set(
NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w,
(() =>
{
const out = clearRgba();
blit(out, ns);
blit(out, ew);
blit(out, teeESWFinal);
blit(out, teeNEWFinal);
return out;
})()
);
// Filled-corner variants for the primary L corners.
byMask.set(NeighborBit.n | NeighborBit.e | NeighborBit.ne, fillNE);
byMask.set(NeighborBit.n | NeighborBit.w | NeighborBit.nw, fillNW);
byMask.set(NeighborBit.s | NeighborBit.e | NeighborBit.se, fillSE);
byMask.set(NeighborBit.s | NeighborBit.w | NeighborBit.sw, fillSW);
const neDelta = cornerDelta(ellNE, fillNE);
const nwDelta = cornerDelta(ellNW, fillNW);
const seDelta = cornerDelta(ellSEFinal, fillSE);
const swDelta = cornerDelta(ellSW, fillSW);
return {
byMask,
neDelta,
nwDelta,
seDelta,
swDelta,
alone,
east,
west,
north,
south: southFinal,
ns,
ew,
ellNE,
fillNE
};
}
function paintMask (mask, pack)
{
const n = (mask & NeighborBit.n) !== 0;
const e = (mask & NeighborBit.e) !== 0;
const s = (mask & NeighborBit.s) !== 0;
const w = (mask & NeighborBit.w) !== 0;
const ne = (mask & NeighborBit.ne) !== 0;
const se = (mask & NeighborBit.se) !== 0;
const sw = (mask & NeighborBit.sw) !== 0;
const nw = (mask & NeighborBit.nw) !== 0;
const cardinal = (n ? NeighborBit.n : 0)
| (e ? NeighborBit.e : 0)
| (s ? NeighborBit.s : 0)
| (w ? NeighborBit.w : 0);
// Exact hit (including known filled corners).
if (pack.byMask.has(mask))
{ return copyRgba(pack.byMask.get(mask)); }
// Start from cardinal-only template, then apply diagonal fills.
let out;
if (pack.byMask.has(cardinal))
{ out = copyRgba(pack.byMask.get(cardinal)); }
else
const all = (() =>
{
out = clearRgba();
if (n)
{ blit(out, pack.north); }
if (s)
{ blit(out, pack.south); }
if (e)
{ blit(out, pack.east); }
if (w)
{ blit(out, pack.west); }
if (n && s)
{ blit(out, pack.ns); }
if (e && w)
{ blit(out, pack.ew); }
}
const out = clearRgba();
blit(out, ns);
blit(out, ew);
return out;
})();
if (n && e && ne)
{ applyDelta(out, pack.neDelta, idX, idY); }
if (n && w && nw)
{ applyDelta(out, pack.nwDelta, idX, idY); }
if (s && e && se)
{ applyDelta(out, pack.seDelta, idX, idY); }
if (s && w && sw)
{ applyDelta(out, pack.swDelta, idX, idY); }
// When diagonal is absent but cardinal template accidentally included fill,
// strip using inverse delta (already concave templates are used for cardinal).
return out;
const byMask = new Map([
[0, alone],
[NeighborBit.n, north],
[NeighborBit.e, east],
[NeighborBit.s, southFinal],
[NeighborBit.w, west],
[NeighborBit.n | NeighborBit.s, ns],
[NeighborBit.e | NeighborBit.w, ew],
[NeighborBit.n | NeighborBit.e, ellNEFinal],
[NeighborBit.e | NeighborBit.s, ellSEFinal],
[NeighborBit.s | NeighborBit.w, ellSW],
[NeighborBit.w | NeighborBit.n, ellNW],
[NeighborBit.e | NeighborBit.s | NeighborBit.w, teeESWFinal],
[NeighborBit.w | NeighborBit.n | NeighborBit.e, teeNEWFinal],
[NeighborBit.n | NeighborBit.e | NeighborBit.s, teeNES],
[NeighborBit.n | NeighborBit.w | NeighborBit.s, teeNWS],
[NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w, all]
]);
return { byMask, alone, east, north, ns, ellNE: ellNEFinal };
}
function clearGenerated (dir)
@@ -553,48 +386,59 @@ function clearGenerated (dir)
mkdirSync(dir, { recursive: true });
for (const name of readdirSync(dir))
{
if (!/^\d+\.png$/i.test(name))
if (!name.endsWith(".png") || name.startsWith("example"))
{ continue; }
unlinkSync(join(dir, name));
}
}
function writeSet (dir, pack, label)
function writeSet (dir, def, pack)
{
clearGenerated(dir);
const masks = listValidNeighborConnectCornerMasks();
for (const mask of masks)
for (let mask = 0; mask < 16; mask++)
{
const rgba = pack.byMask.get(mask);
if (!rgba)
{ throw new Error(`Missing mask ${mask} for ${def.key}`); }
const state = composeNamedNeighborConnectState(def, mask);
writeFileSync(join(dir, `${state}.png`), encodePng(rgba));
}
console.log(`Wrote 16 ${def.key} sprites → ${dir}`);
}
function removeLegacyFolders ()
{
for (const name of ["stone-wall", "stone-wall-thin"])
{
writeFileSync(join(dir, `${mask}.png`), encodePng(paintMask(mask, pack)));
const dir = join(ROOT, name);
if (!existsSync(dir))
{ continue; }
// Keep examples only in _examples/; remove entire legacy folder.
rmSync(dir, { recursive: true, force: true });
console.log(`Removed legacy ${name}/`);
}
console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
}
ensureExamples();
const thin = buildPack("thin");
const thick = buildPack("thick");
function assertSame (a, b, label)
{
for (let i = 0; i < a.length; i++)
{
if (a[i] !== b[i])
{ throw new Error(`Mismatch ${label} @${i}: ${a[i]}≠${b[i]}`); }
{ throw new Error(`Mismatch ${label}`); }
}
}
assertSame(thin.byMask.get(0), thin.alone, "thin alone");
assertSame(thin.byMask.get(1), thin.north, "thin n");
assertSame(thin.byMask.get(2), thin.east, "thin e");
assertSame(thin.byMask.get(5), thin.ns, "thin ns");
assertSame(thick.byMask.get(0), thick.alone, "thick alone");
const thin = buildPack("thin");
const thick = buildPack("thick");
writeSet(OUT_THIN, THIN, thin);
writeSet(OUT_THICK, THICK, thick);
removeLegacyFolders();
assertSame(paintMask(0, thin), thin.alone, "thin/0");
assertSame(paintMask(1, thin), thin.north, "thin/1");
assertSame(paintMask(2, thin), thin.east, "thin/2");
assertSame(paintMask(3, thin), thin.ellNE, "thin/3");
assertSame(paintMask(5, thin), thin.ns, "thin/5");
assertSame(paintMask(19, thin), thin.fillNE, "thin/19");
assertSame(paintMask(0, thick), thick.alone, "thick/0");
assertSame(paintMask(1, thick), thick.north, "thick/1");
assertSame(paintMask(2, thick), thick.east, "thick/2");
assertSame(paintMask(3, thick), thick.ellNE, "thick/3");
assertSame(paintMask(5, thick), thick.ns, "thick/5");
assertSame(paintMask(19, thick), thick.fillNE, "thick/19");
writeSet(OUT_THIN, thin, "thin");
writeSet(OUT_THICK, thick, "thick");
console.log("All authored core templates verified.");
console.log("Suffixes:", [...Array(16)].map((_, m) => `${m}=${cardinalConnectionSuffix(m) || "(alone)"}`).join(", "));
@@ -1,39 +1,41 @@/**/** * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks * Generate thin + thick stone-wall PNGs for the 16 cardinal neighbor masks. * (cardinals + diagonal corners — 47 valid states). * * * Flat greys only (no texture). Authoritative examples live beside the outputs: * Naming: `{key}.png` alone, `{key}-{suffix}.png` when connected. * example-stone-{thin|thick}.png * Suffixes: n/e/s/w, ns, we, ne/es/sw/wn, esw/wne/swn/nes, nesw. * example-stone-{thin|thick}-connecting.png E * example-stone-{thin|thick}-connecting-up.png N * example-stone-thin-connecting-down.png S (thin) * example-stone-{thin|thick}-connecting-updown.png N+S * example-stone-{thin|thick}-connecting-L.png N+E (concave) * example-stone-thin-connecting-Ldownright.png S+E (concave, thin) * example-stone-{thin|thick}-connecting-2x2.png N+E+NE (filled) * example-stone-thin-connecting-T.png E+S+W * example-stone-thin-connecting-T-upsidedown.png N+E+W * example-stone-thick-T.png E+S+W (thick) * * * West variants are X-mirrors. Remaining masks compose from these stamps + * Examples (shape only, no texture) live in * the L↔2×2 corner-fill delta. * client/assets/blocks/_examples/stone-wall/ * * * node client/scripts/generate-stone-wall-sprites.mjs * node client/scripts/generate-stone-wall-sprites.mjs */ */import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync, existsSync } from "node:fs";import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync, existsSync, cpSync, rmSync} from "node:fs";import { deflateSync, inflateSync } from "node:zlib";import { deflateSync, inflateSync } from "node:zlib";import { fileURLToPath } from "node:url";import { fileURLToPath } from "node:url";import { dirname, join } from "node:path";import { dirname, join } from "node:path";import {import { NeighborBit, NeighborBit, listValidNeighborConnectCornerMasks cardinalConnectionSuffix, composeNamedNeighborConnectState} from "../../shared/world/neighborConnect.js";} from "../../shared/world/neighborConnect.js";const SIZE = 16;const SIZE = 16;const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");const OUT_THICK = join(ROOT, "stone-wall");const EXAMPLES = join(ROOT, "_examples/stone-wall");const OUT_THIN = join(ROOT, "stone-wall-thin");const OUT_THICK = join(ROOT, "thick-stone-wall");const EXAMPLES = join(ROOT, "stone-wall");const OUT_THIN = join(ROOT, "thin-stone-wall");const THICK = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true };const THIN = { key: "thin-stone-wall", neighborConnect: true, neighborConnectNamed: true };function crcTable ()function crcTable (){{@@ -234,93 +236,21 @@ function blit (dst, src) } }}}/** Pixels where filled differs from concave (the diagonal corner fill). *//** Ensure example folder exists; migrate from legacy stone-wall/ if needed. */function cornerDelta (concave, filled)function ensureExamples (){ const deltas = []; for (let y = 0; y < SIZE; y++) { for (let x = 0; x < SIZE; x++) { const a = getPx(concave, x, y); const b = getPx(filled, x, y); if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2])) { deltas.push({ x, y, color: b }); } else if (a[3] > 128 && b[3] <= 128) { deltas.push({ x, y, color: [0, 0, 0, 0] }); } } } return deltas;}function applyDelta (dst, deltas, mapX, mapY){ for (const d of deltas) { const x = mapX(d.x); const y = mapY(d.y); setPx(dst, x, y, d.color); }}function idX (x){ return x; }function idY (y){ return y; }function flipX (x){ return SIZE - 1 - x; }function flipY (y){ return SIZE - 1 - y; }/** * Build south-east L by compositing down+east and punching the SE corner using * the NE L↔2×2 delta rotated 180° in corner space (flipX+flipY of NE delta * relative to tile — actually SE is flipY of NE region for thin). * * Simpler: if we have an authored Ldownright, use it. Otherwise compose. */function composeSEFromNE (ellNE, fillNE, east, south){ const out = clearRgba(); blit(out, south); blit(out, east); // Remove NE-style fill if any leaked; then we want SE concave by default. // Punch using mapped NE delta: NE fill region → clear for concave SE. const delta = cornerDelta(ellNE, fillNE); for (const d of delta) { // Map NE corner (top-right) → SE corner (bottom-right): keep x, flip y. const x = d.x; const y = flipY(d.y); // Only clear / don't apply fill for the concave L. if (d.color[3] > 128) { // Was a fill pixel in 2x2 — ensure concave leaves it empty (or outline). const src = getPx(ellNE, d.x, d.y); setPx(out, x, y, src[3] > 128 ? getPx(east, x, Math.min(12, y)) : [0, 0, 0, 0]); if (src[3] <= 128) { setPx(out, x, y, [0, 0, 0, 0]); } } } return out;}function fillSEFromNE (ellSE, ellNE, fillNE){{ const out = copyRgba(ellSE); mkdirSync(EXAMPLES, { recursive: true }); const delta = cornerDelta(ellNE, fillNE); const legacy = join(ROOT, "stone-wall"); for (const d of delta) if (!existsSync(legacy)) { return; } for (const name of readdirSync(legacy)) { { const x = d.x; if (!name.startsWith("example-") || !name.endsWith(".png")) const y = flipY(d.y); { continue; } if (d.color[3] > 128) const dest = join(EXAMPLES, name); { if (!existsSync(dest)) // Prefer sampling from the SE L's nearby interior. { cpSync(join(legacy, name), dest); } const sample = getPx(ellSE, Math.min(SIZE - 1, Math.max(0, x - 1)), Math.min(SIZE - 1, Math.max(0, y - 1))); setPx(out, x, y, sample[3] > 128 ? sample : d.color); } } } return out;}}function buildPack (kind)function buildPack (kind)@@ -328,34 +258,21 @@ function buildPack (kind) const alone = loadExample(`example-stone-${kind}.png`); const alone = loadExample(`example-stone-${kind}.png`); const east = loadExample(`example-stone-${kind}-connecting.png`); const east = loadExample(`example-stone-${kind}-connecting.png`); const north = loadExample(`example-stone-${kind}-connecting-up.png`); const north = loadExample(`example-stone-${kind}-connecting-up.png`); const southAuthored = loadExample(`example-stone-${kind}-connecting-down.png`); const south = loadExample(`example-stone-${kind}-connecting-down.png`); const ns = loadExample(`example-stone-${kind}-connecting-updown.png`); const ns = loadExample(`example-stone-${kind}-connecting-updown.png`); const ellNE = loadExample(`example-stone-${kind}-connecting-L.png`); const ellNE = loadExample(`example-stone-${kind}-connecting-L.png`); const fillNE = loadExample(`example-stone-${kind}-connecting-2x2.png`); const ellSE = loadExample(`example-stone-${kind}-connecting-Ldownright.png`); const ellSEAuthored = loadExample(`example-stone-${kind}-connecting-Ldownright.png`); const teeESW = loadExample(`example-stone-${kind}-T.png`) const teeESW = loadExample(`example-stone-${kind}-T.png`) ?? loadExample(`example-stone-${kind}-connecting-T.png`); ?? loadExample(`example-stone-${kind}-connecting-T.png`); const teeNEW = loadExample(`example-stone-${kind}-connecting-T-upsidedown.png`); const teeNEW = loadExample(`example-stone-${kind}-connecting-T-upsidedown.png`); if (!alone || !east || !north || !ellNE || !fillNE || !ns) if (!alone || !east || !north || !ns) { throw new Error(`Missing core ${kind} examples`); } { throw new Error(`Missing core ${kind} examples in ${EXAMPLES}`); } const west = mirrorX(east); const west = mirrorX(east); const southFinal = southAuthored ?? (() => const southFinal = south ?? (() => { { // No authored south: alone top + updown shaft through the bottom. const out = copyRgba(alone); const out = copyRgba(alone); for (let y = 0; y < SIZE; y++) { for (let x = 0; x < SIZE; x++) { if (y < 2 && opaque(alone, x, y)) { continue; } if (opaque(ns, x, y)) { setPx(out, x, y, getPx(ns, x, y)); } } } // Ensure bottom rows are open shaft from updown. for (let y = 10; y < SIZE; y++) for (let y = 10; y < SIZE; y++) { { for (let x = 0; x < SIZE; x++) for (let x = 0; x < SIZE; x++)@@ -367,45 +284,46 @@ function buildPack (kind) return out; return out; })(); })(); const ellSEFinal = ellSEAuthored ?? composeSEFromNE(ellNE, fillNE, east, southFinal); const ellNEFinal = ellNE ?? (() => const fillSE = fillSEFromNE(ellSEFinal, ellNE, fillNE); { const out = clearRgba(); const ellNW = mirrorX(ellNE); blit(out, north); const fillNW = mirrorX(fillNE); blit(out, east); return out; })(); const ellSEFinal = ellSE ?? (() => { const out = clearRgba(); blit(out, southFinal); blit(out, east); return out; })(); const ellNW = mirrorX(ellNEFinal); const ellSW = mirrorX(ellSEFinal); const ellSW = mirrorX(ellSEFinal); const fillSW = mirrorX(fillSE); const ew = (() => const ew = (() => { { const out = clearRgba(); const out = clearRgba(); blit(out, east); blit(out, east); blit(out, west); blit(out, west); // Close the center seam: fill any gap on rows that both sides use. for (let y = 0; y < SIZE; y++) for (let y = 0; y < SIZE; y++) { { if (!opaque(east, SIZE - 1, y)) { continue; } let fill = null; let fill = null; for (let x = 0; x < SIZE; x++) for (let x = SIZE - 1; x >= 0; x--) { { const c = getPx(east, x, y); const c = getPx(east, x, y); if (c[3] > 128) if (c[3] > 128) { fill = c; } { fill = c; break; } } } if (!fill) if (!fill) { continue; } { continue; } for (let x = 0; x < SIZE; x++) for (let x = 0; x < SIZE; x++) { { if (!opaque(out, x, y) && (opaque(east, SIZE - 1, y) || opaque(west, 0, y))) if (!opaque(out, x, y)) { setPx(out, x, y, fill); } { setPx(out, x, y, fill); } } } // Force full row when east template opens to the edge on this row. if (opaque(east, SIZE - 1, y)) { for (let x = 0; x < SIZE; x++) { if (!opaque(out, x, y)) { setPx(out, x, y, fill); } } } } } return out; return out; })(); })();@@ -433,119 +351,34 @@ function buildPack (kind) return out; return out; })(); })(); const teeNWS = mirrorX(teeNES); const teeNWS = mirrorX(teeNES); const all = (() => /** Exact mask → rgba for authored / derived cardinal templates (no diagonals). */ const byMask = new Map(); byMask.set(0, alone); byMask.set(NeighborBit.n, north); byMask.set(NeighborBit.e, east); byMask.set(NeighborBit.s, southFinal); byMask.set(NeighborBit.w, west); byMask.set(NeighborBit.n | NeighborBit.s, ns); byMask.set(NeighborBit.e | NeighborBit.w, ew); byMask.set(NeighborBit.n | NeighborBit.e, ellNE); byMask.set(NeighborBit.n | NeighborBit.w, ellNW); byMask.set(NeighborBit.s | NeighborBit.e, ellSEFinal); byMask.set(NeighborBit.s | NeighborBit.w, ellSW); byMask.set(NeighborBit.e | NeighborBit.s | NeighborBit.w, teeESWFinal); byMask.set(NeighborBit.n | NeighborBit.e | NeighborBit.w, teeNEWFinal); byMask.set(NeighborBit.n | NeighborBit.e | NeighborBit.s, teeNES); byMask.set(NeighborBit.n | NeighborBit.w | NeighborBit.s, teeNWS); byMask.set( NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w, (() => { const out = clearRgba(); blit(out, ns); blit(out, ew); blit(out, teeESWFinal); blit(out, teeNEWFinal); return out; })() ); // Filled-corner variants for the primary L corners. byMask.set(NeighborBit.n | NeighborBit.e | NeighborBit.ne, fillNE); byMask.set(NeighborBit.n | NeighborBit.w | NeighborBit.nw, fillNW); byMask.set(NeighborBit.s | NeighborBit.e | NeighborBit.se, fillSE); byMask.set(NeighborBit.s | NeighborBit.w | NeighborBit.sw, fillSW); const neDelta = cornerDelta(ellNE, fillNE); const nwDelta = cornerDelta(ellNW, fillNW); const seDelta = cornerDelta(ellSEFinal, fillSE); const swDelta = cornerDelta(ellSW, fillSW); return { byMask, neDelta, nwDelta, seDelta, swDelta, alone, east, west, north, south: southFinal, ns, ew, ellNE, fillNE };}function paintMask (mask, pack){ const n = (mask & NeighborBit.n) !== 0; const e = (mask & NeighborBit.e) !== 0; const s = (mask & NeighborBit.s) !== 0; const w = (mask & NeighborBit.w) !== 0; const ne = (mask & NeighborBit.ne) !== 0; const se = (mask & NeighborBit.se) !== 0; const sw = (mask & NeighborBit.sw) !== 0; const nw = (mask & NeighborBit.nw) !== 0; const cardinal = (n ? NeighborBit.n : 0) | (e ? NeighborBit.e : 0) | (s ? NeighborBit.s : 0) | (w ? NeighborBit.w : 0); // Exact hit (including known filled corners). if (pack.byMask.has(mask)) { return copyRgba(pack.byMask.get(mask)); } // Start from cardinal-only template, then apply diagonal fills. let out; if (pack.byMask.has(cardinal)) { out = copyRgba(pack.byMask.get(cardinal)); } else { { out = clearRgba(); const out = clearRgba(); if (n) blit(out, ns); { blit(out, pack.north); } blit(out, ew); if (s) return out; { blit(out, pack.south); } })(); if (e) { blit(out, pack.east); } if (w) { blit(out, pack.west); } if (n && s) { blit(out, pack.ns); } if (e && w) { blit(out, pack.ew); } } if (n && e && ne) const byMask = new Map([ { applyDelta(out, pack.neDelta, idX, idY); } [0, alone], if (n && w && nw) [NeighborBit.n, north], { applyDelta(out, pack.nwDelta, idX, idY); } [NeighborBit.e, east], if (s && e && se) [NeighborBit.s, southFinal], { applyDelta(out, pack.seDelta, idX, idY); } [NeighborBit.w, west], if (s && w && sw) [NeighborBit.n | NeighborBit.s, ns], { applyDelta(out, pack.swDelta, idX, idY); } [NeighborBit.e | NeighborBit.w, ew], [NeighborBit.n | NeighborBit.e, ellNEFinal], // When diagonal is absent but cardinal template accidentally included fill, [NeighborBit.e | NeighborBit.s, ellSEFinal], // strip using inverse delta (already concave templates are used for cardinal). [NeighborBit.s | NeighborBit.w, ellSW], return out; [NeighborBit.w | NeighborBit.n, ellNW], [NeighborBit.e | NeighborBit.s | NeighborBit.w, teeESWFinal], [NeighborBit.w | NeighborBit.n | NeighborBit.e, teeNEWFinal], [NeighborBit.n | NeighborBit.e | NeighborBit.s, teeNES], [NeighborBit.n | NeighborBit.w | NeighborBit.s, teeNWS], [NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w, all] ]); return { byMask, alone, east, north, ns, ellNE: ellNEFinal };}}function clearGenerated (dir)function clearGenerated (dir)@@ -553,48 +386,59 @@ function clearGenerated (dir) mkdirSync(dir, { recursive: true }); mkdirSync(dir, { recursive: true }); for (const name of readdirSync(dir)) for (const name of readdirSync(dir)) { { if (!/^\d+\.png$/i.test(name)) if (!name.endsWith(".png") || name.startsWith("example")) { continue; } { continue; } unlinkSync(join(dir, name)); unlinkSync(join(dir, name)); } }}}function writeSet (dir, pack, label)function writeSet (dir, def, pack){{ clearGenerated(dir); clearGenerated(dir); const masks = listValidNeighborConnectCornerMasks(); for (let mask = 0; mask < 16; mask++) for (const mask of masks) { const rgba = pack.byMask.get(mask); if (!rgba) { throw new Error(`Missing mask ${mask} for ${def.key}`); } const state = composeNamedNeighborConnectState(def, mask); writeFileSync(join(dir, `${state}.png`), encodePng(rgba)); } console.log(`Wrote 16 ${def.key} sprites → ${dir}`);}function removeLegacyFolders (){ for (const name of ["stone-wall", "stone-wall-thin"]) { { writeFileSync(join(dir, `${mask}.png`), encodePng(paintMask(mask, pack))); const dir = join(ROOT, name); if (!existsSync(dir)) { continue; } // Keep examples only in _examples/; remove entire legacy folder. rmSync(dir, { recursive: true, force: true }); console.log(`Removed legacy ${name}/`); } } console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);}}ensureExamples();const thin = buildPack("thin");const thick = buildPack("thick");function assertSame (a, b, label)function assertSame (a, b, label){{ for (let i = 0; i < a.length; i++) for (let i = 0; i < a.length; i++) { { if (a[i] !== b[i]) if (a[i] !== b[i]) { throw new Error(`Mismatch ${label} @${i}: ${a[i]}≠${b[i]}`); } { throw new Error(`Mismatch ${label}`); } } }}}assertSame(thin.byMask.get(0), thin.alone, "thin alone");assertSame(thin.byMask.get(1), thin.north, "thin n");assertSame(thin.byMask.get(2), thin.east, "thin e");assertSame(thin.byMask.get(5), thin.ns, "thin ns");assertSame(thick.byMask.get(0), thick.alone, "thick alone");const thin = buildPack("thin");writeSet(OUT_THIN, THIN, thin);const thick = buildPack("thick");writeSet(OUT_THICK, THICK, thick);removeLegacyFolders();assertSame(paintMask(0, thin), thin.alone, "thin/0");console.log("Suffixes:", [...Array(16)].map((_, m) => `${m}=${cardinalConnectionSuffix(m) || "(alone)"}`).join(", "));assertSame(paintMask(1, thin), thin.north, "thin/1");assertSame(paintMask(2, thin), thin.east, "thin/2");assertSame(paintMask(3, thin), thin.ellNE, "thin/3");assertSame(paintMask(5, thin), thin.ns, "thin/5");assertSame(paintMask(19, thin), thin.fillNE, "thin/19");assertSame(paintMask(0, thick), thick.alone, "thick/0");assertSame(paintMask(1, thick), thick.north, "thick/1");assertSame(paintMask(2, thick), thick.east, "thick/2");assertSame(paintMask(3, thick), thick.ellNE, "thick/3");assertSame(paintMask(5, thick), thick.ns, "thick/5");assertSame(paintMask(19, thick), thick.fillNE, "thick/19");writeSet(OUT_THIN, thin, "thin");writeSet(OUT_THICK, thick, "thick");console.log("All authored core templates verified.");@@ -26,7 +26,6 @@ import
computeNeighborConnectMask,
composeNeighborConnectState,
definitionUsesNeighborConnect,
definitionUsesNeighborConnectCorners,
neighborConnectBlocksMatch,
neighborConnectRefreshTiles,
worldTileToChunkLocal
@@ -668,10 +667,9 @@ function refreshNeighborConnect (localX, localY, typeId)
const def = BLOCK_DEFINITIONS[typeId];
if (!draft || !definitionUsesNeighborConnect(def))
{ return; }
const corners = definitionUsesNeighborConnectCorners(def);
const originTileX = chunkX * CHUNK_SIZE + localX;
const originTileY = chunkY * CHUNK_SIZE + localY;
for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY, { corners }))
for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY))
{
const block = blockAtWorld(tileX, tileY);
if (!block || block.typeId !== typeId)
@@ -680,7 +678,7 @@ function refreshNeighborConnect (localX, localY, typeId)
{
const neighbor = blockAtWorld(tileX + dx, tileY + dy);
return neighborConnectBlocksMatch(block, neighbor, def);
}, { corners });
});
const nextState = composeNeighborConnectState(def, block.state, mask);
if (block.state === nextState)
{ continue; }
@@ -26,7 +26,6 @@ import computeNeighborConnectMask, computeNeighborConnectMask, composeNeighborConnectState, composeNeighborConnectState, definitionUsesNeighborConnect, definitionUsesNeighborConnect, definitionUsesNeighborConnectCorners, neighborConnectBlocksMatch, neighborConnectBlocksMatch, neighborConnectRefreshTiles, neighborConnectRefreshTiles, worldTileToChunkLocal worldTileToChunkLocal@@ -668,10 +667,9 @@ function refreshNeighborConnect (localX, localY, typeId) const def = BLOCK_DEFINITIONS[typeId]; const def = BLOCK_DEFINITIONS[typeId]; if (!draft || !definitionUsesNeighborConnect(def)) if (!draft || !definitionUsesNeighborConnect(def)) { return; } { return; } const corners = definitionUsesNeighborConnectCorners(def); const originTileX = chunkX * CHUNK_SIZE + localX; const originTileX = chunkX * CHUNK_SIZE + localX; const originTileY = chunkY * CHUNK_SIZE + localY; const originTileY = chunkY * CHUNK_SIZE + localY; for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY, { corners })) for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY)) { { const block = blockAtWorld(tileX, tileY); const block = blockAtWorld(tileX, tileY); if (!block || block.typeId !== typeId) if (!block || block.typeId !== typeId)@@ -680,7 +678,7 @@ function refreshNeighborConnect (localX, localY, typeId) { { const neighbor = blockAtWorld(tileX + dx, tileY + dy); const neighbor = blockAtWorld(tileX + dx, tileY + dy); return neighborConnectBlocksMatch(block, neighbor, def); return neighborConnectBlocksMatch(block, neighbor, def); }, { corners }); }); const nextState = composeNeighborConnectState(def, block.state, mask); const nextState = composeNeighborConnectState(def, block.state, mask); if (block.state === nextState) if (block.state === nextState) { continue; } { continue; }@@ -10,7 +10,9 @@ import {
parseMaterialNeighborConnectState,
worldTileToChunkLocal,
neighborConnectRefreshTiles,
listValidNeighborConnectCornerMasks
cardinalConnectionSuffix,
composeNamedNeighborConnectState,
parseNamedNeighborConnectMask
} from "../../shared/world/neighborConnect.js";
import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";
import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";
@@ -31,26 +33,32 @@ test("neighbor connect masks cover all NESW combinations", () =>
assert.equal(mask, NeighborBit.n | NeighborBit.e);
});
test("corner-aware neighbor connect sets diagonals only with both cardinals", () =>
test("named wall connection suffixes follow nesw / we / esw / wne", () =>
{
const isL = (dx, dy) => (dx === 1 && dy === 0) || (dx === 0 && dy === 1);
assert.equal(cardinalConnectionSuffix(0), "");
assert.equal(cardinalConnectionSuffix(NeighborBit.e | NeighborBit.w), "we");
assert.equal(cardinalConnectionSuffix(NeighborBit.n | NeighborBit.s), "ns");
assert.equal(
computeNeighborConnectMask(isL, { corners: true }),
NeighborBit.e | NeighborBit.s
cardinalConnectionSuffix(NeighborBit.e | NeighborBit.s | NeighborBit.w),
"esw"
);
const isSolid2x2 = (dx, dy) =>
(dx === 1 && dy === 0)
|| (dx === 0 && dy === 1)
|| (dx === 1 && dy === 1);
assert.equal(
computeNeighborConnectMask(isSolid2x2, { corners: true }),
NeighborBit.e | NeighborBit.s | NeighborBit.se
cardinalConnectionSuffix(NeighborBit.w | NeighborBit.n | NeighborBit.e),
"wne"
);
assert.equal(listValidNeighborConnectCornerMasks().length, 47);
assert.deepEqual(
neighborConnectRefreshTiles(5, 5, { corners: true }).length,
9
assert.equal(
cardinalConnectionSuffix(NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w),
"nesw"
);
const def = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true };
assert.equal(composeNamedNeighborConnectState(def, 0), "thick-stone-wall");
assert.equal(
composeNamedNeighborConnectState(def, NeighborBit.e | NeighborBit.s | NeighborBit.w),
"thick-stone-wall-esw"
);
assert.equal(parseNamedNeighborConnectMask("thick-stone-wall-wne", def), NeighborBit.w | NeighborBit.n | NeighborBit.e);
assert.equal(parseNamedNeighborConnectMask("14", def), 14);
assert.deepEqual(neighborConnectRefreshTiles(15, 8).length, 5);
});
test("material neighbor-connect states keep wood id and only match same material", () =>
@@ -10,7 +10,9 @@ import { parseMaterialNeighborConnectState, parseMaterialNeighborConnectState, worldTileToChunkLocal, worldTileToChunkLocal, neighborConnectRefreshTiles, neighborConnectRefreshTiles, listValidNeighborConnectCornerMasks cardinalConnectionSuffix, composeNamedNeighborConnectState, parseNamedNeighborConnectMask} from "../../shared/world/neighborConnect.js";} from "../../shared/world/neighborConnect.js";import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";@@ -31,26 +33,32 @@ test("neighbor connect masks cover all NESW combinations", () => assert.equal(mask, NeighborBit.n | NeighborBit.e); assert.equal(mask, NeighborBit.n | NeighborBit.e);});});test("corner-aware neighbor connect sets diagonals only with both cardinals", () =>test("named wall connection suffixes follow nesw / we / esw / wne", () =>{{ const isL = (dx, dy) => (dx === 1 && dy === 0) || (dx === 0 && dy === 1); assert.equal(cardinalConnectionSuffix(0), ""); assert.equal(cardinalConnectionSuffix(NeighborBit.e | NeighborBit.w), "we"); assert.equal(cardinalConnectionSuffix(NeighborBit.n | NeighborBit.s), "ns"); assert.equal( assert.equal( computeNeighborConnectMask(isL, { corners: true }), cardinalConnectionSuffix(NeighborBit.e | NeighborBit.s | NeighborBit.w), NeighborBit.e | NeighborBit.s "esw" ); ); const isSolid2x2 = (dx, dy) => (dx === 1 && dy === 0) || (dx === 0 && dy === 1) || (dx === 1 && dy === 1); assert.equal( assert.equal( computeNeighborConnectMask(isSolid2x2, { corners: true }), cardinalConnectionSuffix(NeighborBit.w | NeighborBit.n | NeighborBit.e), NeighborBit.e | NeighborBit.s | NeighborBit.se "wne" ); ); assert.equal(listValidNeighborConnectCornerMasks().length, 47); assert.equal( assert.deepEqual( cardinalConnectionSuffix(NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w), neighborConnectRefreshTiles(5, 5, { corners: true }).length, "nesw" 9 ); const def = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true }; assert.equal(composeNamedNeighborConnectState(def, 0), "thick-stone-wall"); assert.equal( composeNamedNeighborConnectState(def, NeighborBit.e | NeighborBit.s | NeighborBit.w), "thick-stone-wall-esw" ); ); assert.equal(parseNamedNeighborConnectMask("thick-stone-wall-wne", def), NeighborBit.w | NeighborBit.n | NeighborBit.e); assert.equal(parseNamedNeighborConnectMask("14", def), 14); assert.deepEqual(neighborConnectRefreshTiles(15, 8).length, 5);});});test("material neighbor-connect states keep wood id and only match same material", () =>test("material neighbor-connect states keep wood id and only match same material", () =>@@ -143,8 +143,8 @@ test("catalog exposes seasonal grass and pine-tree states", () =>
assert.equal(catalog.blocks["pine-tree"].defaultState, "summer");
assert.equal(catalog.blocks["pine-tree"].outdoor, true);
assert.equal(catalog.blocks["pine-tree"].seasonal, true);
assert.equal(catalog.blocks["stone-wall"].outdoor, false);
assert.equal(catalog.blocks["stone-wall"].seasonal, false);
assert.equal(catalog.blocks["thick-stone-wall"].outdoor, false);
assert.equal(catalog.blocks["thick-stone-wall"].seasonal, false);
assert.ok(catalog.images.some((image) => image.name === "block:boulder:boulder-winter"));
assert.ok(catalog.images.some((image) => image.name === "block:boulder:copper-ore-winter"));
assert.ok(catalog.images.some((image) => image.url.includes("boulder-ore-winter.png")));
@@ -143,8 +143,8 @@ test("catalog exposes seasonal grass and pine-tree states", () => assert.equal(catalog.blocks["pine-tree"].defaultState, "summer"); assert.equal(catalog.blocks["pine-tree"].defaultState, "summer"); assert.equal(catalog.blocks["pine-tree"].outdoor, true); assert.equal(catalog.blocks["pine-tree"].outdoor, true); assert.equal(catalog.blocks["pine-tree"].seasonal, true); assert.equal(catalog.blocks["pine-tree"].seasonal, true); assert.equal(catalog.blocks["stone-wall"].outdoor, false); assert.equal(catalog.blocks["thick-stone-wall"].outdoor, false); assert.equal(catalog.blocks["stone-wall"].seasonal, false); assert.equal(catalog.blocks["thick-stone-wall"].seasonal, false); assert.ok(catalog.images.some((image) => image.name === "block:boulder:boulder-winter")); assert.ok(catalog.images.some((image) => image.name === "block:boulder:boulder-winter")); assert.ok(catalog.images.some((image) => image.name === "block:boulder:copper-ore-winter")); assert.ok(catalog.images.some((image) => image.name === "block:boulder:copper-ore-winter")); assert.ok(catalog.images.some((image) => image.url.includes("boulder-ore-winter.png"))); assert.ok(catalog.images.some((image) => image.url.includes("boulder-ore-winter.png")));@@ -5,7 +5,7 @@ import { join } from "node:path";
import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
import { cycleState, isCompanionSpriteStem, parseSpriteStem, resolveState } from "../../shared/definitions/tileSprites.js";
import { decodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";
import { GroundType, BlockType, normalizeGround, setBlockVisualState } from "../../shared/definitions/tiles.js";
import { GroundType, BlockType, normalizeGround, normalizeBlock, setBlockVisualState } from "../../shared/definitions/tiles.js";
import { diffChunks } from "../src/editor/service.js";
const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta.url)));
@@ -13,15 +13,15 @@ const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta
test("sprite folders expose alphabetical states; first is default", () =>
{
const catalog = buildSpriteCatalog(ASSET_ROOT);
assert.equal(catalog.blocks["stone-wall"].states.length, 47);
assert.equal(catalog.blocks["stone-wall"].defaultState, "0");
assert.ok(catalog.blocks["stone-wall"].states.includes("15"));
assert.ok(catalog.blocks["stone-wall"].states.includes("38"));
assert.ok(catalog.blocks["stone-wall"].states.includes("255"));
assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:255"));
assert.equal(catalog.blocks["stone-wall-thin"].states.length, 47);
assert.equal(catalog.blocks["stone-wall-thin"].defaultState, "0");
assert.ok(catalog.images.some((image) => image.name === "block:stone-wall-thin:38"));
assert.equal(catalog.blocks["thick-stone-wall"].defaultState, "thick-stone-wall");
assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall"));
assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-esw"));
assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-nesw"));
assert.equal(catalog.blocks["thick-stone-wall"].states.length, 16);
assert.ok(catalog.images.some((image) => image.name === "block:thick-stone-wall:thick-stone-wall-nesw"));
assert.equal(catalog.blocks["thin-stone-wall"].defaultState, "thin-stone-wall");
assert.equal(catalog.blocks["thin-stone-wall"].states.length, 16);
assert.ok(catalog.images.some((image) => image.name === "block:thin-stone-wall:thin-stone-wall-wne"));
assert.equal(catalog.images[0].subImgTotal, 1);
assert.equal(catalog.images[0].perRow, 1);
});
@@ -121,17 +121,26 @@ test("gameplay can set a block visual state", () =>
{
const data = createEmptyChunkData();
data.blocks[0] = { typeId: BlockType.stoneWall, state: null, config: null };
setBlockVisualState(data.blocks[0], "2");
assert.equal(data.blocks[0].state, "2");
setBlockVisualState(data.blocks[0], "thick-stone-wall-e");
assert.equal(data.blocks[0].state, "thick-stone-wall-e");
});
test("chunk diffs mention visual state changes", () =>
{
const previous = createEmptyChunkData();
const next = createEmptyChunkData();
previous.blocks[0] = { typeId: BlockType.stoneWall, state: "1", config: null };
next.blocks[0] = { typeId: BlockType.stoneWall, state: "2", config: null };
previous.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-n", config: null };
next.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-e", config: null };
const bullets = diffChunks(0, 0, previous, next, true);
assert.ok(bullets.some((line) => line.includes("state changed from 1 to 2")));
assert.ok(bullets.some((line) =>
line.includes("state changed from thick-stone-wall-n to thick-stone-wall-e")));
assert.equal(normalizeGround(GroundType.grass).typeId, GroundType.grass);
});
test("normalizeBlock migrates legacy numeric wall states to named suffixes", () =>
{
const migrated = normalizeBlock({ typeId: BlockType.stoneWall, state: "14", config: null });
assert.equal(migrated.state, "thick-stone-wall-esw");
const alone = normalizeBlock({ typeId: BlockType.stoneWallThin, state: "0", config: null });
assert.equal(alone.state, "thin-stone-wall");
});
@@ -5,7 +5,7 @@ import { join } from "node:path";import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";import { cycleState, isCompanionSpriteStem, parseSpriteStem, resolveState } from "../../shared/definitions/tileSprites.js";import { cycleState, isCompanionSpriteStem, parseSpriteStem, resolveState } from "../../shared/definitions/tileSprites.js";import { decodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";import { decodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";import { GroundType, BlockType, normalizeGround, setBlockVisualState } from "../../shared/definitions/tiles.js";import { GroundType, BlockType, normalizeGround, normalizeBlock, setBlockVisualState } from "../../shared/definitions/tiles.js";import { diffChunks } from "../src/editor/service.js";import { diffChunks } from "../src/editor/service.js";const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta.url)));const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta.url)));@@ -13,15 +13,15 @@ const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.metatest("sprite folders expose alphabetical states; first is default", () =>test("sprite folders expose alphabetical states; first is default", () =>{{ const catalog = buildSpriteCatalog(ASSET_ROOT); const catalog = buildSpriteCatalog(ASSET_ROOT); assert.equal(catalog.blocks["stone-wall"].states.length, 47); assert.equal(catalog.blocks["thick-stone-wall"].defaultState, "thick-stone-wall"); assert.equal(catalog.blocks["stone-wall"].defaultState, "0"); assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall")); assert.ok(catalog.blocks["stone-wall"].states.includes("15")); assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-esw")); assert.ok(catalog.blocks["stone-wall"].states.includes("38")); assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-nesw")); assert.ok(catalog.blocks["stone-wall"].states.includes("255")); assert.equal(catalog.blocks["thick-stone-wall"].states.length, 16); assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:255")); assert.ok(catalog.images.some((image) => image.name === "block:thick-stone-wall:thick-stone-wall-nesw")); assert.equal(catalog.blocks["stone-wall-thin"].states.length, 47); assert.equal(catalog.blocks["thin-stone-wall"].defaultState, "thin-stone-wall"); assert.equal(catalog.blocks["stone-wall-thin"].defaultState, "0"); assert.equal(catalog.blocks["thin-stone-wall"].states.length, 16); assert.ok(catalog.images.some((image) => image.name === "block:stone-wall-thin:38")); assert.ok(catalog.images.some((image) => image.name === "block:thin-stone-wall:thin-stone-wall-wne")); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].perRow, 1); assert.equal(catalog.images[0].perRow, 1);});});@@ -121,17 +121,26 @@ test("gameplay can set a block visual state", () =>{{ const data = createEmptyChunkData(); const data = createEmptyChunkData(); data.blocks[0] = { typeId: BlockType.stoneWall, state: null, config: null }; data.blocks[0] = { typeId: BlockType.stoneWall, state: null, config: null }; setBlockVisualState(data.blocks[0], "2"); setBlockVisualState(data.blocks[0], "thick-stone-wall-e"); assert.equal(data.blocks[0].state, "2"); assert.equal(data.blocks[0].state, "thick-stone-wall-e");});});test("chunk diffs mention visual state changes", () =>test("chunk diffs mention visual state changes", () =>{{ const previous = createEmptyChunkData(); const previous = createEmptyChunkData(); const next = createEmptyChunkData(); const next = createEmptyChunkData(); previous.blocks[0] = { typeId: BlockType.stoneWall, state: "1", config: null }; previous.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-n", config: null }; next.blocks[0] = { typeId: BlockType.stoneWall, state: "2", config: null }; next.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-e", config: null }; const bullets = diffChunks(0, 0, previous, next, true); const bullets = diffChunks(0, 0, previous, next, true); assert.ok(bullets.some((line) => line.includes("state changed from 1 to 2"))); assert.ok(bullets.some((line) => line.includes("state changed from thick-stone-wall-n to thick-stone-wall-e"))); assert.equal(normalizeGround(GroundType.grass).typeId, GroundType.grass); assert.equal(normalizeGround(GroundType.grass).typeId, GroundType.grass);});});test("normalizeBlock migrates legacy numeric wall states to named suffixes", () =>{ const migrated = normalizeBlock({ typeId: BlockType.stoneWall, state: "14", config: null }); assert.equal(migrated.state, "thick-stone-wall-esw"); const alone = normalizeBlock({ typeId: BlockType.stoneWallThin, state: "0", config: null }); assert.equal(alone.state, "thin-stone-wall");});