Rebuild wall sprites from the expanded example set.
Map authored alone/E/N/S/NS/L/T/2×2 templates directly to masks and mirror for west; keep shapes flat (no texture).
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.
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.
@@ -2,18 +2,25 @@
* Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
* (cardinals + diagonal corners — 47 valid states).
*
* Authoritative shape examples (no texture — flat greys only):
* example-stone-{thin|thick}.png alone
* example-stone-{thin|thick}-connecting.png east
* example-stone-{thin|thick}-connecting-up.png north
* example-stone-{thin|thick}-connecting-L.png north+east (concave)
* example-stone-{thin|thick}-connecting-2x2.png north+east+NE (filled)
* 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)
*
* Other directions are mirrors / south extrusions of those rules.
* West variants are X-mirrors. Remaining masks compose from these stamps +
* the L↔2×2 corner-fill delta.
*
* node client/scripts/generate-stone-wall-sprites.mjs
*/
import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from "node:fs";
import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync, existsSync } from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
@@ -159,6 +166,14 @@ function decodePngRgba (path)
return rgba;
}
function loadExample (name)
{
const path = join(EXAMPLES, name);
if (!existsSync(path))
{ return null; }
return decodePngRgba(path);
}
function getPx (rgba, x, y)
{
if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
@@ -204,9 +219,10 @@ function mirrorX (rgba)
return out;
}
/** Stamp every opaque pixel from src onto dst (src wins). */
function blit (dst, src)
{
if (!src)
{ return; }
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
@@ -218,12 +234,10 @@ function blit (dst, src)
}
}
/**
* Where `filled` is opaque and `concave` is not (or differs), copy `filled`.
* Used to turn an L template into a 2×2 corner by applying the NE fill.
*/
function applyCornerFill (dst, concave, filled)
/** 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++)
@@ -231,336 +245,306 @@ function applyCornerFill (dst, concave, filled)
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]))
{ setPx(dst, x, y, b); }
{ 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;
}
/**
* Where `filled` differs from `concave`, clear dst back toward concave
* (remove corner fill — used when diagonal bit is absent).
*/
function stripCornerFill (dst, concave, filled)
function applyDelta (dst, deltas, mapX, mapY)
{
for (let y = 0; y < SIZE; y++)
for (const d of deltas)
{
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]))
{ setPx(dst, x, y, a); }
}
const x = mapX(d.x);
const y = mapY(d.y);
setPx(dst, x, y, d.color);
}
}
function decodeMask (mask)
{
return {
n: (mask & NeighborBit.n) !== 0,
e: (mask & NeighborBit.e) !== 0,
s: (mask & NeighborBit.s) !== 0,
w: (mask & NeighborBit.w) !== 0,
ne: (mask & NeighborBit.ne) !== 0,
se: (mask & NeighborBit.se) !== 0,
sw: (mask & NeighborBit.sw) !== 0,
nw: (mask & NeighborBit.nw) !== 0
};
}
function idX (x)
{ return x; }
function idY (y)
{ return y; }
function flipX (x)
{ return SIZE - 1 - x; }
function flipY (y)
{ return SIZE - 1 - y; }
/**
* South-only: alone silhouette with the body columns extended to y=15
* (mirror of how up opens the top while keeping the bottom face).
* 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 makeSouth (alone, up)
function composeSEFromNE (ellNE, fillNE, east, south)
{
const out = copyRgba(alone);
for (let y = 0; y < SIZE; y++)
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)
{
for (let x = 0; x < SIZE; x++)
// 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)
{
if (y <= 12)
{ continue; }
// Extend columns that belong to the vertical shaft (up body width).
if (!opaque(up, x, 12))
{ continue; }
setPx(out, x, y, getPx(alone, x, 12));
// 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;
}
/**
* North+south shaft: up template opened through the bottom as well.
*/
function makeNS (up, south)
function fillSEFromNE (ellSE, ellNE, fillNE)
{
const out = copyRgba(up);
for (let y = 13; y < SIZE; y++)
const out = copyRgba(ellSE);
const delta = cornerDelta(ellNE, fillNE);
for (const d of delta)
{
for (let x = 0; x < SIZE; x++)
const x = d.x;
const y = flipY(d.y);
if (d.color[3] > 128)
{
if (opaque(south, x, y))
{ setPx(out, x, y, getPx(south, x, y)); }
else if (opaque(up, x, 12))
{ setPx(out, x, y, getPx(up, x, 12)); }
// 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);
}
}
return out;
}
/**
* East+west run: east template with the west side also opened (mirror blend).
*/
function makeEW (east, west)
function buildPack (kind)
{
const out = clearRgba();
for (let y = 0; y < SIZE; y++)
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 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 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`); }
const west = mirrorX(east);
const southFinal = southAuthored ?? (() =>
{
for (let x = 0; x < SIZE; x++)
// No authored south: alone top + updown shaft through the bottom.
const out = copyRgba(alone);
for (let y = 0; y < SIZE; y++)
{
const e = getPx(east, x, y);
const w = getPx(west, x, y);
if (e[3] > 128 && w[3] > 128)
for (let x = 0; x < SIZE; x++)
{
// Prefer interior sample from east beyond the free-end bevels.
setPx(out, x, y, x < 8 ? w : e);
if (y < 2 && opaque(alone, x, y))
{ continue; }
if (opaque(ns, x, y))
{ setPx(out, x, y, getPx(ns, x, y)); }
}
else if (e[3] > 128)
{ setPx(out, x, y, e); }
else if (w[3] > 128)
{ setPx(out, x, y, w); }
}
}
// Ensure full-width rows where either side has the band.
for (let y = 0; y < SIZE; y++)
{
let any = false;
for (let x = 0; x < SIZE; x++)
// Ensure bottom rows are open shaft from updown.
for (let y = 10; y < SIZE; y++)
{
if (opaque(out, x, y))
{ any = true; break; }
}
if (!any)
{ continue; }
// Find a representative interior colour from east.
let fill = null;
for (let x = SIZE - 1; x >= 0; x--)
{
const c = getPx(east, x, y);
if (c[3] > 128)
{ fill = c; break; }
}
if (!fill)
{ continue; }
for (let x = 0; x < SIZE; x++)
{
if (!opaque(out, x, y))
{ setPx(out, x, y, fill); }
for (let x = 0; x < SIZE; x++)
{
if (opaque(ns, x, y))
{ setPx(out, x, y, getPx(ns, x, y)); }
}
}
}
return out;
}
return out;
})();
const ellSEFinal = ellSEAuthored ?? composeSEFromNE(ellNE, fillNE, east, southFinal);
const fillSE = fillSEFromNE(ellSEFinal, ellNE, fillNE);
/**
* Build one wall variant's template pack from the five authored examples.
*/
function buildPack (prefix)
{
const alone = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}.png`));
const east = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting.png`));
const north = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-up.png`));
const ellNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-L.png`));
const fillNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-2x2.png`));
const west = mirrorX(east);
const south = makeSouth(alone, north);
const ellNW = mirrorX(ellNE);
const fillNW = mirrorX(fillNE);
// South-east / south-west L: mirror the north L vertically in occupancy terms
// by compositing south + east with the SE corner left open / filled.
const ellSE = makeCardinalL(south, east, "se");
const fillSE = makeCardinalFill(ellSE, south, east, "se", ellNE, fillNE);
const ellSW = mirrorX(ellSE);
const ellSW = mirrorX(ellSEFinal);
const fillSW = mirrorX(fillSE);
const ns = makeNS(north, south);
const ew = makeEW(east, west);
return {
alone, east, west, north, south, ns, ew,
ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW
};
}
/**
* Compose an L for south+east from south & east templates, leaving SE concave.
* Corner open region is inferred from the NE L vs 2×2 delta, rotated to SE.
*/
function makeCardinalL (vert, horiz, corner)
{
const out = clearRgba();
blit(out, vert);
blit(out, horiz);
// Punch the concave corner using the NE L/2×2 delta mapped to this corner.
return out;
}
function makeCardinalFill (ell, vert, horiz, corner, ellNE, fillNE)
{
const out = copyRgba(ell);
// Map NE fill delta onto the target corner.
for (let y = 0; y < SIZE; y++)
const ew = (() =>
{
for (let x = 0; x < SIZE; x++)
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++)
{
let sx = x;
let sy = y;
if (corner === "se")
let fill = null;
for (let x = 0; x < SIZE; x++)
{
sx = x;
sy = SIZE - 1 - y;
const c = getPx(east, x, y);
if (c[3] > 128)
{ fill = c; }
}
else if (corner === "sw")
{
sx = SIZE - 1 - x;
sy = SIZE - 1 - y;
}
else if (corner === "nw")
if (!fill)
{ continue; }
for (let x = 0; x < SIZE; x++)
{
sx = SIZE - 1 - x;
sy = y;
if (!opaque(out, x, y) && (opaque(east, SIZE - 1, y) || opaque(west, 0, y)))
{ setPx(out, x, y, fill); }
}
const a = getPx(ellNE, sx, sy);
const b = getPx(fillNE, sx, sy);
if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0]))
// Force full row when east template opens to the edge on this row.
if (opaque(east, SIZE - 1, y))
{
// Sample fill colour from the horizontal arm interior.
const sample = getPx(horiz, Math.min(SIZE - 1, x), Math.min(SIZE - 1, Math.max(0, y)));
const col = sample[3] > 128 ? sample : b;
setPx(out, x, y, col);
for (let x = 0; x < SIZE; x++)
{
if (!opaque(out, x, y))
{ setPx(out, x, y, fill); }
}
}
}
}
return out;
return out;
})();
const teeESWFinal = teeESW ?? (() =>
{
const out = clearRgba();
blit(out, ew);
blit(out, southFinal);
return out;
})();
const teeNEWFinal = teeNEW ?? (() =>
{
const out = clearRgba();
blit(out, ew);
blit(out, north);
return out;
})();
const teeNES = (() =>
{
const out = clearRgba();
blit(out, north);
blit(out, east);
blit(out, southFinal);
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
};
}
/**
* Paint one mask by starting from the best base template, then OR-ing extra
* arms and applying / stripping corner fills for each diagonal bit.
*/
function paintMask (mask, pack)
{
const c = decodeMask(mask);
const {
alone, east, west, north, south, ns, ew,
ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW
} = pack;
const n = c.n;
const e = c.e;
const s = c.s;
const w = c.w;
const cardinal = (n ? 1 : 0) + (e ? 1 : 0) + (s ? 1 : 0) + (w ? 1 : 0);
// --- Exact / near-exact authored cases ---
if (cardinal === 0)
{ return copyRgba(alone); }
if (cardinal === 1)
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
{
if (e)
{ return copyRgba(east); }
if (w)
{ return copyRgba(west); }
out = clearRgba();
if (n)
{ return copyRgba(north); }
{ blit(out, pack.north); }
if (s)
{ return copyRgba(south); }
}
// Pure L corners (two adjacent cardinals)
if (cardinal === 2 && n && e && !s && !w)
{ return c.ne ? copyRgba(fillNE) : copyRgba(ellNE); }
if (cardinal === 2 && n && w && !s && !e)
{ return c.nw ? copyRgba(fillNW) : copyRgba(ellNW); }
if (cardinal === 2 && s && e && !n && !w)
{ return c.se ? copyRgba(fillSE) : copyRgba(ellSE); }
if (cardinal === 2 && s && w && !n && !e)
{ return c.sw ? copyRgba(fillSW) : copyRgba(ellSW); }
// Opposite pairs
if (cardinal === 2 && n && s && !e && !w)
{ return copyRgba(ns); }
if (cardinal === 2 && e && w && !n && !s)
{ return copyRgba(ew); }
// --- General compose ---
const out = clearRgba();
// Prefer richer multi-arm templates when available, then blit extras.
if (n && e)
{ blit(out, c.ne ? fillNE : ellNE); }
else if (n && w)
{ blit(out, c.nw ? fillNW : ellNW); }
else if (s && e)
{ blit(out, c.se ? fillSE : ellSE); }
else if (s && w)
{ blit(out, c.sw ? fillSW : ellSW); }
else if (n && s)
{ blit(out, ns); }
else if (e && w)
{ blit(out, ew); }
else if (n)
{ blit(out, north); }
else if (s)
{ blit(out, south); }
else if (e)
{ blit(out, east); }
else if (w)
{ blit(out, west); }
// Add missing opposite / side arms.
if (n)
{ blit(out, north); }
if (s)
{ blit(out, south); }
if (e)
{ blit(out, east); }
if (w)
{ blit(out, west); }
if (n && s)
{ blit(out, ns); }
if (e && w)
{ blit(out, ew); }
// Corner fills / strips for every relevant diagonal.
if (n && e)
{
if (c.ne)
{ applyCornerFill(out, ellNE, fillNE); }
else
{ stripCornerFill(out, ellNE, fillNE); }
}
if (n && w)
{
if (c.nw)
{ applyCornerFill(out, ellNW, fillNW); }
else
{ stripCornerFill(out, ellNW, fillNW); }
}
if (s && e)
{
if (c.se)
{ applyCornerFill(out, ellSE, fillSE); }
else
{ stripCornerFill(out, ellSE, fillSE); }
}
if (s && w)
{
if (c.sw)
{ applyCornerFill(out, ellSW, fillSW); }
else
{ stripCornerFill(out, ellSW, fillSW); }
{ 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)
{ 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;
}
@@ -586,28 +570,31 @@ function writeSet (dir, pack, label)
console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
}
const thin = buildPack("thin");
const thick = buildPack("thick");
// Sanity checks against authored examples
function assertSame (a, b, label)
{
for (let i = 0; i < a.length; i++)
{
if (a[i] !== b[i])
{ throw new Error(`Template mismatch: ${label} at byte ${i}`); }
{ throw new Error(`Mismatch ${label} @${i}: ${a[i]}≠${b[i]}`); }
}
}
assertSame(paintMask(0, thin), thin.alone, "thin alone");
assertSame(paintMask(2, thin), thin.east, "thin east");
assertSame(paintMask(1, thin), thin.north, "thin north");
assertSame(paintMask(3, thin), thin.ellNE, "thin L");
assertSame(paintMask(19, thin), thin.fillNE, "thin 2x2");
assertSame(paintMask(0, thick), thick.alone, "thick alone");
assertSame(paintMask(2, thick), thick.east, "thick east");
assertSame(paintMask(1, thick), thick.north, "thick north");
assertSame(paintMask(3, thick), thick.ellNE, "thick L");
assertSame(paintMask(19, thick), thick.fillNE, "thick 2x2");
const thin = buildPack("thin");
const thick = buildPack("thick");
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.");
@@ -2,18 +2,25 @@ * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks * (cardinals + diagonal corners — 47 valid states). * (cardinals + diagonal corners — 47 valid states). * * * Authoritative shape examples (no texture — flat greys only): * Flat greys only (no texture). Authoritative examples live beside the outputs: * example-stone-{thin|thick}.png alone * example-stone-{thin|thick}.png * example-stone-{thin|thick}-connecting.png east * example-stone-{thin|thick}-connecting.png E * example-stone-{thin|thick}-connecting-up.png north * example-stone-{thin|thick}-connecting-up.png N * example-stone-{thin|thick}-connecting-L.png north+east (concave) * example-stone-thin-connecting-down.png S (thin) * example-stone-{thin|thick}-connecting-2x2.png north+east+NE (filled) * 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) * * * Other directions are mirrors / south extrusions of those rules. * West variants are X-mirrors. Remaining masks compose from these stamps + * the L↔2×2 corner-fill delta. * * * node client/scripts/generate-stone-wall-sprites.mjs * node client/scripts/generate-stone-wall-sprites.mjs */ */import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from "node:fs";import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync, existsSync } 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";@@ -159,6 +166,14 @@ function decodePngRgba (path) return rgba; return rgba;}}function loadExample (name){ const path = join(EXAMPLES, name); if (!existsSync(path)) { return null; } return decodePngRgba(path);}function getPx (rgba, x, y)function getPx (rgba, x, y){{ if (x < 0 || y < 0 || x >= SIZE || y >= SIZE) if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)@@ -204,9 +219,10 @@ function mirrorX (rgba) return out; return out;}}/** Stamp every opaque pixel from src onto dst (src wins). */function blit (dst, src)function blit (dst, src){{ if (!src) { return; } for (let y = 0; y < SIZE; y++) for (let y = 0; y < SIZE; y++) { { for (let x = 0; x < SIZE; x++) for (let x = 0; x < SIZE; x++)@@ -218,12 +234,10 @@ function blit (dst, src) } }}}/**/** Pixels where filled differs from concave (the diagonal corner fill). */ * Where `filled` is opaque and `concave` is not (or differs), copy `filled`.function cornerDelta (concave, filled) * Used to turn an L template into a 2×2 corner by applying the NE fill. */function applyCornerFill (dst, concave, filled){{ const deltas = []; for (let y = 0; y < SIZE; y++) for (let y = 0; y < SIZE; y++) { { for (let x = 0; x < SIZE; x++) for (let x = 0; x < SIZE; x++)@@ -231,336 +245,306 @@ function applyCornerFill (dst, concave, filled) const a = getPx(concave, x, y); const a = getPx(concave, x, y); const b = getPx(filled, 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])) if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2])) { setPx(dst, x, y, b); } { 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) * Where `filled` differs from `concave`, clear dst back toward concave * (remove corner fill — used when diagonal bit is absent). */function stripCornerFill (dst, concave, filled){{ for (let y = 0; y < SIZE; y++) for (const d of deltas) { { for (let x = 0; x < SIZE; x++) const x = mapX(d.x); { const y = mapY(d.y); const a = getPx(concave, x, y); setPx(dst, x, y, d.color); 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])) { setPx(dst, x, y, a); } } } }}}function decodeMask (mask)function idX (x){{ return x; } return {function idY (y) n: (mask & NeighborBit.n) !== 0,{ return y; } e: (mask & NeighborBit.e) !== 0,function flipX (x) s: (mask & NeighborBit.s) !== 0,{ return SIZE - 1 - x; } w: (mask & NeighborBit.w) !== 0,function flipY (y) ne: (mask & NeighborBit.ne) !== 0,{ return SIZE - 1 - y; } se: (mask & NeighborBit.se) !== 0, sw: (mask & NeighborBit.sw) !== 0, nw: (mask & NeighborBit.nw) !== 0 };}/**/** * South-only: alone silhouette with the body columns extended to y=15 * Build south-east L by compositing down+east and punching the SE corner using * (mirror of how up opens the top while keeping the bottom face). * 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 makeSouth (alone, up)function composeSEFromNE (ellNE, fillNE, east, south){{ const out = copyRgba(alone); const out = clearRgba(); for (let y = 0; y < SIZE; y++) 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) { { for (let x = 0; x < SIZE; x++) // 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) { { if (y <= 12) // Was a fill pixel in 2x2 — ensure concave leaves it empty (or outline). { continue; } const src = getPx(ellNE, d.x, d.y); // Extend columns that belong to the vertical shaft (up body width). setPx(out, x, y, src[3] > 128 ? getPx(east, x, Math.min(12, y)) : [0, 0, 0, 0]); if (!opaque(up, x, 12)) if (src[3] <= 128) { continue; } { setPx(out, x, y, [0, 0, 0, 0]); } setPx(out, x, y, getPx(alone, x, 12)); } } } } return out; return out;}}/**function fillSEFromNE (ellSE, ellNE, fillNE) * North+south shaft: up template opened through the bottom as well. */function makeNS (up, south){{ const out = copyRgba(up); const out = copyRgba(ellSE); for (let y = 13; y < SIZE; y++) const delta = cornerDelta(ellNE, fillNE); for (const d of delta) { { for (let x = 0; x < SIZE; x++) const x = d.x; const y = flipY(d.y); if (d.color[3] > 128) { { if (opaque(south, x, y)) // Prefer sampling from the SE L's nearby interior. { setPx(out, x, y, getPx(south, x, y)); } const sample = getPx(ellSE, Math.min(SIZE - 1, Math.max(0, x - 1)), Math.min(SIZE - 1, Math.max(0, y - 1))); else if (opaque(up, x, 12)) setPx(out, x, y, sample[3] > 128 ? sample : d.color); { setPx(out, x, y, getPx(up, x, 12)); } } } } } return out; return out;}}/**function buildPack (kind) * East+west run: east template with the west side also opened (mirror blend). */function makeEW (east, west){{ const out = clearRgba(); const alone = loadExample(`example-stone-${kind}.png`); for (let y = 0; y < SIZE; y++) 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 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 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`); } const west = mirrorX(east); const southFinal = southAuthored ?? (() => { { for (let x = 0; x < SIZE; x++) // No authored south: alone top + updown shaft through the bottom. const out = copyRgba(alone); for (let y = 0; y < SIZE; y++) { { const e = getPx(east, x, y); for (let x = 0; x < SIZE; x++) const w = getPx(west, x, y); if (e[3] > 128 && w[3] > 128) { { // Prefer interior sample from east beyond the free-end bevels. if (y < 2 && opaque(alone, x, y)) setPx(out, x, y, x < 8 ? w : e); { continue; } if (opaque(ns, x, y)) { setPx(out, x, y, getPx(ns, x, y)); } } } else if (e[3] > 128) { setPx(out, x, y, e); } else if (w[3] > 128) { setPx(out, x, y, w); } } } } // Ensure bottom rows are open shaft from updown. // Ensure full-width rows where either side has the band. for (let y = 10; y < SIZE; y++) for (let y = 0; y < SIZE; y++) { let any = false; for (let x = 0; x < SIZE; x++) { { if (opaque(out, x, y)) for (let x = 0; x < SIZE; x++) { any = true; break; } { } if (opaque(ns, x, y)) if (!any) { setPx(out, x, y, getPx(ns, x, y)); } { continue; } } // Find a representative interior colour from east. let fill = null; for (let x = SIZE - 1; x >= 0; x--) { const c = getPx(east, x, y); if (c[3] > 128) { fill = c; break; } } if (!fill) { continue; } for (let x = 0; x < SIZE; x++) { if (!opaque(out, x, y)) { setPx(out, x, y, fill); } } } } return out; return out; })();} const ellSEFinal = ellSEAuthored ?? composeSEFromNE(ellNE, fillNE, east, southFinal); const fillSE = fillSEFromNE(ellSEFinal, ellNE, fillNE);/** * Build one wall variant's template pack from the five authored examples. */function buildPack (prefix){ const alone = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}.png`)); const east = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting.png`)); const north = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-up.png`)); const ellNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-L.png`)); const fillNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-2x2.png`)); const west = mirrorX(east); const south = makeSouth(alone, north); const ellNW = mirrorX(ellNE); const ellNW = mirrorX(ellNE); const fillNW = mirrorX(fillNE); const fillNW = mirrorX(fillNE); // South-east / south-west L: mirror the north L vertically in occupancy terms const ellSW = mirrorX(ellSEFinal); // by compositing south + east with the SE corner left open / filled. const ellSE = makeCardinalL(south, east, "se"); const fillSE = makeCardinalFill(ellSE, south, east, "se", ellNE, fillNE); const ellSW = mirrorX(ellSE); const fillSW = mirrorX(fillSE); const fillSW = mirrorX(fillSE); const ns = makeNS(north, south); const ew = makeEW(east, west); return { alone, east, west, north, south, ns, ew, ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW };}/** * Compose an L for south+east from south & east templates, leaving SE concave. * Corner open region is inferred from the NE L vs 2×2 delta, rotated to SE. */function makeCardinalL (vert, horiz, corner){ const out = clearRgba(); blit(out, vert); blit(out, horiz); // Punch the concave corner using the NE L/2×2 delta mapped to this corner. return out;}function makeCardinalFill (ell, vert, horiz, corner, ellNE, fillNE) const ew = (() =>{ const out = copyRgba(ell); // Map NE fill delta onto the target corner. for (let y = 0; y < SIZE; y++) { { for (let x = 0; x < SIZE; x++) 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++) { { let sx = x; let fill = null; let sy = y; for (let x = 0; x < SIZE; x++) if (corner === "se") { { sx = x; const c = getPx(east, x, y); sy = SIZE - 1 - y; if (c[3] > 128) { fill = c; } } } else if (corner === "sw") if (!fill) { { continue; } sx = SIZE - 1 - x; for (let x = 0; x < SIZE; x++) sy = SIZE - 1 - y; } else if (corner === "nw") { { sx = SIZE - 1 - x; if (!opaque(out, x, y) && (opaque(east, SIZE - 1, y) || opaque(west, 0, y))) sy = y; { setPx(out, x, y, fill); } } } const a = getPx(ellNE, sx, sy); // Force full row when east template opens to the edge on this row. const b = getPx(fillNE, sx, sy); if (opaque(east, SIZE - 1, y)) if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0])) { { // Sample fill colour from the horizontal arm interior. for (let x = 0; x < SIZE; x++) const sample = getPx(horiz, Math.min(SIZE - 1, x), Math.min(SIZE - 1, Math.max(0, y))); { const col = sample[3] > 128 ? sample : b; if (!opaque(out, x, y)) setPx(out, x, y, col); { setPx(out, x, y, fill); } } } } } } } return out; return out; })(); const teeESWFinal = teeESW ?? (() => { const out = clearRgba(); blit(out, ew); blit(out, southFinal); return out; })(); const teeNEWFinal = teeNEW ?? (() => { const out = clearRgba(); blit(out, ew); blit(out, north); return out; })(); const teeNES = (() => { const out = clearRgba(); blit(out, north); blit(out, east); blit(out, southFinal); 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 };}}/** * Paint one mask by starting from the best base template, then OR-ing extra * arms and applying / stripping corner fills for each diagonal bit. */function paintMask (mask, pack)function paintMask (mask, pack){{ const c = decodeMask(mask); const n = (mask & NeighborBit.n) !== 0; const { const e = (mask & NeighborBit.e) !== 0; alone, east, west, north, south, ns, ew, const s = (mask & NeighborBit.s) !== 0; ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW const w = (mask & NeighborBit.w) !== 0; } = pack; const ne = (mask & NeighborBit.ne) !== 0; const se = (mask & NeighborBit.se) !== 0; const n = c.n; const sw = (mask & NeighborBit.sw) !== 0; const e = c.e; const nw = (mask & NeighborBit.nw) !== 0; const s = c.s; const w = c.w; const cardinal = (n ? NeighborBit.n : 0) const cardinal = (n ? 1 : 0) + (e ? 1 : 0) + (s ? 1 : 0) + (w ? 1 : 0); | (e ? NeighborBit.e : 0) | (s ? NeighborBit.s : 0) // --- Exact / near-exact authored cases --- | (w ? NeighborBit.w : 0); if (cardinal === 0) { return copyRgba(alone); } // Exact hit (including known filled corners). if (cardinal === 1) 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 { { if (e) out = clearRgba(); { return copyRgba(east); } if (w) { return copyRgba(west); } if (n) if (n) { return copyRgba(north); } { blit(out, pack.north); } if (s) if (s) { return copyRgba(south); } { blit(out, pack.south); } } if (e) { blit(out, pack.east); } // Pure L corners (two adjacent cardinals) if (w) if (cardinal === 2 && n && e && !s && !w) { blit(out, pack.west); } { return c.ne ? copyRgba(fillNE) : copyRgba(ellNE); } if (n && s) if (cardinal === 2 && n && w && !s && !e) { blit(out, pack.ns); } { return c.nw ? copyRgba(fillNW) : copyRgba(ellNW); } if (e && w) if (cardinal === 2 && s && e && !n && !w) { blit(out, pack.ew); } { return c.se ? copyRgba(fillSE) : copyRgba(ellSE); } if (cardinal === 2 && s && w && !n && !e) { return c.sw ? copyRgba(fillSW) : copyRgba(ellSW); } // Opposite pairs if (cardinal === 2 && n && s && !e && !w) { return copyRgba(ns); } if (cardinal === 2 && e && w && !n && !s) { return copyRgba(ew); } // --- General compose --- const out = clearRgba(); // Prefer richer multi-arm templates when available, then blit extras. if (n && e) { blit(out, c.ne ? fillNE : ellNE); } else if (n && w) { blit(out, c.nw ? fillNW : ellNW); } else if (s && e) { blit(out, c.se ? fillSE : ellSE); } else if (s && w) { blit(out, c.sw ? fillSW : ellSW); } else if (n && s) { blit(out, ns); } else if (e && w) { blit(out, ew); } else if (n) { blit(out, north); } else if (s) { blit(out, south); } else if (e) { blit(out, east); } else if (w) { blit(out, west); } // Add missing opposite / side arms. if (n) { blit(out, north); } if (s) { blit(out, south); } if (e) { blit(out, east); } if (w) { blit(out, west); } if (n && s) { blit(out, ns); } if (e && w) { blit(out, ew); } // Corner fills / strips for every relevant diagonal. if (n && e) { if (c.ne) { applyCornerFill(out, ellNE, fillNE); } else { stripCornerFill(out, ellNE, fillNE); } } if (n && w) { if (c.nw) { applyCornerFill(out, ellNW, fillNW); } else { stripCornerFill(out, ellNW, fillNW); } } if (s && e) { if (c.se) { applyCornerFill(out, ellSE, fillSE); } else { stripCornerFill(out, ellSE, fillSE); } } if (s && w) { if (c.sw) { applyCornerFill(out, ellSW, fillSW); } else { stripCornerFill(out, ellSW, fillSW); } } } 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; return out;}}@@ -586,28 +570,31 @@ function writeSet (dir, pack, label) console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`); console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);}}const thin = buildPack("thin");const thick = buildPack("thick");// Sanity checks against authored examplesfunction 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(`Template mismatch: ${label} at byte ${i}`); } { throw new Error(`Mismatch ${label} @${i}: ${a[i]}≠${b[i]}`); } } }}}assertSame(paintMask(0, thin), thin.alone, "thin alone");assertSame(paintMask(2, thin), thin.east, "thin east");const thin = buildPack("thin");assertSame(paintMask(1, thin), thin.north, "thin north");const thick = buildPack("thick");assertSame(paintMask(3, thin), thin.ellNE, "thin L");assertSame(paintMask(19, thin), thin.fillNE, "thin 2x2");assertSame(paintMask(0, thin), thin.alone, "thin/0");assertSame(paintMask(0, thick), thick.alone, "thick alone");assertSame(paintMask(1, thin), thin.north, "thin/1");assertSame(paintMask(2, thick), thick.east, "thick east");assertSame(paintMask(2, thin), thin.east, "thin/2");assertSame(paintMask(1, thick), thick.north, "thick north");assertSame(paintMask(3, thin), thin.ellNE, "thin/3");assertSame(paintMask(3, thick), thick.ellNE, "thick L");assertSame(paintMask(5, thin), thin.ns, "thin/5");assertSame(paintMask(19, thick), thick.fillNE, "thick 2x2");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_THIN, thin, "thin");writeSet(OUT_THICK, thick, "thick");writeSet(OUT_THICK, thick, "thick");console.log("All authored core templates verified.");