Add smooth stone wall variants with low-grit texture.
Same thick/thin face-id shapes as cobble stone, baked with rarer speckles for a cleaner surface.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -1,297 +1,13 @@
/**
* Bake grey cobblestone texture onto thick/thin stone-wall shape masks.
*
* Shape source of truth (greyscale face-IDs):
* client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png
*
* Textured output (gameplay sprites):
* client/assets/blocks/thick-stone-wall/
* client/assets/blocks/thin-stone-wall/
*
* Face greys (see docs/STONE_WALL_SHAPES.md) pick a cobble base luminance;
* a stable hash adds mortar/highlight speckles inside each face.
* Bake grey cobblestone onto thick/thin stone-wall shape masks.
* Delegates to texture-wall-sprites.mjs --variant=cobble
*
* node client/scripts/texture-stone-wall-sprites.mjs
*/
import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
const SIZE = 16;
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
const EXAMPLES = join(ROOT, "_examples/stone-wall");
const OUT = {
"thick-stone-wall": join(ROOT, "thick-stone-wall"),
"thin-stone-wall": join(ROOT, "thin-stone-wall")
};
/** Gray cobble palette (cool stone; no magenta). */
const TOP = [168, 168, 172, 255];
const TOP_HI = [198, 198, 202, 255];
const TOP_LO = [140, 140, 144, 255];
const FACE = [112, 112, 116, 255];
const FACE_HI = [132, 132, 136, 255];
const FACE_LO = [88, 88, 92, 255];
const EDGE = [70, 70, 74, 255];
const MORTAR = [78, 78, 82, 255];
/**
* Face-id grey → cobble base (directional light from NW).
* Thick and thin use slightly different vocabularies (thin frustum).
*/
const THICK_ROLE_BASE = new Map([
[0xaf, TOP_HI], // north bevel
[0x95, FACE_HI], // west face
[0x80, TOP], // top plateau
[0x6c, FACE], // east face
[0x54, FACE_LO], // south face
[0x40, EDGE] // outline / crease
]);
const THIN_ROLE_BASE = new Map([
[0xb6, FACE_HI], // west face (bright)
[0x95, TOP_HI], // north rim / ridge top
[0x80, FACE], // east face
[0x73, FACE_LO], // south / front body
[0x40, EDGE]
]);
function roleBaseFor (prefix)
{
return prefix === "thin-stone-wall" ? THIN_ROLE_BASE : THICK_ROLE_BASE;
}
/** Fallback: map arbitrary grey luminance into the cobble range. */
function baseFromLuminance (g)
{
if (g <= 0x48)
{ return EDGE; }
if (g <= 0x60)
{ return FACE_LO; }
if (g <= 0x78)
{ return FACE; }
if (g <= 0x90)
{ return FACE_HI; }
if (g <= 0xa8)
{ return TOP; }
return TOP_HI;
}
function crcTable ()
{
const table = new Uint32Array(256);
for (let n = 0; n < 256; n++)
{
let c = n;
for (let k = 0; k < 8; k++)
{ c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); }
table[n] = c >>> 0;
}
return table;
}
const CRC_TABLE = crcTable();
function crc32 (buf)
{
let c = 0xffffffff;
for (let i = 0; i < buf.length; i++)
{ c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); }
return (c ^ 0xffffffff) >>> 0;
}
function chunk (type, data)
{
const len = Buffer.alloc(4);
len.writeUInt32BE(data.length);
const typeBuf = Buffer.from(type, "ascii");
const crcBuf = Buffer.alloc(4);
crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])));
return Buffer.concat([len, typeBuf, data, crcBuf]);
}
function encodePng (rgba)
{
const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE);
for (let y = 0; y < SIZE; y++)
{
const row = y * (SIZE * 4 + 1);
raw[row] = 0;
for (let x = 0; x < SIZE; x++)
{
const i = (y * SIZE + x) * 4;
const o = row + 1 + x * 4;
raw[o] = rgba[i];
raw[o + 1] = rgba[i + 1];
raw[o + 2] = rgba[i + 2];
raw[o + 3] = rgba[i + 3];
}
}
const ihdr = Buffer.alloc(13);
ihdr.writeUInt32BE(SIZE, 0);
ihdr.writeUInt32BE(SIZE, 4);
ihdr[8] = 8;
ihdr[9] = 6;
return Buffer.concat([
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
chunk("IHDR", ihdr),
chunk("IDAT", deflateSync(raw, { level: 9 })),
chunk("IEND", Buffer.alloc(0))
]);
}
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);
}
else if (type === "IDAT")
{ idat.push(data); }
else if (type === "IEND")
{ break; }
off += 12 + len;
}
const inflated = inflateSync(Buffer.concat(idat));
const rgba = new Uint8Array(w * h * 4);
const bpp = 4;
let src = 0;
for (let y = 0; y < h; y++)
{
const filter = inflated[src++];
const row = inflated.subarray(src, src + w * bpp);
src += w * bpp;
const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null;
const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp);
for (let i = 0; i < row.length; i++)
{
let v = row[i];
if (filter === 1)
{ v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; }
else if (filter === 2)
{ v = (v + (prev ? prev[i] : 0)) & 255; }
else if (filter === 3)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
v = (v + Math.floor((a + b) / 2)) & 255;
}
else if (filter === 4)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
const c = prev && i >= bpp ? prev[i - bpp] : 0;
const p = a + b - c;
const pa = Math.abs(p - a);
const pb = Math.abs(p - b);
const pc = Math.abs(p - c);
v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255;
}
out[i] = v;
}
}
if (w !== SIZE || h !== SIZE)
{ throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
return rgba;
}
function hash2 (x, y)
{
let n = (x * 374761393 + y * 668265263) | 0;
n = (n ^ (n >>> 13)) * 1274126177;
return (n ^ (n >>> 16)) >>> 0;
}
function cobbleShade (base, x, y, isOutline)
{
if (isOutline)
{
// Keep creases mostly solid so silhouettes stay crisp.
const h = hash2(x, y);
return (h & 15) === 0 ? MORTAR : EDGE;
}
const h = hash2(x, y);
const speck = h & 7;
if (speck === 0)
{ return MORTAR; }
if (speck === 1 || speck === 2)
{
return base === TOP || base === TOP_HI || base === TOP_LO
? TOP_HI
: FACE_HI;
}
if (speck === 3)
{
return base === TOP || base === TOP_HI || base === TOP_LO
? TOP_LO
: FACE_LO;
}
return base;
}
function textureMask (rgba, roleBase)
{
const out = new Uint8Array(SIZE * SIZE * 4);
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
const i = (y * SIZE + x) * 4;
const a = rgba[i + 3];
if (a === 0)
{ continue; }
const g = rgba[i];
const base = roleBase.get(g) ?? baseFromLuminance(g);
const color = cobbleShade(base, x, y, g === 0x40);
out[i] = color[0];
out[i + 1] = color[1];
out[i + 2] = color[2];
out[i + 3] = 255;
}
}
return out;
}
function shapeFiles (prefix)
{
if (!existsSync(EXAMPLES))
{ throw new Error(`Missing examples folder: ${EXAMPLES}`); }
return readdirSync(EXAMPLES)
.filter((name) => name.startsWith(prefix) && name.endsWith(".png"))
.sort();
}
let wrote = 0;
for (const [prefix, outDir] of Object.entries(OUT))
{
mkdirSync(outDir, { recursive: true });
const files = shapeFiles(prefix);
if (files.length !== 16)
{
throw new Error(
`Expected 16 ${prefix} masks in ${EXAMPLES}, found ${files.length}`
);
}
const roleBase = roleBaseFor(prefix);
for (const name of files)
{
const shaped = decodePngRgba(join(EXAMPLES, name));
const textured = textureMask(shaped, roleBase);
writeFileSync(join(outDir, name), encodePng(textured));
wrote++;
}
console.log(`Textured ${files.length} → ${outDir}`);
}
console.log(`Done (${wrote} sprites). Shapes left greyscale in ${EXAMPLES}`);
const script = join(dirname(fileURLToPath(import.meta.url)), "texture-wall-sprites.mjs");
const result = spawnSync(process.execPath, [script, "--variant=cobble"], { stdio: "inherit" });
process.exit(result.status ?? 1);
@@ -1,297 +1,13 @@/**/** * Bake grey cobblestone texture onto thick/thin stone-wall shape masks. * Bake grey cobblestone onto thick/thin stone-wall shape masks. * * Delegates to texture-wall-sprites.mjs --variant=cobble * Shape source of truth (greyscale face-IDs): * client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png * * Textured output (gameplay sprites): * client/assets/blocks/thick-stone-wall/ * client/assets/blocks/thin-stone-wall/ * * Face greys (see docs/STONE_WALL_SHAPES.md) pick a cobble base luminance; * a stable hash adds mortar/highlight speckles inside each face. * * * node client/scripts/texture-stone-wall-sprites.mjs * node client/scripts/texture-stone-wall-sprites.mjs */ */import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";import { spawnSync } from "node:child_process";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";const SIZE = 16;const script = join(dirname(fileURLToPath(import.meta.url)), "texture-wall-sprites.mjs");const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");const result = spawnSync(process.execPath, [script, "--variant=cobble"], { stdio: "inherit" });const EXAMPLES = join(ROOT, "_examples/stone-wall");process.exit(result.status ?? 1);const OUT = { "thick-stone-wall": join(ROOT, "thick-stone-wall"), "thin-stone-wall": join(ROOT, "thin-stone-wall")};/** Gray cobble palette (cool stone; no magenta). */const TOP = [168, 168, 172, 255];const TOP_HI = [198, 198, 202, 255];const TOP_LO = [140, 140, 144, 255];const FACE = [112, 112, 116, 255];const FACE_HI = [132, 132, 136, 255];const FACE_LO = [88, 88, 92, 255];const EDGE = [70, 70, 74, 255];const MORTAR = [78, 78, 82, 255];/** * Face-id grey → cobble base (directional light from NW). * Thick and thin use slightly different vocabularies (thin frustum). */const THICK_ROLE_BASE = new Map([ [0xaf, TOP_HI], // north bevel [0x95, FACE_HI], // west face [0x80, TOP], // top plateau [0x6c, FACE], // east face [0x54, FACE_LO], // south face [0x40, EDGE] // outline / crease]);const THIN_ROLE_BASE = new Map([ [0xb6, FACE_HI], // west face (bright) [0x95, TOP_HI], // north rim / ridge top [0x80, FACE], // east face [0x73, FACE_LO], // south / front body [0x40, EDGE]]);function roleBaseFor (prefix){ return prefix === "thin-stone-wall" ? THIN_ROLE_BASE : THICK_ROLE_BASE;}/** Fallback: map arbitrary grey luminance into the cobble range. */function baseFromLuminance (g){ if (g <= 0x48) { return EDGE; } if (g <= 0x60) { return FACE_LO; } if (g <= 0x78) { return FACE; } if (g <= 0x90) { return FACE_HI; } if (g <= 0xa8) { return TOP; } return TOP_HI;}function crcTable (){ const table = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) { c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); } table[n] = c >>> 0; } return table;}const CRC_TABLE = crcTable();function crc32 (buf){ let c = 0xffffffff; for (let i = 0; i < buf.length; i++) { c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); } return (c ^ 0xffffffff) >>> 0;}function chunk (type, data){ const len = Buffer.alloc(4); len.writeUInt32BE(data.length); const typeBuf = Buffer.from(type, "ascii"); const crcBuf = Buffer.alloc(4); crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data]))); return Buffer.concat([len, typeBuf, data, crcBuf]);}function encodePng (rgba){ const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE); for (let y = 0; y < SIZE; y++) { const row = y * (SIZE * 4 + 1); raw[row] = 0; for (let x = 0; x < SIZE; x++) { const i = (y * SIZE + x) * 4; const o = row + 1 + x * 4; raw[o] = rgba[i]; raw[o + 1] = rgba[i + 1]; raw[o + 2] = rgba[i + 2]; raw[o + 3] = rgba[i + 3]; } } const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(SIZE, 0); ihdr.writeUInt32BE(SIZE, 4); ihdr[8] = 8; ihdr[9] = 6; return Buffer.concat([ Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", ihdr), chunk("IDAT", deflateSync(raw, { level: 9 })), chunk("IEND", Buffer.alloc(0)) ]);}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); } else if (type === "IDAT") { idat.push(data); } else if (type === "IEND") { break; } off += 12 + len; } const inflated = inflateSync(Buffer.concat(idat)); const rgba = new Uint8Array(w * h * 4); const bpp = 4; let src = 0; for (let y = 0; y < h; y++) { const filter = inflated[src++]; const row = inflated.subarray(src, src + w * bpp); src += w * bpp; const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null; const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp); for (let i = 0; i < row.length; i++) { let v = row[i]; if (filter === 1) { v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; } else if (filter === 2) { v = (v + (prev ? prev[i] : 0)) & 255; } else if (filter === 3) { const a = i >= bpp ? out[i - bpp] : 0; const b = prev ? prev[i] : 0; v = (v + Math.floor((a + b) / 2)) & 255; } else if (filter === 4) { const a = i >= bpp ? out[i - bpp] : 0; const b = prev ? prev[i] : 0; const c = prev && i >= bpp ? prev[i - bpp] : 0; const p = a + b - c; const pa = Math.abs(p - a); const pb = Math.abs(p - b); const pc = Math.abs(p - c); v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255; } out[i] = v; } } if (w !== SIZE || h !== SIZE) { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); } return rgba;}function hash2 (x, y){ let n = (x * 374761393 + y * 668265263) | 0; n = (n ^ (n >>> 13)) * 1274126177; return (n ^ (n >>> 16)) >>> 0;}function cobbleShade (base, x, y, isOutline){ if (isOutline) { // Keep creases mostly solid so silhouettes stay crisp. const h = hash2(x, y); return (h & 15) === 0 ? MORTAR : EDGE; } const h = hash2(x, y); const speck = h & 7; if (speck === 0) { return MORTAR; } if (speck === 1 || speck === 2) { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_HI : FACE_HI; } if (speck === 3) { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_LO : FACE_LO; } return base;}function textureMask (rgba, roleBase){ const out = new Uint8Array(SIZE * SIZE * 4); for (let y = 0; y < SIZE; y++) { for (let x = 0; x < SIZE; x++) { const i = (y * SIZE + x) * 4; const a = rgba[i + 3]; if (a === 0) { continue; } const g = rgba[i]; const base = roleBase.get(g) ?? baseFromLuminance(g); const color = cobbleShade(base, x, y, g === 0x40); out[i] = color[0]; out[i + 1] = color[1]; out[i + 2] = color[2]; out[i + 3] = 255; } } return out;}function shapeFiles (prefix){ if (!existsSync(EXAMPLES)) { throw new Error(`Missing examples folder: ${EXAMPLES}`); } return readdirSync(EXAMPLES) .filter((name) => name.startsWith(prefix) && name.endsWith(".png")) .sort();}let wrote = 0;for (const [prefix, outDir] of Object.entries(OUT)){ mkdirSync(outDir, { recursive: true }); const files = shapeFiles(prefix); if (files.length !== 16) { throw new Error( `Expected 16 ${prefix} masks in ${EXAMPLES}, found ${files.length}` ); } const roleBase = roleBaseFor(prefix); for (const name of files) { const shaped = decodePngRgba(join(EXAMPLES, name)); const textured = textureMask(shaped, roleBase); writeFileSync(join(outDir, name), encodePng(textured)); wrote++; } console.log(`Textured ${files.length} → ${outDir}`);}console.log(`Done (${wrote} sprites). Shapes left greyscale in ${EXAMPLES}`);@@ -0,0 +1,492 @@
/**
* Bake wall textures onto thick/thin greyscale face-id shape masks.
*
* Shapes (source of truth):
* client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png
*
* Usage:
* node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff
* node client/scripts/texture-wall-sprites.mjs --variant=all
*
* cobble → thick-stone-wall / thin-stone-wall (named)
* smooth → thick-smooth-stone-wall / thin-smooth-stone-wall (named)
* brick → thick-brick-wall / thin-brick-wall (named)
* wood → thick-wood-wall / thin-wood-wall (magenta masks 0–15)
* cliff → thick-cliff / thin-cliff (dirt sides + magenta top, named)
*/
import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";
import { deflateSync, inflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { cardinalConnectionSuffix } from "../../shared/world/neighborConnect.js";
const SIZE = 16;
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
const EXAMPLES = join(ROOT, "_examples/stone-wall");
const GROUNDS = join(dirname(fileURLToPath(import.meta.url)), "../assets/grounds");
const THICK_ROLE = {
0xaf: "N",
0x95: "W",
0x80: "T",
0x6c: "E",
0x54: "S",
0x40: "O"
};
const THIN_ROLE = {
0xb6: "W",
0x95: "N",
0x80: "E",
0x73: "S",
0x40: "O"
};
function roleOf (prefix, g)
{
const map = prefix.startsWith("thin") ? THIN_ROLE : THICK_ROLE;
return map[g] ?? null;
}
function isTopRole (role)
{
return role === "T" || role === "N";
}
function crcTable ()
{
const table = new Uint32Array(256);
for (let n = 0; n < 256; n++)
{
let c = n;
for (let k = 0; k < 8; k++)
{ c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); }
table[n] = c >>> 0;
}
return table;
}
const CRC_TABLE = crcTable();
function crc32 (buf)
{
let c = 0xffffffff;
for (let i = 0; i < buf.length; i++)
{ c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); }
return (c ^ 0xffffffff) >>> 0;
}
function chunk (type, data)
{
const len = Buffer.alloc(4);
len.writeUInt32BE(data.length);
const typeBuf = Buffer.from(type, "ascii");
const crcBuf = Buffer.alloc(4);
crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])));
return Buffer.concat([len, typeBuf, data, crcBuf]);
}
function encodePng (rgba)
{
const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE);
for (let y = 0; y < SIZE; y++)
{
const row = y * (SIZE * 4 + 1);
raw[row] = 0;
for (let x = 0; x < SIZE; x++)
{
const i = (y * SIZE + x) * 4;
const o = row + 1 + x * 4;
raw[o] = rgba[i];
raw[o + 1] = rgba[i + 1];
raw[o + 2] = rgba[i + 2];
raw[o + 3] = rgba[i + 3];
}
}
const ihdr = Buffer.alloc(13);
ihdr.writeUInt32BE(SIZE, 0);
ihdr.writeUInt32BE(SIZE, 4);
ihdr[8] = 8;
ihdr[9] = 6;
return Buffer.concat([
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
chunk("IHDR", ihdr),
chunk("IDAT", deflateSync(raw, { level: 9 })),
chunk("IEND", Buffer.alloc(0))
]);
}
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);
}
else if (type === "IDAT")
{ idat.push(data); }
else if (type === "IEND")
{ break; }
off += 12 + len;
}
const inflated = inflateSync(Buffer.concat(idat));
const rgba = new Uint8Array(w * h * 4);
const bpp = 4;
let src = 0;
for (let y = 0; y < h; y++)
{
const filter = inflated[src++];
const row = inflated.subarray(src, src + w * bpp);
src += w * bpp;
const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null;
const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp);
for (let i = 0; i < row.length; i++)
{
let v = row[i];
if (filter === 1)
{ v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; }
else if (filter === 2)
{ v = (v + (prev ? prev[i] : 0)) & 255; }
else if (filter === 3)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
v = (v + Math.floor((a + b) / 2)) & 255;
}
else if (filter === 4)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
const c = prev && i >= bpp ? prev[i - bpp] : 0;
const p = a + b - c;
const pa = Math.abs(p - a);
const pb = Math.abs(p - b);
const pc = Math.abs(p - c);
v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255;
}
out[i] = v;
}
}
if (w !== SIZE || h !== SIZE)
{ throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
return rgba;
}
function hash2 (x, y)
{
let n = (x * 374761393 + y * 668265263) | 0;
n = (n ^ (n >>> 13)) * 1274126177;
return (n ^ (n >>> 16)) >>> 0;
}
function rgba (r, g, b, a = 255)
{
return [r, g, b, a];
}
function mulRgb (c, factor)
{
return rgba(
Math.min(255, Math.round(c[0] * factor)),
Math.min(255, Math.round(c[1] * factor)),
Math.min(255, Math.round(c[2] * factor)),
c[3] ?? 255
);
}
function mixRgb (a, b, t)
{
return rgba(
Math.round(a[0] + (b[0] - a[0]) * t),
Math.round(a[1] + (b[1] - a[1]) * t),
Math.round(a[2] + (b[2] - a[2]) * t),
255
);
}
/** Face role → lighting factor (NW light). */
const ROLE_LIT = { N: 1.15, W: 1.0, T: 1.05, E: 0.82, S: 0.62, O: 0.45 };
function faceLit (role)
{
return ROLE_LIT[role] ?? 0.9;
}
function loadDirt ()
{
const path = join(GROUNDS, "dirt/dirt.png");
if (!existsSync(path))
{ throw new Error(`Missing dirt texture: ${path}`); }
return decodePngRgba(path);
}
let dirtRgba = null;
function dirtAt (x, y)
{
if (!dirtRgba)
{ dirtRgba = loadDirt(); }
const i = ((y & 15) * SIZE + (x & 15)) * 4;
return rgba(dirtRgba[i], dirtRgba[i + 1], dirtRgba[i + 2]);
}
/* ---- palettes ---- */
const COBBLE = {
N: rgba(198, 198, 202),
W: rgba(132, 132, 136),
T: rgba(168, 168, 172),
E: rgba(112, 112, 116),
S: rgba(88, 88, 92),
O: rgba(70, 70, 74),
mortar: rgba(78, 78, 82),
hiN: rgba(210, 210, 214),
loS: rgba(78, 78, 82)
};
const BRICK = {
N: rgba(196, 92, 72),
W: rgba(168, 72, 56),
T: rgba(178, 78, 60),
E: rgba(148, 58, 46),
S: rgba(118, 48, 38),
O: rgba(72, 36, 30),
mortar: rgba(92, 78, 68),
hi: rgba(210, 110, 88),
lo: rgba(100, 42, 34)
};
function cobbleLike (basePal, x, y, role, gritMask)
{
if (role === "O")
{
const h = hash2(x, y);
return (h & 15) === 0 ? basePal.mortar : basePal.O;
}
const base = basePal[role] ?? basePal.T;
const h = hash2(x, y);
const speck = h & gritMask;
if (speck === 0)
{ return basePal.mortar; }
if (gritMask === 7)
{
if (speck === 1 || speck === 2)
{ return role === "N" || role === "T" ? (basePal.hiN ?? basePal.hi ?? mulRgb(base, 1.12)) : (basePal.hi ?? mulRgb(base, 1.1)); }
if (speck === 3)
{ return role === "S" ? (basePal.loS ?? basePal.lo ?? mulRgb(base, 0.88)) : (basePal.lo ?? mulRgb(base, 0.9)); }
}
else if (gritMask === 31)
{
// Smooth: rare soft variation only.
if (speck === 1)
{ return mulRgb(base, 1.06); }
if (speck === 2)
{ return mulRgb(base, 0.94); }
}
return base;
}
function brickShade (x, y, role)
{
if (role === "O")
{ return BRICK.O; }
const row = Math.floor(y / 4);
const brickX = x + (row & 1) * 3;
const onHMortar = (y % 4) === 0;
const onVMortar = (brickX % 6) === 0;
if (onHMortar || onVMortar)
{ return BRICK.mortar; }
const h = hash2(x, y);
if ((h & 15) === 0)
{ return BRICK.hi; }
if ((h & 15) === 1)
{ return BRICK.lo; }
return BRICK[role] ?? BRICK.T;
}
function woodMagenta (role)
{
// R≈B, G<R — lightness encodes face.
const L = {
O: 55,
S: 95,
E: 120,
W: 155,
T: 185,
N: 210
}[role] ?? 140;
const gHi = role === "N" || role === "T" ? Math.min(L - 20, 50) : 0;
return rgba(L, gHi, L);
}
function cliffShade (x, y, role)
{
if (isTopRole(role))
{
// Full magenta top — replaced in-game by ground sample shader.
return rgba(255, 0, 255);
}
if (role === "O")
{
const d = dirtAt(x, y);
return mulRgb(d, 0.35);
}
const d = dirtAt(x, y);
return mulRgb(d, faceLit(role));
}
function paintPixel (variant, prefix, g, x, y)
{
const role = roleOf(prefix, g);
if (!role)
{
// Unknown grey: luminance fallback toward mid face.
const lit = g / 128;
if (variant === "wood")
{ return rgba(Math.round(140 * lit), 0, Math.round(140 * lit)); }
if (variant === "cliff")
{ return mulRgb(dirtAt(x, y), lit); }
if (variant === "brick")
{ return mulRgb(BRICK.T, lit); }
return mulRgb(COBBLE.T, lit);
}
if (variant === "cobble")
{ return cobbleLike(COBBLE, x, y, role, 7); }
if (variant === "smooth")
{ return cobbleLike(COBBLE, x, y, role, 31); }
if (variant === "brick")
{ return brickShade(x, y, role); }
if (variant === "wood")
{ return woodMagenta(role); }
if (variant === "cliff")
{ return cliffShade(x, y, role); }
throw new Error(`Unknown variant ${variant}`);
}
function textureMask (rgbaIn, variant, shapePrefix)
{
const out = new Uint8Array(SIZE * SIZE * 4);
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
const i = (y * SIZE + x) * 4;
if (rgbaIn[i + 3] === 0)
{ continue; }
const color = paintPixel(variant, shapePrefix, rgbaIn[i], x, y);
out[i] = color[0];
out[i + 1] = color[1];
out[i + 2] = color[2];
out[i + 3] = 255;
}
}
return out;
}
const VARIANT_OUT = {
cobble: {
thick: { dir: "thick-stone-wall", named: true, prefix: "thick-stone-wall" },
thin: { dir: "thin-stone-wall", named: true, prefix: "thin-stone-wall" }
},
smooth: {
thick: { dir: "thick-smooth-stone-wall", named: true, prefix: "thick-smooth-stone-wall" },
thin: { dir: "thin-smooth-stone-wall", named: true, prefix: "thin-smooth-stone-wall" }
},
brick: {
thick: { dir: "thick-brick-wall", named: true, prefix: "thick-brick-wall" },
thin: { dir: "thin-brick-wall", named: true, prefix: "thin-brick-wall" }
},
wood: {
thick: { dir: "thick-wood-wall", named: false, prefix: "thick-stone-wall" },
thin: { dir: "thin-wood-wall", named: false, prefix: "thin-stone-wall" }
},
cliff: {
thick: { dir: "thick-cliff", named: true, prefix: "thick-cliff" },
thin: { dir: "thin-cliff", named: true, prefix: "thin-cliff" }
}
};
function shapeFiles (shapeKey)
{
return readdirSync(EXAMPLES)
.filter((name) => name.startsWith(shapeKey) && name.endsWith(".png") && !name.includes("ref-"))
.sort();
}
function namedOutName (outPrefix, shapeName, shapeKey)
{
// thick-stone-wall-esw.png → thick-smooth-stone-wall-esw.png
const suffix = shapeName.slice(shapeKey.length); // "" or "-esw"
return `${outPrefix}${suffix}`;
}
function bakeVariant (variant)
{
const cfg = VARIANT_OUT[variant];
if (!cfg)
{ throw new Error(`Unknown variant: ${variant}`); }
let wrote = 0;
for (const kind of ["thick", "thin"])
{
const shapeKey = `${kind}-stone-wall`;
const out = cfg[kind];
const outDir = join(ROOT, out.dir);
mkdirSync(outDir, { recursive: true });
const files = shapeFiles(shapeKey);
if (files.length !== 16)
{ throw new Error(`Expected 16 ${shapeKey} masks, found ${files.length}`); }
if (out.named)
{
for (const name of files)
{
const shaped = decodePngRgba(join(EXAMPLES, name));
const textured = textureMask(shaped, variant, shapeKey);
const outName = namedOutName(out.prefix, name, shapeKey);
writeFileSync(join(outDir, outName), encodePng(textured));
wrote++;
}
}
else
{
// Material-connect: write 0.png … 15.png from matching named shapes.
for (let mask = 0; mask < 16; mask++)
{
const suffix = cardinalConnectionSuffix(mask);
const shapeName = suffix ? `${shapeKey}-${suffix}.png` : `${shapeKey}.png`;
const shaped = decodePngRgba(join(EXAMPLES, shapeName));
const textured = textureMask(shaped, variant, shapeKey);
writeFileSync(join(outDir, `${mask}.png`), encodePng(textured));
wrote++;
}
}
console.log(` ${variant} ${kind} → ${outDir} (${out.named ? "named" : "0–15"})`);
}
return wrote;
}
const arg = process.argv.find((a) => a.startsWith("--variant="));
const variant = arg ? arg.slice("--variant=".length) : "cobble";
const list = variant === "all"
? ["cobble", "smooth", "brick", "wood", "cliff"]
: [variant];
if (!existsSync(EXAMPLES))
{ throw new Error(`Missing ${EXAMPLES}`); }
let total = 0;
for (const v of list)
{
console.log(`Baking ${v}…`);
total += bakeVariant(v);
}
console.log(`Done (${total} sprites).`);
@@ -0,0 +1,492 @@/** * Bake wall textures onto thick/thin greyscale face-id shape masks. * * Shapes (source of truth): * client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png * * Usage: * node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff * node client/scripts/texture-wall-sprites.mjs --variant=all * * cobble → thick-stone-wall / thin-stone-wall (named) * smooth → thick-smooth-stone-wall / thin-smooth-stone-wall (named) * brick → thick-brick-wall / thin-brick-wall (named) * wood → thick-wood-wall / thin-wood-wall (magenta masks 0–15) * cliff → thick-cliff / thin-cliff (dirt sides + magenta top, named) */import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";import { deflateSync, inflateSync } from "node:zlib";import { fileURLToPath } from "node:url";import { dirname, join } from "node:path";import { cardinalConnectionSuffix } from "../../shared/world/neighborConnect.js";const SIZE = 16;const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");const EXAMPLES = join(ROOT, "_examples/stone-wall");const GROUNDS = join(dirname(fileURLToPath(import.meta.url)), "../assets/grounds");const THICK_ROLE = { 0xaf: "N", 0x95: "W", 0x80: "T", 0x6c: "E", 0x54: "S", 0x40: "O"};const THIN_ROLE = { 0xb6: "W", 0x95: "N", 0x80: "E", 0x73: "S", 0x40: "O"};function roleOf (prefix, g){ const map = prefix.startsWith("thin") ? THIN_ROLE : THICK_ROLE; return map[g] ?? null;}function isTopRole (role){ return role === "T" || role === "N";}function crcTable (){ const table = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) { c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); } table[n] = c >>> 0; } return table;}const CRC_TABLE = crcTable();function crc32 (buf){ let c = 0xffffffff; for (let i = 0; i < buf.length; i++) { c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); } return (c ^ 0xffffffff) >>> 0;}function chunk (type, data){ const len = Buffer.alloc(4); len.writeUInt32BE(data.length); const typeBuf = Buffer.from(type, "ascii"); const crcBuf = Buffer.alloc(4); crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data]))); return Buffer.concat([len, typeBuf, data, crcBuf]);}function encodePng (rgba){ const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE); for (let y = 0; y < SIZE; y++) { const row = y * (SIZE * 4 + 1); raw[row] = 0; for (let x = 0; x < SIZE; x++) { const i = (y * SIZE + x) * 4; const o = row + 1 + x * 4; raw[o] = rgba[i]; raw[o + 1] = rgba[i + 1]; raw[o + 2] = rgba[i + 2]; raw[o + 3] = rgba[i + 3]; } } const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(SIZE, 0); ihdr.writeUInt32BE(SIZE, 4); ihdr[8] = 8; ihdr[9] = 6; return Buffer.concat([ Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", ihdr), chunk("IDAT", deflateSync(raw, { level: 9 })), chunk("IEND", Buffer.alloc(0)) ]);}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); } else if (type === "IDAT") { idat.push(data); } else if (type === "IEND") { break; } off += 12 + len; } const inflated = inflateSync(Buffer.concat(idat)); const rgba = new Uint8Array(w * h * 4); const bpp = 4; let src = 0; for (let y = 0; y < h; y++) { const filter = inflated[src++]; const row = inflated.subarray(src, src + w * bpp); src += w * bpp; const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null; const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp); for (let i = 0; i < row.length; i++) { let v = row[i]; if (filter === 1) { v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; } else if (filter === 2) { v = (v + (prev ? prev[i] : 0)) & 255; } else if (filter === 3) { const a = i >= bpp ? out[i - bpp] : 0; const b = prev ? prev[i] : 0; v = (v + Math.floor((a + b) / 2)) & 255; } else if (filter === 4) { const a = i >= bpp ? out[i - bpp] : 0; const b = prev ? prev[i] : 0; const c = prev && i >= bpp ? prev[i - bpp] : 0; const p = a + b - c; const pa = Math.abs(p - a); const pb = Math.abs(p - b); const pc = Math.abs(p - c); v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255; } out[i] = v; } } if (w !== SIZE || h !== SIZE) { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); } return rgba;}function hash2 (x, y){ let n = (x * 374761393 + y * 668265263) | 0; n = (n ^ (n >>> 13)) * 1274126177; return (n ^ (n >>> 16)) >>> 0;}function rgba (r, g, b, a = 255){ return [r, g, b, a];}function mulRgb (c, factor){ return rgba( Math.min(255, Math.round(c[0] * factor)), Math.min(255, Math.round(c[1] * factor)), Math.min(255, Math.round(c[2] * factor)), c[3] ?? 255 );}function mixRgb (a, b, t){ return rgba( Math.round(a[0] + (b[0] - a[0]) * t), Math.round(a[1] + (b[1] - a[1]) * t), Math.round(a[2] + (b[2] - a[2]) * t), 255 );}/** Face role → lighting factor (NW light). */const ROLE_LIT = { N: 1.15, W: 1.0, T: 1.05, E: 0.82, S: 0.62, O: 0.45 };function faceLit (role){ return ROLE_LIT[role] ?? 0.9;}function loadDirt (){ const path = join(GROUNDS, "dirt/dirt.png"); if (!existsSync(path)) { throw new Error(`Missing dirt texture: ${path}`); } return decodePngRgba(path);}let dirtRgba = null;function dirtAt (x, y){ if (!dirtRgba) { dirtRgba = loadDirt(); } const i = ((y & 15) * SIZE + (x & 15)) * 4; return rgba(dirtRgba[i], dirtRgba[i + 1], dirtRgba[i + 2]);}/* ---- palettes ---- */const COBBLE = { N: rgba(198, 198, 202), W: rgba(132, 132, 136), T: rgba(168, 168, 172), E: rgba(112, 112, 116), S: rgba(88, 88, 92), O: rgba(70, 70, 74), mortar: rgba(78, 78, 82), hiN: rgba(210, 210, 214), loS: rgba(78, 78, 82)};const BRICK = { N: rgba(196, 92, 72), W: rgba(168, 72, 56), T: rgba(178, 78, 60), E: rgba(148, 58, 46), S: rgba(118, 48, 38), O: rgba(72, 36, 30), mortar: rgba(92, 78, 68), hi: rgba(210, 110, 88), lo: rgba(100, 42, 34)};function cobbleLike (basePal, x, y, role, gritMask){ if (role === "O") { const h = hash2(x, y); return (h & 15) === 0 ? basePal.mortar : basePal.O; } const base = basePal[role] ?? basePal.T; const h = hash2(x, y); const speck = h & gritMask; if (speck === 0) { return basePal.mortar; } if (gritMask === 7) { if (speck === 1 || speck === 2) { return role === "N" || role === "T" ? (basePal.hiN ?? basePal.hi ?? mulRgb(base, 1.12)) : (basePal.hi ?? mulRgb(base, 1.1)); } if (speck === 3) { return role === "S" ? (basePal.loS ?? basePal.lo ?? mulRgb(base, 0.88)) : (basePal.lo ?? mulRgb(base, 0.9)); } } else if (gritMask === 31) { // Smooth: rare soft variation only. if (speck === 1) { return mulRgb(base, 1.06); } if (speck === 2) { return mulRgb(base, 0.94); } } return base;}function brickShade (x, y, role){ if (role === "O") { return BRICK.O; } const row = Math.floor(y / 4); const brickX = x + (row & 1) * 3; const onHMortar = (y % 4) === 0; const onVMortar = (brickX % 6) === 0; if (onHMortar || onVMortar) { return BRICK.mortar; } const h = hash2(x, y); if ((h & 15) === 0) { return BRICK.hi; } if ((h & 15) === 1) { return BRICK.lo; } return BRICK[role] ?? BRICK.T;}function woodMagenta (role){ // R≈B, G<R — lightness encodes face. const L = { O: 55, S: 95, E: 120, W: 155, T: 185, N: 210 }[role] ?? 140; const gHi = role === "N" || role === "T" ? Math.min(L - 20, 50) : 0; return rgba(L, gHi, L);}function cliffShade (x, y, role){ if (isTopRole(role)) { // Full magenta top — replaced in-game by ground sample shader. return rgba(255, 0, 255); } if (role === "O") { const d = dirtAt(x, y); return mulRgb(d, 0.35); } const d = dirtAt(x, y); return mulRgb(d, faceLit(role));}function paintPixel (variant, prefix, g, x, y){ const role = roleOf(prefix, g); if (!role) { // Unknown grey: luminance fallback toward mid face. const lit = g / 128; if (variant === "wood") { return rgba(Math.round(140 * lit), 0, Math.round(140 * lit)); } if (variant === "cliff") { return mulRgb(dirtAt(x, y), lit); } if (variant === "brick") { return mulRgb(BRICK.T, lit); } return mulRgb(COBBLE.T, lit); } if (variant === "cobble") { return cobbleLike(COBBLE, x, y, role, 7); } if (variant === "smooth") { return cobbleLike(COBBLE, x, y, role, 31); } if (variant === "brick") { return brickShade(x, y, role); } if (variant === "wood") { return woodMagenta(role); } if (variant === "cliff") { return cliffShade(x, y, role); } throw new Error(`Unknown variant ${variant}`);}function textureMask (rgbaIn, variant, shapePrefix){ const out = new Uint8Array(SIZE * SIZE * 4); for (let y = 0; y < SIZE; y++) { for (let x = 0; x < SIZE; x++) { const i = (y * SIZE + x) * 4; if (rgbaIn[i + 3] === 0) { continue; } const color = paintPixel(variant, shapePrefix, rgbaIn[i], x, y); out[i] = color[0]; out[i + 1] = color[1]; out[i + 2] = color[2]; out[i + 3] = 255; } } return out;}const VARIANT_OUT = { cobble: { thick: { dir: "thick-stone-wall", named: true, prefix: "thick-stone-wall" }, thin: { dir: "thin-stone-wall", named: true, prefix: "thin-stone-wall" } }, smooth: { thick: { dir: "thick-smooth-stone-wall", named: true, prefix: "thick-smooth-stone-wall" }, thin: { dir: "thin-smooth-stone-wall", named: true, prefix: "thin-smooth-stone-wall" } }, brick: { thick: { dir: "thick-brick-wall", named: true, prefix: "thick-brick-wall" }, thin: { dir: "thin-brick-wall", named: true, prefix: "thin-brick-wall" } }, wood: { thick: { dir: "thick-wood-wall", named: false, prefix: "thick-stone-wall" }, thin: { dir: "thin-wood-wall", named: false, prefix: "thin-stone-wall" } }, cliff: { thick: { dir: "thick-cliff", named: true, prefix: "thick-cliff" }, thin: { dir: "thin-cliff", named: true, prefix: "thin-cliff" } }};function shapeFiles (shapeKey){ return readdirSync(EXAMPLES) .filter((name) => name.startsWith(shapeKey) && name.endsWith(".png") && !name.includes("ref-")) .sort();}function namedOutName (outPrefix, shapeName, shapeKey){ // thick-stone-wall-esw.png → thick-smooth-stone-wall-esw.png const suffix = shapeName.slice(shapeKey.length); // "" or "-esw" return `${outPrefix}${suffix}`;}function bakeVariant (variant){ const cfg = VARIANT_OUT[variant]; if (!cfg) { throw new Error(`Unknown variant: ${variant}`); } let wrote = 0; for (const kind of ["thick", "thin"]) { const shapeKey = `${kind}-stone-wall`; const out = cfg[kind]; const outDir = join(ROOT, out.dir); mkdirSync(outDir, { recursive: true }); const files = shapeFiles(shapeKey); if (files.length !== 16) { throw new Error(`Expected 16 ${shapeKey} masks, found ${files.length}`); } if (out.named) { for (const name of files) { const shaped = decodePngRgba(join(EXAMPLES, name)); const textured = textureMask(shaped, variant, shapeKey); const outName = namedOutName(out.prefix, name, shapeKey); writeFileSync(join(outDir, outName), encodePng(textured)); wrote++; } } else { // Material-connect: write 0.png … 15.png from matching named shapes. for (let mask = 0; mask < 16; mask++) { const suffix = cardinalConnectionSuffix(mask); const shapeName = suffix ? `${shapeKey}-${suffix}.png` : `${shapeKey}.png`; const shaped = decodePngRgba(join(EXAMPLES, shapeName)); const textured = textureMask(shaped, variant, shapeKey); writeFileSync(join(outDir, `${mask}.png`), encodePng(textured)); wrote++; } } console.log(` ${variant} ${kind} → ${outDir} (${out.named ? "named" : "0–15"})`); } return wrote;}const arg = process.argv.find((a) => a.startsWith("--variant="));const variant = arg ? arg.slice("--variant=".length) : "cobble";const list = variant === "all" ? ["cobble", "smooth", "brick", "wood", "cliff"] : [variant];if (!existsSync(EXAMPLES)){ throw new Error(`Missing ${EXAMPLES}`); }let total = 0;for (const v of list){ console.log(`Baking ${v}…`); total += bakeVariant(v);}console.log(`Done (${total} sprites).`);@@ -22,6 +22,9 @@ test("sprite folders expose alphabetical states; first is default", () =>
assert.equal(catalog.blocks["thin-stone-wall"].defaultState, "thin-stone-wall");
assert.equal(catalog.blocks["thin-stone-wall"].states.length, 16);
assert.ok(catalog.images.some((image) => image.name === "block:thin-stone-wall:thin-stone-wall-wne"));
assert.equal(catalog.blocks["thick-smooth-stone-wall"].states.length, 16);
assert.equal(catalog.blocks["thin-smooth-stone-wall"].states.length, 16);
assert.ok(catalog.images.some((image) => image.name === "block:thick-smooth-stone-wall:thick-smooth-stone-wall"));
assert.equal(catalog.images[0].subImgTotal, 1);
assert.equal(catalog.images[0].perRow, 1);
});
@@ -22,6 +22,9 @@ test("sprite folders expose alphabetical states; first is default", () => assert.equal(catalog.blocks["thin-stone-wall"].defaultState, "thin-stone-wall"); assert.equal(catalog.blocks["thin-stone-wall"].defaultState, "thin-stone-wall"); assert.equal(catalog.blocks["thin-stone-wall"].states.length, 16); assert.equal(catalog.blocks["thin-stone-wall"].states.length, 16); assert.ok(catalog.images.some((image) => image.name === "block:thin-stone-wall:thin-stone-wall-wne")); assert.ok(catalog.images.some((image) => image.name === "block:thin-stone-wall:thin-stone-wall-wne")); assert.equal(catalog.blocks["thick-smooth-stone-wall"].states.length, 16); assert.equal(catalog.blocks["thin-smooth-stone-wall"].states.length, 16); assert.ok(catalog.images.some((image) => image.name === "block:thick-smooth-stone-wall:thick-smooth-stone-wall")); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].perRow, 1); assert.equal(catalog.images[0].perRow, 1);});});