Fix vertical stone-wall joins using up/L/2x2 examples.
North uses the authored shaft width, L keeps the concave inner corner, and the 2x2 template fills that corner; no procedural texture yet.
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.
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,14 +2,14 @@
* Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
* (cardinals + diagonal corners — 47 valid states).
*
* Shape sources (authoritative):
* example-stone-thin.png / example-stone-thin-connecting.png
* example-stone-thick.png / example-stone-thick-connecting.png
* 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)
*
* Alone = free-standing frustum / bevelled block.
* *-connecting = same bands extruded to the east edge (free west end kept).
* Other directions are mirrors / vertical extrusions of that rule.
* Diagonal bits fill the concave L cutout so solid 2×2 reads continuous.
* Other directions are mirrors / south extrusions of those rules.
*
* node client/scripts/generate-stone-wall-sprites.mjs
*/
@@ -28,8 +28,6 @@ const OUT_THICK = join(ROOT, "stone-wall");
const OUT_THIN = join(ROOT, "stone-wall-thin");
const EXAMPLES = join(ROOT, "stone-wall");
const MORTAR = [0x58, 0x58, 0x5c, 255];
function crcTable ()
{
const table = new Uint32Array(256);
@@ -93,7 +91,6 @@ function encodePng (rgba)
]);
}
/** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */
function decodePngRgba (path)
{
const buf = readFileSync(path);
@@ -186,9 +183,19 @@ function opaque (rgba, x, y)
return getPx(rgba, x, y)[3] > 128;
}
function copyRgba (rgba)
{
return new Uint8ClampedArray(rgba);
}
function clearRgba ()
{
return new Uint8ClampedArray(SIZE * SIZE * 4);
}
function mirrorX (rgba)
{
const out = new Uint8ClampedArray(rgba.length);
const out = clearRgba();
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
@@ -197,40 +204,54 @@ function mirrorX (rgba)
return out;
}
function hash2 (x, y)
/** Stamp every opaque pixel from src onto dst (src wins). */
function blit (dst, src)
{
let n = (x * 374761393 + y * 668265263) | 0;
n = (n ^ (n >>> 13)) * 1274126177;
return (n ^ (n >>> 16)) >>> 0;
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
const c = getPx(src, x, y);
if (c[3] > 128)
{ setPx(dst, x, y, c); }
}
}
}
function cobbleShade (base, x, y)
/**
* 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)
{
if (base[3] < 128)
{ return base; }
const h = hash2(x, y);
const speck = h & 7;
if (speck === 0)
{ return MORTAR; }
if (speck === 1)
for (let y = 0; y < SIZE; y++)
{
return [
Math.min(255, base[0] + 14),
Math.min(255, base[1] + 14),
Math.min(255, base[2] + 14),
255
];
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, b); }
}
}
if (speck === 2)
}
/**
* 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++)
{
return [
Math.max(0, base[0] - 12),
Math.max(0, base[1] - 12),
Math.max(0, base[2] - 12),
255
];
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); }
}
}
return base;
}
function decodeMask (mask)
@@ -247,271 +268,300 @@ function decodeMask (mask)
};
}
function aloneRowRange (alone, y)
{
let x0 = -1;
let x1 = -1;
for (let x = 0; x < SIZE; x++)
{
if (!opaque(alone, x, y))
{ continue; }
if (x0 < 0)
{ x0 = x; }
x1 = x;
}
return x0 < 0 ? null : { x0, x1 };
}
function aloneColRange (alone, x)
{
let y0 = -1;
let y1 = -1;
for (let y = 0; y < SIZE; y++)
{
if (!opaque(alone, x, y))
{ continue; }
if (y0 < 0)
{ y0 = y; }
y1 = y;
}
return y0 < 0 ? null : { y0, y1 };
}
function aloneBounds (alone)
/**
* South-only: alone silhouette with the body columns extended to y=15
* (mirror of how up opens the top while keeping the bottom face).
*/
function makeSouth (alone, up)
{
let minX = SIZE;
let maxX = -1;
let minY = SIZE;
let maxY = -1;
const out = copyRgba(alone);
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
if (!opaque(alone, x, y))
if (y <= 12)
{ continue; }
minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
// 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));
}
}
return { minX, maxX, minY, maxY };
return out;
}
/**
* Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion),
* plus diagonal fills for solid 2×2 corners.
* North+south shaft: up template opened through the bottom as well.
*/
function thinOccupied (x, y, c, alone)
function makeNS (up, south)
{
if (!c.n && !c.e && !c.s && !c.w)
{ return opaque(alone, x, y); }
const row = aloneRowRange(alone, y);
if (row && (c.e || c.w || opaque(alone, x, y)))
const out = copyRgba(up);
for (let y = 13; y < SIZE; y++)
{
const x0 = c.w ? 0 : row.x0;
const x1 = c.e ? SIZE - 1 : row.x1;
if (x >= x0 && x <= x1)
{ return true; }
}
const col = aloneColRange(alone, x);
if (col && (c.n || c.s || opaque(alone, x, y)))
{
const y0 = c.n ? 0 : col.y0;
const y1 = c.s ? SIZE - 1 : col.y1;
if (y >= y0 && y <= y1)
{ return true; }
}
if (opaque(alone, x, y))
{ return true; }
const b = aloneBounds(alone);
// Diagonal fills close the concave cutout of an L/T.
if (c.se && c.s && c.e && x > b.maxX && y > b.maxY)
{ return true; }
if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
{ return true; }
if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
{ return true; }
if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
{ return true; }
// Also fill the "inside" corner within the extruded AABB when diagonal joins
// (region east of alone footprint ∩ south of alone footprint, etc.).
if (c.se && c.s && c.e && x > b.maxX && y >= b.minY && y <= SIZE - 1 && x <= SIZE - 1)
{
// Only below the horizontal band's natural bottom is the true cutout;
// pixels with y in alone rows are already filled by E extrusion.
if (y > b.maxY)
{ return true; }
for (let x = 0; x < SIZE; x++)
{
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)); }
}
}
if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
{ return true; }
if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
{ return true; }
if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
{ return true; }
return false;
return out;
}
/**
* Colour for a thin pixel: prefer alone, else east/west connecting template,
* else sample the nearest alone edge colour along the extrusion axis.
* East+west run: east template with the west side also opened (mirror blend).
*/
function thinColor (x, y, c, alone, east, west)
function makeEW (east, west)
{
if (opaque(alone, x, y))
{ return getPx(alone, x, y); }
if (c.e && !c.w && opaque(east, x, y))
{ return getPx(east, x, y); }
if (c.w && !c.e && opaque(west, x, y))
{ return getPx(west, x, y); }
if (c.e && c.w)
const out = clearRgba();
for (let y = 0; y < SIZE; y++)
{
// Full E–W run: take interior colour from the east template at this y.
const row = aloneRowRange(alone, y);
if (row)
for (let x = 0; x < SIZE; x++)
{
const sampleX = Math.min(SIZE - 1, row.x1);
const col = getPx(east, sampleX, y);
if (col[3] > 128)
{ return col; }
return getPx(alone, sampleX, y);
const e = getPx(east, x, y);
const w = getPx(west, x, y);
if (e[3] > 128 && w[3] > 128)
{
// Prefer interior sample from east beyond the free-end bevels.
setPx(out, x, y, x < 8 ? w : e);
}
else if (e[3] > 128)
{ setPx(out, x, y, e); }
else if (w[3] > 128)
{ setPx(out, x, y, w); }
}
}
// N/S extrusion: continue the colour of the alone column end.
const col = aloneColRange(alone, x);
if (col)
// Ensure full-width rows where either side has the band.
for (let y = 0; y < SIZE; y++)
{
if (c.n && y < col.y0)
{ return getPx(alone, x, col.y0); }
if (c.s && y > col.y1)
{ return getPx(alone, x, col.y1); }
let any = false;
for (let x = 0; x < SIZE; x++)
{
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); }
}
}
// Diagonal fill / extended cutout: pick nearest alone interior.
const b = aloneBounds(alone);
const sx = Math.min(b.maxX, Math.max(b.minX, x));
const sy = Math.min(b.maxY, Math.max(b.minY, y));
return getPx(alone, sx, sy);
return out;
}
/**
* Thick walls always fill the tile. Shading: start from alone; for each
* connected side, replace that edge's bevel with the extruded connecting look.
* Build one wall variant's template pack from the five authored examples.
*/
function thickColor (x, y, c, alone, east, west)
function buildPack (prefix)
{
// Build by compositing directional templates.
// Base = alone.
let color = getPx(alone, x, y);
const fromEast = opaque(east, x, y) ? getPx(east, x, y) : null;
const fromWest = opaque(west, x, y) ? getPx(west, x, y) : null;
// East connection: use east template where it differs from alone on the right half,
// or more simply — if only E: use east template entirely.
if (c.e && !c.w && !c.n && !c.s)
{ return fromEast ?? color; }
if (c.w && !c.e && !c.n && !c.s)
{ return fromWest ?? color; }
// General case: for each axis, prefer the connecting template's pixel when
// that side is connected and we're on the extruded side of the tile.
if (c.e && x >= 8 && fromEast)
{ color = fromEast; }
if (c.w && x <= 7 && fromWest)
{ color = fromWest; }
// North/south: extend the top/bottom band colours toward the edge.
if (c.n && y <= 2)
{
// Sample the y=1 band from the appropriate horizontal template.
const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
color = getPx(src, x, 1);
}
if (c.s && y >= 13)
{
const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
color = getPx(src, x, 14);
}
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 fillSW = mirrorX(fillSE);
const ns = makeNS(north, south);
const ew = makeEW(east, west);
// Both E+W: full horizontal extrusion like two connecting halves.
if (c.e && c.w)
{
const left = getPx(west, Math.min(x, 7), y);
const right = getPx(east, Math.max(x, 8), y);
color = x <= 7 ? left : right;
}
// Open L corner (cardinals without diagonal): keep alone's outer-corner bevel
// in that quadrant. Filled diagonal: use connecting interior instead.
if (c.e && c.s && !c.se && x >= 12 && y >= 12)
{ color = getPx(alone, x, y); }
if (c.e && c.s && c.se && x >= 12 && y >= 12)
{ color = getPx(east, Math.min(15, x), Math.min(14, y)); }
if (c.w && c.s && !c.sw && x <= 3 && y >= 12)
{ color = getPx(alone, x, y); }
if (c.w && c.s && c.sw && x <= 3 && y >= 12)
{ color = getPx(west, Math.max(0, x), Math.min(14, y)); }
if (c.e && c.n && !c.ne && x >= 12 && y <= 3)
{ color = getPx(alone, x, y); }
if (c.e && c.n && c.ne && x >= 12 && y <= 3)
{ color = getPx(east, Math.min(15, x), Math.max(1, y)); }
if (c.w && c.n && !c.nw && x <= 3 && y <= 3)
{ color = getPx(alone, x, y); }
if (c.w && c.n && c.nw && x <= 3 && y <= 3)
{ color = getPx(west, Math.max(0, x), Math.max(1, y)); }
// Interior of solid block (all 4 + diagonals): flat top mid colour.
if (c.n && c.e && c.s && c.w && c.ne && c.se && c.sw && c.nw)
{
if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1)
{ color = getPx(east, 8, 5); }
}
return {
alone, east, west, north, south, ns, ew,
ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW
};
}
return color;
/**
* 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 paintThin (mask, alone, east, west)
function makeCardinalFill (ell, vert, horiz, corner, ellNE, fillNE)
{
const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
const c = decodeMask(mask);
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++)
{
if (!thinOccupied(x, y, c, alone))
{ continue; }
const col = thinColor(x, y, c, alone, east, west);
setPx(rgba, x, y, cobbleShade(col, x, y));
let sx = x;
let sy = y;
if (corner === "se")
{
sx = x;
sy = SIZE - 1 - y;
}
else if (corner === "sw")
{
sx = SIZE - 1 - x;
sy = SIZE - 1 - y;
}
else if (corner === "nw")
{
sx = SIZE - 1 - x;
sy = y;
}
const a = getPx(ellNE, sx, sy);
const b = getPx(fillNE, sx, sy);
if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0]))
{
// 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);
}
}
}
return rgba;
return out;
}
function paintThick (mask, alone, east, west)
/**
* 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 rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
const c = decodeMask(mask);
for (let y = 0; y < SIZE; y++)
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)
{
for (let x = 0; x < SIZE; x++)
{
const col = thickColor(x, y, c, alone, east, west);
setPx(rgba, x, y, cobbleShade(col, x, y));
}
if (e)
{ return copyRgba(east); }
if (w)
{ return copyRgba(west); }
if (n)
{ return copyRgba(north); }
if (s)
{ return copyRgba(south); }
}
return rgba;
// 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); }
}
return out;
}
function clearGenerated (dir)
@@ -525,40 +575,39 @@ function clearGenerated (dir)
}
}
function writeSet (dir, paint, label)
function writeSet (dir, pack, label)
{
clearGenerated(dir);
const masks = listValidNeighborConnectCornerMasks();
for (const mask of masks)
{
writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask)));
writeFileSync(join(dir, `${mask}.png`), encodePng(paintMask(mask, pack)));
}
console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
}
const thinAlone = decodePngRgba(join(EXAMPLES, "example-stone-thin.png"));
const thinEast = decodePngRgba(join(EXAMPLES, "example-stone-thin-connecting.png"));
const thinWest = mirrorX(thinEast);
const thickAlone = decodePngRgba(join(EXAMPLES, "example-stone-thick.png"));
const thickEast = decodePngRgba(join(EXAMPLES, "example-stone-thick-connecting.png"));
const thickWest = mirrorX(thickEast);
// Sanity: alone / east templates must decode to expected coverage.
const thinAloneCount = [...thinAlone].filter((_, i) => i % 4 === 3 && thinAlone[i] > 128).length;
const thinEastCount = [...thinEast].filter((_, i) => i % 4 === 3 && thinEast[i] > 128).length;
if (thinAloneCount < 80 || thinEastCount < 120)
const thin = buildPack("thin");
const thick = buildPack("thick");
// Sanity checks against authored examples
function assertSame (a, b, label)
{
throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`);
for (let i = 0; i < a.length; i++)
{
if (a[i] !== b[i])
{ throw new Error(`Template mismatch: ${label} at byte ${i}`); }
}
}
writeSet(OUT_THICK, (mask) => paintThick(mask, thickAlone, thickEast, thickWest), "thick");
writeSet(OUT_THIN, (mask) => paintThin(mask, thinAlone, thinEast, thinWest), "thin");
// Keep mask 0 / east-only (2) pixel-identical to examples (minus cobble speck on 0).
writeFileSync(join(OUT_THIN, "0.png"), encodePng(thinAlone));
writeFileSync(join(OUT_THICK, "0.png"), encodePng(thickAlone));
writeFileSync(join(OUT_THIN, "2.png"), encodePng(thinEast));
writeFileSync(join(OUT_THICK, "2.png"), encodePng(thickEast));
writeFileSync(join(OUT_THIN, "8.png"), encodePng(thinWest));
writeFileSync(join(OUT_THICK, "8.png"), encodePng(thickWest));
console.log("Pinned 0 / E / W templates to example pixels");
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");
writeSet(OUT_THIN, thin, "thin");
writeSet(OUT_THICK, thick, "thick");
@@ -2,14 +2,14 @@ * 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). * * * Shape sources (authoritative): * Authoritative shape examples (no texture — flat greys only): * example-stone-thin.png / example-stone-thin-connecting.png * example-stone-{thin|thick}.png alone * example-stone-thick.png / example-stone-thick-connecting.png * 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) * * * Alone = free-standing frustum / bevelled block. * Other directions are mirrors / south extrusions of those rules. * *-connecting = same bands extruded to the east edge (free west end kept). * Other directions are mirrors / vertical extrusions of that rule. * Diagonal bits fill the concave L cutout so solid 2×2 reads continuous. * * * node client/scripts/generate-stone-wall-sprites.mjs * node client/scripts/generate-stone-wall-sprites.mjs */ */@@ -28,8 +28,6 @@ const OUT_THICK = join(ROOT, "stone-wall");const OUT_THIN = join(ROOT, "stone-wall-thin");const OUT_THIN = join(ROOT, "stone-wall-thin");const EXAMPLES = join(ROOT, "stone-wall");const EXAMPLES = join(ROOT, "stone-wall");const MORTAR = [0x58, 0x58, 0x5c, 255];function crcTable ()function crcTable (){{ const table = new Uint32Array(256); const table = new Uint32Array(256);@@ -93,7 +91,6 @@ function encodePng (rgba) ]); ]);}}/** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */function decodePngRgba (path)function decodePngRgba (path){{ const buf = readFileSync(path); const buf = readFileSync(path);@@ -186,9 +183,19 @@ function opaque (rgba, x, y) return getPx(rgba, x, y)[3] > 128; return getPx(rgba, x, y)[3] > 128;}}function copyRgba (rgba){ return new Uint8ClampedArray(rgba);}function clearRgba (){ return new Uint8ClampedArray(SIZE * SIZE * 4);}function mirrorX (rgba)function mirrorX (rgba){{ const out = new Uint8ClampedArray(rgba.length); const out = clearRgba(); 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++)@@ -197,40 +204,54 @@ function mirrorX (rgba) return out; return out;}}function hash2 (x, y)/** Stamp every opaque pixel from src onto dst (src wins). */function blit (dst, src){{ let n = (x * 374761393 + y * 668265263) | 0; for (let y = 0; y < SIZE; y++) n = (n ^ (n >>> 13)) * 1274126177; { return (n ^ (n >>> 16)) >>> 0; for (let x = 0; x < SIZE; x++) { const c = getPx(src, x, y); if (c[3] > 128) { setPx(dst, x, y, c); } } }}}function cobbleShade (base, x, y)/** * 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){{ if (base[3] < 128) for (let y = 0; y < SIZE; y++) { return base; } const h = hash2(x, y); const speck = h & 7; if (speck === 0) { return MORTAR; } if (speck === 1) { { return [ for (let x = 0; x < SIZE; x++) Math.min(255, base[0] + 14), { Math.min(255, base[1] + 14), const a = getPx(concave, x, y); Math.min(255, base[2] + 14), const b = getPx(filled, x, y); 255 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2])) ]; { setPx(dst, x, y, b); } } } } if (speck === 2)}/** * 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++) { { return [ for (let x = 0; x < SIZE; x++) Math.max(0, base[0] - 12), { Math.max(0, base[1] - 12), const a = getPx(concave, x, y); Math.max(0, base[2] - 12), const b = getPx(filled, x, y); 255 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2])) ]; { setPx(dst, x, y, a); } } } } return base;}}function decodeMask (mask)function decodeMask (mask)@@ -247,271 +268,300 @@ function decodeMask (mask) }; };}}function aloneRowRange (alone, y)/**{ * South-only: alone silhouette with the body columns extended to y=15 let x0 = -1; * (mirror of how up opens the top while keeping the bottom face). let x1 = -1; */ for (let x = 0; x < SIZE; x++)function makeSouth (alone, up) { if (!opaque(alone, x, y)) { continue; } if (x0 < 0) { x0 = x; } x1 = x; } return x0 < 0 ? null : { x0, x1 };}function aloneColRange (alone, x){ let y0 = -1; let y1 = -1; for (let y = 0; y < SIZE; y++) { if (!opaque(alone, x, y)) { continue; } if (y0 < 0) { y0 = y; } y1 = y; } return y0 < 0 ? null : { y0, y1 };}function aloneBounds (alone){{ let minX = SIZE; const out = copyRgba(alone); let maxX = -1; let minY = SIZE; let maxY = -1; 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++) { { if (!opaque(alone, x, y)) if (y <= 12) { continue; } { continue; } minX = Math.min(minX, x); // Extend columns that belong to the vertical shaft (up body width). maxX = Math.max(maxX, x); if (!opaque(up, x, 12)) minY = Math.min(minY, y); { continue; } maxY = Math.max(maxY, y); setPx(out, x, y, getPx(alone, x, 12)); } } } } return { minX, maxX, minY, maxY }; return out;}}/**/** * Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion), * North+south shaft: up template opened through the bottom as well. * plus diagonal fills for solid 2×2 corners. */ */function thinOccupied (x, y, c, alone)function makeNS (up, south){{ if (!c.n && !c.e && !c.s && !c.w) const out = copyRgba(up); { return opaque(alone, x, y); } for (let y = 13; y < SIZE; y++) const row = aloneRowRange(alone, y); if (row && (c.e || c.w || opaque(alone, x, y))) { { const x0 = c.w ? 0 : row.x0; for (let x = 0; x < SIZE; x++) const x1 = c.e ? SIZE - 1 : row.x1; { if (x >= x0 && x <= x1) if (opaque(south, x, y)) { return true; } { setPx(out, x, y, getPx(south, x, y)); } } else if (opaque(up, x, 12)) { setPx(out, x, y, getPx(up, x, 12)); } const col = aloneColRange(alone, x); } if (col && (c.n || c.s || opaque(alone, x, y))) { const y0 = c.n ? 0 : col.y0; const y1 = c.s ? SIZE - 1 : col.y1; if (y >= y0 && y <= y1) { return true; } } if (opaque(alone, x, y)) { return true; } const b = aloneBounds(alone); // Diagonal fills close the concave cutout of an L/T. if (c.se && c.s && c.e && x > b.maxX && y > b.maxY) { return true; } if (c.sw && c.s && c.w && x < b.minX && y > b.maxY) { return true; } if (c.ne && c.n && c.e && x > b.maxX && y < b.minY) { return true; } if (c.nw && c.n && c.w && x < b.minX && y < b.minY) { return true; } // Also fill the "inside" corner within the extruded AABB when diagonal joins // (region east of alone footprint ∩ south of alone footprint, etc.). if (c.se && c.s && c.e && x > b.maxX && y >= b.minY && y <= SIZE - 1 && x <= SIZE - 1) { // Only below the horizontal band's natural bottom is the true cutout; // pixels with y in alone rows are already filled by E extrusion. if (y > b.maxY) { return true; } } } if (c.sw && c.s && c.w && x < b.minX && y > b.maxY) return out; { return true; } if (c.ne && c.n && c.e && x > b.maxX && y < b.minY) { return true; } if (c.nw && c.n && c.w && x < b.minX && y < b.minY) { return true; } return false;}}/**/** * Colour for a thin pixel: prefer alone, else east/west connecting template, * East+west run: east template with the west side also opened (mirror blend). * else sample the nearest alone edge colour along the extrusion axis. */ */function thinColor (x, y, c, alone, east, west)function makeEW (east, west){{ if (opaque(alone, x, y)) const out = clearRgba(); { return getPx(alone, x, y); } for (let y = 0; y < SIZE; y++) if (c.e && !c.w && opaque(east, x, y)) { return getPx(east, x, y); } if (c.w && !c.e && opaque(west, x, y)) { return getPx(west, x, y); } if (c.e && c.w) { { // Full E–W run: take interior colour from the east template at this y. for (let x = 0; x < SIZE; x++) const row = aloneRowRange(alone, y); if (row) { { const sampleX = Math.min(SIZE - 1, row.x1); const e = getPx(east, x, y); const col = getPx(east, sampleX, y); const w = getPx(west, x, y); if (col[3] > 128) if (e[3] > 128 && w[3] > 128) { return col; } { return getPx(alone, sampleX, y); // Prefer interior sample from east beyond the free-end bevels. setPx(out, x, y, x < 8 ? w : e); } 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. // N/S extrusion: continue the colour of the alone column end. for (let y = 0; y < SIZE; y++) const col = aloneColRange(alone, x); if (col) { { if (c.n && y < col.y0) let any = false; { return getPx(alone, x, col.y0); } for (let x = 0; x < SIZE; x++) if (c.s && y > col.y1) { { return getPx(alone, x, col.y1); } 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); } } } } return out; // Diagonal fill / extended cutout: pick nearest alone interior. const b = aloneBounds(alone); const sx = Math.min(b.maxX, Math.max(b.minX, x)); const sy = Math.min(b.maxY, Math.max(b.minY, y)); return getPx(alone, sx, sy);}}/**/** * Thick walls always fill the tile. Shading: start from alone; for each * Build one wall variant's template pack from the five authored examples. * connected side, replace that edge's bevel with the extruded connecting look. */ */function thickColor (x, y, c, alone, east, west)function buildPack (prefix){{ // Build by compositing directional templates. const alone = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}.png`)); // Base = alone. const east = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting.png`)); let color = getPx(alone, x, y); const north = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-up.png`)); const ellNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-L.png`)); const fromEast = opaque(east, x, y) ? getPx(east, x, y) : null; const fillNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-2x2.png`)); const fromWest = opaque(west, x, y) ? getPx(west, x, y) : null; const west = mirrorX(east); const south = makeSouth(alone, north); // East connection: use east template where it differs from alone on the right half, const ellNW = mirrorX(ellNE); // or more simply — if only E: use east template entirely. const fillNW = mirrorX(fillNE); if (c.e && !c.w && !c.n && !c.s) // South-east / south-west L: mirror the north L vertically in occupancy terms { return fromEast ?? color; } // by compositing south + east with the SE corner left open / filled. if (c.w && !c.e && !c.n && !c.s) const ellSE = makeCardinalL(south, east, "se"); { return fromWest ?? color; } const fillSE = makeCardinalFill(ellSE, south, east, "se", ellNE, fillNE); const ellSW = mirrorX(ellSE); // General case: for each axis, prefer the connecting template's pixel when const fillSW = mirrorX(fillSE); // that side is connected and we're on the extruded side of the tile. const ns = makeNS(north, south); if (c.e && x >= 8 && fromEast) const ew = makeEW(east, west); { color = fromEast; } if (c.w && x <= 7 && fromWest) { color = fromWest; } // North/south: extend the top/bottom band colours toward the edge. if (c.n && y <= 2) { // Sample the y=1 band from the appropriate horizontal template. const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone); color = getPx(src, x, 1); } if (c.s && y >= 13) { const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone); color = getPx(src, x, 14); } // Both E+W: full horizontal extrusion like two connecting halves. return { if (c.e && c.w) alone, east, west, north, south, ns, ew, { ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW const left = getPx(west, Math.min(x, 7), y); }; const right = getPx(east, Math.max(x, 8), y);} color = x <= 7 ? left : right; } // Open L corner (cardinals without diagonal): keep alone's outer-corner bevel // in that quadrant. Filled diagonal: use connecting interior instead. if (c.e && c.s && !c.se && x >= 12 && y >= 12) { color = getPx(alone, x, y); } if (c.e && c.s && c.se && x >= 12 && y >= 12) { color = getPx(east, Math.min(15, x), Math.min(14, y)); } if (c.w && c.s && !c.sw && x <= 3 && y >= 12) { color = getPx(alone, x, y); } if (c.w && c.s && c.sw && x <= 3 && y >= 12) { color = getPx(west, Math.max(0, x), Math.min(14, y)); } if (c.e && c.n && !c.ne && x >= 12 && y <= 3) { color = getPx(alone, x, y); } if (c.e && c.n && c.ne && x >= 12 && y <= 3) { color = getPx(east, Math.min(15, x), Math.max(1, y)); } if (c.w && c.n && !c.nw && x <= 3 && y <= 3) { color = getPx(alone, x, y); } if (c.w && c.n && c.nw && x <= 3 && y <= 3) { color = getPx(west, Math.max(0, x), Math.max(1, y)); } // Interior of solid block (all 4 + diagonals): flat top mid colour. if (c.n && c.e && c.s && c.w && c.ne && c.se && c.sw && c.nw) { if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1) { color = getPx(east, 8, 5); } } return color;/** * 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 paintThin (mask, alone, east, west)function makeCardinalFill (ell, vert, horiz, corner, ellNE, fillNE){{ const rgba = new Uint8ClampedArray(SIZE * SIZE * 4); const out = copyRgba(ell); const c = decodeMask(mask); // Map NE fill delta onto the target corner. 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++) { { if (!thinOccupied(x, y, c, alone)) let sx = x; { continue; } let sy = y; const col = thinColor(x, y, c, alone, east, west); if (corner === "se") setPx(rgba, x, y, cobbleShade(col, x, y)); { sx = x; sy = SIZE - 1 - y; } else if (corner === "sw") { sx = SIZE - 1 - x; sy = SIZE - 1 - y; } else if (corner === "nw") { sx = SIZE - 1 - x; sy = y; } const a = getPx(ellNE, sx, sy); const b = getPx(fillNE, sx, sy); if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0])) { // 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); } } } } } return rgba; return out;}}function paintThick (mask, alone, east, west)/** * 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 rgba = new Uint8ClampedArray(SIZE * SIZE * 4); const c = decodeMask(mask); const c = decodeMask(mask); for (let y = 0; y < SIZE; y++) 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) { { for (let x = 0; x < SIZE; x++) if (e) { { return copyRgba(east); } const col = thickColor(x, y, c, alone, east, west); if (w) setPx(rgba, x, y, cobbleShade(col, x, y)); { return copyRgba(west); } } if (n) { return copyRgba(north); } if (s) { return copyRgba(south); } } } return rgba; // 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); } } return out;}}function clearGenerated (dir)function clearGenerated (dir)@@ -525,40 +575,39 @@ function clearGenerated (dir) } }}}function writeSet (dir, paint, label)function writeSet (dir, pack, label){{ clearGenerated(dir); clearGenerated(dir); const masks = listValidNeighborConnectCornerMasks(); const masks = listValidNeighborConnectCornerMasks(); for (const mask of masks) for (const mask of masks) { { writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask))); writeFileSync(join(dir, `${mask}.png`), encodePng(paintMask(mask, pack))); } } console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`); console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);}}const thinAlone = decodePngRgba(join(EXAMPLES, "example-stone-thin.png"));const thin = buildPack("thin");const thinEast = decodePngRgba(join(EXAMPLES, "example-stone-thin-connecting.png"));const thick = buildPack("thick");const thinWest = mirrorX(thinEast);const thickAlone = decodePngRgba(join(EXAMPLES, "example-stone-thick.png"));// Sanity checks against authored examplesconst thickEast = decodePngRgba(join(EXAMPLES, "example-stone-thick-connecting.png"));function assertSame (a, b, label)const thickWest = mirrorX(thickEast);// Sanity: alone / east templates must decode to expected coverage.const thinAloneCount = [...thinAlone].filter((_, i) => i % 4 === 3 && thinAlone[i] > 128).length;const thinEastCount = [...thinEast].filter((_, i) => i % 4 === 3 && thinEast[i] > 128).length;if (thinAloneCount < 80 || thinEastCount < 120){{ throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`); for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) { throw new Error(`Template mismatch: ${label} at byte ${i}`); } }}}assertSame(paintMask(0, thin), thin.alone, "thin alone");writeSet(OUT_THICK, (mask) => paintThick(mask, thickAlone, thickEast, thickWest), "thick");assertSame(paintMask(2, thin), thin.east, "thin east");writeSet(OUT_THIN, (mask) => paintThin(mask, thinAlone, thinEast, thinWest), "thin");assertSame(paintMask(1, thin), thin.north, "thin north");assertSame(paintMask(3, thin), thin.ellNE, "thin L");// Keep mask 0 / east-only (2) pixel-identical to examples (minus cobble speck on 0).assertSame(paintMask(19, thin), thin.fillNE, "thin 2x2");writeFileSync(join(OUT_THIN, "0.png"), encodePng(thinAlone));assertSame(paintMask(0, thick), thick.alone, "thick alone");writeFileSync(join(OUT_THICK, "0.png"), encodePng(thickAlone));assertSame(paintMask(2, thick), thick.east, "thick east");writeFileSync(join(OUT_THIN, "2.png"), encodePng(thinEast));assertSame(paintMask(1, thick), thick.north, "thick north");writeFileSync(join(OUT_THICK, "2.png"), encodePng(thickEast));assertSame(paintMask(3, thick), thick.ellNE, "thick L");writeFileSync(join(OUT_THIN, "8.png"), encodePng(thinWest));assertSame(paintMask(19, thick), thick.fillNE, "thick 2x2");writeFileSync(join(OUT_THICK, "8.png"), encodePng(thickWest));console.log("Pinned 0 / E / W templates to example pixels");writeSet(OUT_THIN, thin, "thin");writeSet(OUT_THICK, thick, "thick");