Rebuild stone-wall sprites from alone/connecting examples.
Extrude the authored frustum bands to connected edges (mirrors for W) and keep diagonal fills for solid 2×2 corners so L-strips stay concave.
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.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -2,18 +2,19 @@
* Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
* (cardinals + diagonal corners — 47 valid states).
*
* Shape references (silhouette / shading only, not final texture):
* client/assets/blocks/stone-wall/example-stone-thin.png
* client/assets/blocks/stone-wall/example-stone-thick.png
* Shape sources (authoritative):
* example-stone-thin.png / example-stone-thin-connecting.png
* example-stone-thick.png / example-stone-thick-connecting.png
*
* Corner bits: when both adjacent cardinals join but the diagonal does not,
* paint an L-strip (concave). When the diagonal also joins, fill the quadrant
* so a solid 2×2 reads as one block.
* 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.
*
* node client/scripts/generate-stone-wall-sprites.mjs
*/
import { mkdirSync, writeFileSync, readdirSync, unlinkSync } from "node:fs";
import { deflateSync } from "node:zlib";
import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import {
@@ -25,48 +26,10 @@ 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 OUTLINE = [0x40, 0x40, 0x40, 255];
const TOP_HI = [0xaf, 0xaf, 0xaf, 255];
const TOP = [0x80, 0x80, 0x80, 255];
const TOP_LO = [0x73, 0x73, 0x73, 255];
const FACE_L = [0x95, 0x95, 0x95, 255];
const FACE = [0x73, 0x73, 0x73, 255];
const FACE_R = [0x6c, 0x6c, 0x6c, 255];
const FACE_FRONT = [0x54, 0x54, 0x54, 255];
const HI_L = [0xb6, 0xb6, 0xb6, 255];
const HI_R = [0x80, 0x80, 0x80, 255];
const MORTAR = [0x58, 0x58, 0x5c, 255];
/**
* Thin: compact top core (table-style strip-union) so L keeps a concave cutout;
* frustum face hangs below on free south edges. Alone matches example-stone-thin.
*/
const THIN = Object.freeze({
topY0: 2,
coreY0: 3,
coreY1: 7,
faceY1: 12,
coreX0: 5,
coreX1: 10,
baseX0: 3,
baseX1: 12,
fullTile: false
});
/** Thick: full-tile footprint; bevels react to free edges / missing diagonals. */
const THICK = Object.freeze({
topY0: 1,
coreY0: 1,
coreY1: 8,
faceY1: 14,
coreX0: 3,
coreX1: 12,
baseX0: 0,
baseX1: 15,
fullTile: true
});
function crcTable ()
{
const table = new Uint32Array(256);
@@ -130,6 +93,83 @@ function encodePng (rgba)
]);
}
/** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */
function decodePngRgba (path)
{
const buf = readFileSync(path);
let off = 8;
let w = 0;
let h = 0;
const idat = [];
while (off < buf.length)
{
const len = buf.readUInt32BE(off);
const type = buf.slice(off + 4, off + 8).toString("ascii");
const data = buf.slice(off + 8, off + 8 + len);
if (type === "IHDR")
{
w = data.readUInt32BE(0);
h = data.readUInt32BE(4);
if (data[8] !== 8 || data[9] !== 6)
{ throw new Error(`${path}: expected 8-bit RGBA`); }
}
else if (type === "IDAT")
{ idat.push(data); }
else if (type === "IEND")
{ break; }
off += 12 + len;
}
const raw = inflateSync(Buffer.concat(idat));
const bpp = 4;
const stride = w * bpp;
const rgba = new Uint8ClampedArray(w * h * 4);
let src = 0;
const prev = Buffer.alloc(stride);
const cur = Buffer.alloc(stride);
for (let y = 0; y < h; y++)
{
const filter = raw[src++];
for (let i = 0; i < stride; i++)
{ cur[i] = raw[src++]; }
for (let i = 0; i < stride; i++)
{
const left = i >= bpp ? cur[i - bpp] : 0;
const up = prev[i];
const upLeft = i >= bpp ? prev[i - bpp] : 0;
let val = cur[i];
if (filter === 1)
{ val = (val + left) & 255; }
else if (filter === 2)
{ val = (val + up) & 255; }
else if (filter === 3)
{ val = (val + ((left + up) >> 1)) & 255; }
else if (filter === 4)
{
const p = left + up - upLeft;
const pa = Math.abs(p - left);
const pb = Math.abs(p - up);
const pc = Math.abs(p - upLeft);
const pr = (pa <= pb && pa <= pc) ? left : (pb <= pc ? up : upLeft);
val = (val + pr) & 255;
}
cur[i] = val;
}
rgba.set(cur, y * stride);
prev.set(cur);
}
if (w !== SIZE || h !== SIZE)
{ throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
return rgba;
}
function getPx (rgba, x, y)
{
if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
{ return [0, 0, 0, 0]; }
const i = (y * SIZE + x) * 4;
return [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]];
}
function setPx (rgba, x, y, color)
{
if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
@@ -141,6 +181,22 @@ function setPx (rgba, x, y, color)
rgba[i + 3] = color[3];
}
function opaque (rgba, x, y)
{
return getPx(rgba, x, y)[3] > 128;
}
function mirrorX (rgba)
{
const out = new Uint8ClampedArray(rgba.length);
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{ setPx(out, x, y, getPx(rgba, SIZE - 1 - x, y)); }
}
return out;
}
function hash2 (x, y)
{
let n = (x * 374761393 + y * 668265263) | 0;
@@ -150,6 +206,8 @@ function hash2 (x, y)
function cobbleShade (base, x, y)
{
if (base[3] < 128)
{ return base; }
const h = hash2(x, y);
const speck = h & 7;
if (speck === 0)
@@ -157,18 +215,18 @@ function cobbleShade (base, x, y)
if (speck === 1)
{
return [
Math.min(255, base[0] + 18),
Math.min(255, base[1] + 18),
Math.min(255, base[2] + 18),
Math.min(255, base[0] + 14),
Math.min(255, base[1] + 14),
Math.min(255, base[2] + 14),
255
];
}
if (speck === 2)
{
return [
Math.max(0, base[0] - 14),
Math.max(0, base[1] - 14),
Math.max(0, base[2] - 14),
Math.max(0, base[0] - 12),
Math.max(0, base[1] - 12),
Math.max(0, base[2] - 12),
255
];
}
@@ -189,186 +247,268 @@ function decodeMask (mask)
};
}
function frustumX0X1 (y, profile)
function aloneRowRange (alone, y)
{
if (y <= 2)
{ return { x0: 6, x1: 9 }; }
if (y <= 4)
{ return { x0: 5, x1: 10 }; }
if (y <= 6)
{ return { x0: 4, x1: 11 }; }
return { x0: profile.baseX0, x1: profile.baseX1 };
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 };
}
/** Top-plane strip-union + diagonal fills (no front skirt). */
function inTopPlane (x, y, c, profile)
function aloneColRange (alone, x)
{
const { coreX0, coreX1, coreY0, coreY1 } = profile;
const inCoreX = x >= coreX0 && x <= coreX1;
const inCoreY = y >= coreY0 && y <= coreY1;
const wantH = c.e || c.w;
const wantV = c.n || c.s;
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 };
}
if (inCoreX && inCoreY)
{ return true; }
function aloneBounds (alone)
{
let minX = SIZE;
let maxX = -1;
let minY = SIZE;
let maxY = -1;
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
if (!opaque(alone, x, y))
{ continue; }
minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
}
}
return { minX, maxX, minY, maxY };
}
/**
* Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion),
* plus diagonal fills for solid 2×2 corners.
*/
function thinOccupied (x, y, c, alone)
{
if (!c.n && !c.e && !c.s && !c.w)
{ return opaque(alone, x, y); }
if (wantH && inCoreY)
const row = aloneRowRange(alone, y);
if (row && (c.e || c.w || opaque(alone, x, y)))
{
const x0 = c.w ? 0 : coreX0;
const x1 = c.e ? SIZE - 1 : coreX1;
const x0 = c.w ? 0 : row.x0;
const x1 = c.e ? SIZE - 1 : row.x1;
if (x >= x0 && x <= x1)
{ return true; }
}
if (wantV && inCoreX)
const col = aloneColRange(alone, x);
if (col && (c.n || c.s || opaque(alone, x, y)))
{
const y0 = c.n ? 0 : coreY0;
const y1 = c.s ? SIZE - 1 : coreY1;
const y0 = c.n ? 0 : col.y0;
const y1 = c.s ? SIZE - 1 : col.y1;
if (y >= y0 && y <= y1)
{ return true; }
}
// Close concave L/T cutouts when the diagonal neighbour is present.
if (c.se && c.s && c.e && x > coreX1 && y > coreY1)
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 < coreX0 && y > coreY1)
if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
{ return true; }
if (c.ne && c.n && c.e && x > coreX1 && y < coreY0)
if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
{ return true; }
if (c.nw && c.n && c.w && x < coreX0 && y < coreY0)
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 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;
}
function inWall (x, y, c, profile)
/**
* Colour for a thin pixel: prefer alone, else east/west connecting template,
* else sample the nearest alone edge colour along the extrusion axis.
*/
function thinColor (x, y, c, alone, east, west)
{
if (profile.fullTile)
{ return true; }
const alone = !c.n && !c.e && !c.s && !c.w;
if (alone)
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)
{
if (y < profile.topY0 || y > profile.faceY1)
{ return false; }
const { x0, x1 } = frustumX0X1(y, profile);
return x >= x0 && x <= x1;
// Full E–W run: take interior colour from the east template at this y.
const row = aloneRowRange(alone, y);
if (row)
{
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);
}
}
if (inTopPlane(x, y, c, profile))
{ return true; }
// Front-face skirt under top-plane pixels that do not continue south.
if (y > profile.coreY1 && y <= profile.faceY1)
// N/S extrusion: continue the colour of the alone column end.
const col = aloneColRange(alone, x);
if (col)
{
if (!inTopPlane(x, profile.coreY1, c, profile))
{ return false; }
// Vertical run into a southern neighbour: no skirt in the core column.
if (c.s && x >= profile.coreX0 && x <= profile.coreX1)
{ return false; }
// Diagonal-filled SE mass continues as solid top — skirt only at very bottom
// of columns that are the south perimeter (no further south neighbour top).
if (c.s && ((c.se && c.e && x > profile.coreX1) || (c.sw && c.w && x < profile.coreX0)))
{ return false; }
const { x0, x1 } = frustumX0X1(y, profile);
const skirtX0 = c.w ? 0 : x0;
const skirtX1 = c.e ? SIZE - 1 : x1;
if (x < skirtX0 || x > skirtX1)
{ return false; }
return inTopPlane(x, profile.coreY1, c, profile);
if (c.n && y < col.y0)
{ return getPx(alone, x, col.y0); }
if (c.s && y > col.y1)
{ return getPx(alone, x, col.y1); }
}
return false;
// 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);
}
function shadeAt (x, y, c, profile, occ)
/**
* Thick walls always fill the tile. Shading: start from alone; for each
* connected side, replace that edge's bevel with the extruded connecting look.
*/
function thickColor (x, y, c, alone, east, west)
{
const n = occ(x, y - 1);
const e = occ(x + 1, y);
const s = occ(x, y + 1);
const w = occ(x - 1, y);
const openCount = (!n ? 1 : 0) + (!s ? 1 : 0) + (!e ? 1 : 0) + (!w ? 1 : 0);
if (openCount > 0)
// 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)
{
const edgeHeavy = (!n && y <= (profile.fullTile ? 0 : profile.topY0))
|| (!s && y >= (profile.fullTile ? SIZE - 1 : profile.faceY1))
|| (!w && x <= (profile.fullTile ? 0 : profile.baseX0))
|| (!e && x >= (profile.fullTile ? SIZE - 1 : profile.baseX1));
if (edgeHeavy || openCount >= 2)
{ return OUTLINE; }
// 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);
}
if (profile.fullTile)
// Both E+W: full horizontal extrusion like two connecting halves.
if (c.e && c.w)
{
const freeN = !c.n;
const freeS = !c.s;
const freeW = !c.w;
const freeE = !c.e;
const openNe = c.n && c.e && !c.ne;
const openSe = c.s && c.e && !c.se;
const openSw = c.s && c.w && !c.sw;
const openNw = c.n && c.w && !c.nw;
if (y === 0 || x === 0 || x === SIZE - 1 || y === SIZE - 1)
{ return OUTLINE; }
if ((freeW && x <= 2) || (openNw && x <= 2 && y <= 2) || (openSw && x <= 2 && y >= SIZE - 3))
{ return FACE_L; }
if ((freeE && x >= SIZE - 3) || (openNe && x >= SIZE - 3 && y <= 2) || (openSe && x >= SIZE - 3 && y >= SIZE - 3))
{ return FACE_R; }
if (freeN && y === 1)
{ return TOP_HI; }
if (y <= 8 && x >= 3 && x <= 12)
{ return TOP; }
if (freeS || y >= 10)
{ return FACE_FRONT; }
return TOP_LO;
const left = getPx(west, Math.min(x, 7), y);
const right = getPx(east, Math.max(x, 8), y);
color = x <= 7 ? left : right;
}
if (y <= profile.coreY1)
// 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 (!n)
{ return OUTLINE; }
if (!w)
{ return HI_L; }
if (!e)
{ return HI_R; }
return TOP;
if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1)
{ color = getPx(east, 8, 5); }
}
if (!s)
{ return OUTLINE; }
if (!w)
{ return HI_L; }
if (!e)
{ return HI_R; }
return FACE;
return color;
}
function paintWall (mask, profile)
function paintThin (mask, alone, east, west)
{
const rgba = new Uint8Array(SIZE * SIZE * 4);
const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
const c = decodeMask(mask);
const occ = (x, y) =>
for (let y = 0; y < SIZE; y++)
{
if (x < 0)
{ return c.w; }
if (x >= SIZE)
{ return c.e; }
if (y < 0)
{ return c.n; }
if (y >= SIZE)
{ return c.s; }
return inWall(x, y, c, profile);
};
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));
}
}
return rgba;
}
function paintThick (mask, alone, east, west)
{
const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
const c = decodeMask(mask);
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
if (!occ(x, y))
{ continue; }
setPx(rgba, x, y, cobbleShade(shadeAt(x, y, c, profile, occ), x, y));
const col = thickColor(x, y, c, alone, east, west);
setPx(rgba, x, y, cobbleShade(col, x, y));
}
}
return rgba;
@@ -385,16 +525,40 @@ function clearGenerated (dir)
}
}
function writeSet (dir, profile, label)
function writeSet (dir, paint, label)
{
clearGenerated(dir);
const masks = listValidNeighborConnectCornerMasks();
for (const mask of masks)
{
writeFileSync(join(dir, `${mask}.png`), encodePng(paintWall(mask, profile)));
writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask)));
}
console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
}
writeSet(OUT_THICK, THICK, "thick");
writeSet(OUT_THIN, THIN, "thin");
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)
{
throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`);
}
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");
@@ -2,18 +2,19 @@ * 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 references (silhouette / shading only, not final texture): * Shape sources (authoritative): * client/assets/blocks/stone-wall/example-stone-thin.png * example-stone-thin.png / example-stone-thin-connecting.png * client/assets/blocks/stone-wall/example-stone-thick.png * example-stone-thick.png / example-stone-thick-connecting.png * * * Corner bits: when both adjacent cardinals join but the diagonal does not, * Alone = free-standing frustum / bevelled block. * paint an L-strip (concave). When the diagonal also joins, fill the quadrant * *-connecting = same bands extruded to the east edge (free west end kept). * so a solid 2×2 reads as one block. * 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 */ */import { mkdirSync, writeFileSync, readdirSync, unlinkSync } from "node:fs";import { mkdirSync, writeFileSync, readdirSync, unlinkSync, readFileSync } from "node:fs";import { deflateSync } 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 {@@ -25,48 +26,10 @@ 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 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 OUTLINE = [0x40, 0x40, 0x40, 255];const TOP_HI = [0xaf, 0xaf, 0xaf, 255];const TOP = [0x80, 0x80, 0x80, 255];const TOP_LO = [0x73, 0x73, 0x73, 255];const FACE_L = [0x95, 0x95, 0x95, 255];const FACE = [0x73, 0x73, 0x73, 255];const FACE_R = [0x6c, 0x6c, 0x6c, 255];const FACE_FRONT = [0x54, 0x54, 0x54, 255];const HI_L = [0xb6, 0xb6, 0xb6, 255];const HI_R = [0x80, 0x80, 0x80, 255];const MORTAR = [0x58, 0x58, 0x5c, 255];const MORTAR = [0x58, 0x58, 0x5c, 255];/** * Thin: compact top core (table-style strip-union) so L keeps a concave cutout; * frustum face hangs below on free south edges. Alone matches example-stone-thin. */const THIN = Object.freeze({ topY0: 2, coreY0: 3, coreY1: 7, faceY1: 12, coreX0: 5, coreX1: 10, baseX0: 3, baseX1: 12, fullTile: false});/** Thick: full-tile footprint; bevels react to free edges / missing diagonals. */const THICK = Object.freeze({ topY0: 1, coreY0: 1, coreY1: 8, faceY1: 14, coreX0: 3, coreX1: 12, baseX0: 0, baseX1: 15, fullTile: true});function crcTable ()function crcTable (){{ const table = new Uint32Array(256); const table = new Uint32Array(256);@@ -130,6 +93,83 @@ function encodePng (rgba) ]); ]);}}/** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */function decodePngRgba (path){ const buf = readFileSync(path); let off = 8; let w = 0; let h = 0; const idat = []; while (off < buf.length) { const len = buf.readUInt32BE(off); const type = buf.slice(off + 4, off + 8).toString("ascii"); const data = buf.slice(off + 8, off + 8 + len); if (type === "IHDR") { w = data.readUInt32BE(0); h = data.readUInt32BE(4); if (data[8] !== 8 || data[9] !== 6) { throw new Error(`${path}: expected 8-bit RGBA`); } } else if (type === "IDAT") { idat.push(data); } else if (type === "IEND") { break; } off += 12 + len; } const raw = inflateSync(Buffer.concat(idat)); const bpp = 4; const stride = w * bpp; const rgba = new Uint8ClampedArray(w * h * 4); let src = 0; const prev = Buffer.alloc(stride); const cur = Buffer.alloc(stride); for (let y = 0; y < h; y++) { const filter = raw[src++]; for (let i = 0; i < stride; i++) { cur[i] = raw[src++]; } for (let i = 0; i < stride; i++) { const left = i >= bpp ? cur[i - bpp] : 0; const up = prev[i]; const upLeft = i >= bpp ? prev[i - bpp] : 0; let val = cur[i]; if (filter === 1) { val = (val + left) & 255; } else if (filter === 2) { val = (val + up) & 255; } else if (filter === 3) { val = (val + ((left + up) >> 1)) & 255; } else if (filter === 4) { const p = left + up - upLeft; const pa = Math.abs(p - left); const pb = Math.abs(p - up); const pc = Math.abs(p - upLeft); const pr = (pa <= pb && pa <= pc) ? left : (pb <= pc ? up : upLeft); val = (val + pr) & 255; } cur[i] = val; } rgba.set(cur, y * stride); prev.set(cur); } if (w !== SIZE || h !== SIZE) { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); } return rgba;}function getPx (rgba, x, y){ if (x < 0 || y < 0 || x >= SIZE || y >= SIZE) { return [0, 0, 0, 0]; } const i = (y * SIZE + x) * 4; return [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]];}function setPx (rgba, x, y, color)function setPx (rgba, x, y, color){{ if (x < 0 || y < 0 || x >= SIZE || y >= SIZE) if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)@@ -141,6 +181,22 @@ function setPx (rgba, x, y, color) rgba[i + 3] = color[3]; rgba[i + 3] = color[3];}}function opaque (rgba, x, y){ return getPx(rgba, x, y)[3] > 128;}function mirrorX (rgba){ const out = new Uint8ClampedArray(rgba.length); for (let y = 0; y < SIZE; y++) { for (let x = 0; x < SIZE; x++) { setPx(out, x, y, getPx(rgba, SIZE - 1 - x, y)); } } return out;}function hash2 (x, y)function hash2 (x, y){{ let n = (x * 374761393 + y * 668265263) | 0; let n = (x * 374761393 + y * 668265263) | 0;@@ -150,6 +206,8 @@ function hash2 (x, y)function cobbleShade (base, x, y)function cobbleShade (base, x, y){{ if (base[3] < 128) { return base; } const h = hash2(x, y); const h = hash2(x, y); const speck = h & 7; const speck = h & 7; if (speck === 0) if (speck === 0)@@ -157,18 +215,18 @@ function cobbleShade (base, x, y) if (speck === 1) if (speck === 1) { { return [ return [ Math.min(255, base[0] + 18), Math.min(255, base[0] + 14), Math.min(255, base[1] + 18), Math.min(255, base[1] + 14), Math.min(255, base[2] + 18), Math.min(255, base[2] + 14), 255 255 ]; ]; } } if (speck === 2) if (speck === 2) { { return [ return [ Math.max(0, base[0] - 14), Math.max(0, base[0] - 12), Math.max(0, base[1] - 14), Math.max(0, base[1] - 12), Math.max(0, base[2] - 14), Math.max(0, base[2] - 12), 255 255 ]; ]; } }@@ -189,186 +247,268 @@ function decodeMask (mask) }; };}}function frustumX0X1 (y, profile)function aloneRowRange (alone, y){{ if (y <= 2) let x0 = -1; { return { x0: 6, x1: 9 }; } let x1 = -1; if (y <= 4) for (let x = 0; x < SIZE; x++) { return { x0: 5, x1: 10 }; } { if (y <= 6) if (!opaque(alone, x, y)) { return { x0: 4, x1: 11 }; } { continue; } return { x0: profile.baseX0, x1: profile.baseX1 }; if (x0 < 0) { x0 = x; } x1 = x; } return x0 < 0 ? null : { x0, x1 };}}/** Top-plane strip-union + diagonal fills (no front skirt). */function aloneColRange (alone, x)function inTopPlane (x, y, c, profile){{ const { coreX0, coreX1, coreY0, coreY1 } = profile; let y0 = -1; const inCoreX = x >= coreX0 && x <= coreX1; let y1 = -1; const inCoreY = y >= coreY0 && y <= coreY1; for (let y = 0; y < SIZE; y++) const wantH = c.e || c.w; { const wantV = c.n || c.s; if (!opaque(alone, x, y)) { continue; } if (y0 < 0) { y0 = y; } y1 = y; } return y0 < 0 ? null : { y0, y1 };} if (inCoreX && inCoreY)function aloneBounds (alone) { return true; }{ let minX = SIZE; let maxX = -1; let minY = SIZE; let maxY = -1; for (let y = 0; y < SIZE; y++) { for (let x = 0; x < SIZE; x++) { if (!opaque(alone, x, y)) { continue; } minX = Math.min(minX, x); maxX = Math.max(maxX, x); minY = Math.min(minY, y); maxY = Math.max(maxY, y); } } return { minX, maxX, minY, maxY };}/** * Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion), * plus diagonal fills for solid 2×2 corners. */function thinOccupied (x, y, c, alone){ if (!c.n && !c.e && !c.s && !c.w) { return opaque(alone, x, y); } if (wantH && inCoreY) const row = aloneRowRange(alone, y); if (row && (c.e || c.w || opaque(alone, x, y))) { { const x0 = c.w ? 0 : coreX0; const x0 = c.w ? 0 : row.x0; const x1 = c.e ? SIZE - 1 : coreX1; const x1 = c.e ? SIZE - 1 : row.x1; if (x >= x0 && x <= x1) if (x >= x0 && x <= x1) { return true; } { return true; } } } if (wantV && inCoreX) const col = aloneColRange(alone, x); if (col && (c.n || c.s || opaque(alone, x, y))) { { const y0 = c.n ? 0 : coreY0; const y0 = c.n ? 0 : col.y0; const y1 = c.s ? SIZE - 1 : coreY1; const y1 = c.s ? SIZE - 1 : col.y1; if (y >= y0 && y <= y1) if (y >= y0 && y <= y1) { return true; } { return true; } } } // Close concave L/T cutouts when the diagonal neighbour is present. if (opaque(alone, x, y)) if (c.se && c.s && c.e && x > coreX1 && y > coreY1) { 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; } { return true; } if (c.sw && c.s && c.w && x < coreX0 && y > coreY1) if (c.sw && c.s && c.w && x < b.minX && y > b.maxY) { return true; } { return true; } if (c.ne && c.n && c.e && x > coreX1 && y < coreY0) if (c.ne && c.n && c.e && x > b.maxX && y < b.minY) { return true; } { return true; } if (c.nw && c.n && c.w && x < coreX0 && y < coreY0) 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 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 true; } return false; return false;}}function inWall (x, y, c, profile)/** * Colour for a thin pixel: prefer alone, else east/west connecting template, * else sample the nearest alone edge colour along the extrusion axis. */function thinColor (x, y, c, alone, east, west){{ if (profile.fullTile) if (opaque(alone, x, y)) { return true; } { return getPx(alone, x, y); } const alone = !c.n && !c.e && !c.s && !c.w; if (c.e && !c.w && opaque(east, x, y)) if (alone) { return getPx(east, x, y); } if (c.w && !c.e && opaque(west, x, y)) { return getPx(west, x, y); } if (c.e && c.w) { { if (y < profile.topY0 || y > profile.faceY1) // Full E–W run: take interior colour from the east template at this y. { return false; } const row = aloneRowRange(alone, y); const { x0, x1 } = frustumX0X1(y, profile); if (row) return x >= x0 && x <= x1; { 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); } } } if (inTopPlane(x, y, c, profile)) // N/S extrusion: continue the colour of the alone column end. { return true; } const col = aloneColRange(alone, x); if (col) // Front-face skirt under top-plane pixels that do not continue south. if (y > profile.coreY1 && y <= profile.faceY1) { { if (!inTopPlane(x, profile.coreY1, c, profile)) if (c.n && y < col.y0) { return false; } { return getPx(alone, x, col.y0); } // Vertical run into a southern neighbour: no skirt in the core column. if (c.s && y > col.y1) if (c.s && x >= profile.coreX0 && x <= profile.coreX1) { return getPx(alone, x, col.y1); } { return false; } // Diagonal-filled SE mass continues as solid top — skirt only at very bottom // of columns that are the south perimeter (no further south neighbour top). if (c.s && ((c.se && c.e && x > profile.coreX1) || (c.sw && c.w && x < profile.coreX0))) { return false; } const { x0, x1 } = frustumX0X1(y, profile); const skirtX0 = c.w ? 0 : x0; const skirtX1 = c.e ? SIZE - 1 : x1; if (x < skirtX0 || x > skirtX1) { return false; } return inTopPlane(x, profile.coreY1, c, profile); } } return false; // 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);}}function shadeAt (x, y, c, profile, occ)/** * Thick walls always fill the tile. Shading: start from alone; for each * connected side, replace that edge's bevel with the extruded connecting look. */function thickColor (x, y, c, alone, east, west){{ const n = occ(x, y - 1); // Build by compositing directional templates. const e = occ(x + 1, y); // Base = alone. const s = occ(x, y + 1); let color = getPx(alone, x, y); const w = occ(x - 1, y); const fromEast = opaque(east, x, y) ? getPx(east, x, y) : null; const openCount = (!n ? 1 : 0) + (!s ? 1 : 0) + (!e ? 1 : 0) + (!w ? 1 : 0); const fromWest = opaque(west, x, y) ? getPx(west, x, y) : null; if (openCount > 0) // 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) { { const edgeHeavy = (!n && y <= (profile.fullTile ? 0 : profile.topY0)) // Sample the y=1 band from the appropriate horizontal template. || (!s && y >= (profile.fullTile ? SIZE - 1 : profile.faceY1)) const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone); || (!w && x <= (profile.fullTile ? 0 : profile.baseX0)) color = getPx(src, x, 1); || (!e && x >= (profile.fullTile ? SIZE - 1 : profile.baseX1)); } if (edgeHeavy || openCount >= 2) if (c.s && y >= 13) { return OUTLINE; } { const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone); color = getPx(src, x, 14); } } if (profile.fullTile) // Both E+W: full horizontal extrusion like two connecting halves. if (c.e && c.w) { { const freeN = !c.n; const left = getPx(west, Math.min(x, 7), y); const freeS = !c.s; const right = getPx(east, Math.max(x, 8), y); const freeW = !c.w; color = x <= 7 ? left : right; const freeE = !c.e; const openNe = c.n && c.e && !c.ne; const openSe = c.s && c.e && !c.se; const openSw = c.s && c.w && !c.sw; const openNw = c.n && c.w && !c.nw; if (y === 0 || x === 0 || x === SIZE - 1 || y === SIZE - 1) { return OUTLINE; } if ((freeW && x <= 2) || (openNw && x <= 2 && y <= 2) || (openSw && x <= 2 && y >= SIZE - 3)) { return FACE_L; } if ((freeE && x >= SIZE - 3) || (openNe && x >= SIZE - 3 && y <= 2) || (openSe && x >= SIZE - 3 && y >= SIZE - 3)) { return FACE_R; } if (freeN && y === 1) { return TOP_HI; } if (y <= 8 && x >= 3 && x <= 12) { return TOP; } if (freeS || y >= 10) { return FACE_FRONT; } return TOP_LO; } } if (y <= profile.coreY1) // 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 (!n) if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1) { return OUTLINE; } { color = getPx(east, 8, 5); } if (!w) { return HI_L; } if (!e) { return HI_R; } return TOP; } } if (!s) return color; { return OUTLINE; } if (!w) { return HI_L; } if (!e) { return HI_R; } return FACE;}}function paintWall (mask, profile)function paintThin (mask, alone, east, west){{ const rgba = new Uint8Array(SIZE * SIZE * 4); const rgba = new Uint8ClampedArray(SIZE * SIZE * 4); const c = decodeMask(mask); const c = decodeMask(mask); const occ = (x, y) => for (let y = 0; y < SIZE; y++) { { if (x < 0) for (let x = 0; x < SIZE; x++) { return c.w; } { if (x >= SIZE) if (!thinOccupied(x, y, c, alone)) { return c.e; } { continue; } if (y < 0) const col = thinColor(x, y, c, alone, east, west); { return c.n; } setPx(rgba, x, y, cobbleShade(col, x, y)); if (y >= SIZE) } { return c.s; } } return inWall(x, y, c, profile); return rgba; };}function paintThick (mask, alone, east, west){ const rgba = new Uint8ClampedArray(SIZE * SIZE * 4); const c = decodeMask(mask); 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 (!occ(x, y)) const col = thickColor(x, y, c, alone, east, west); { continue; } setPx(rgba, x, y, cobbleShade(col, x, y)); setPx(rgba, x, y, cobbleShade(shadeAt(x, y, c, profile, occ), x, y)); } } } } return rgba; return rgba;@@ -385,16 +525,40 @@ function clearGenerated (dir) } }}}function writeSet (dir, profile, label)function writeSet (dir, paint, 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(paintWall(mask, profile))); writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask))); } } console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`); console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);}}writeSet(OUT_THICK, THICK, "thick");const thinAlone = decodePngRgba(join(EXAMPLES, "example-stone-thin.png"));writeSet(OUT_THIN, THIN, "thin");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){ throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`);}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");