Add wood-tiered neighbor-connect fences.
Fences autotile like tables per wood material; magenta placeholder sprites cover all 16 connection masks.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -0,0 +1,190 @@
/**
* Generate 16×16 magenta wooden fence PNGs for neighbor-connect masks 0–15.
* Top-down posts + dual rails; rails extend to tile edges where connected so
* adjacent same-wood fences read as one continuous run (same as tables).
*/
import { mkdirSync, writeFileSync } from "node:fs";
import { deflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { NeighborBit } from "../../shared/world/neighborConnect.js";
const SIZE = 16;
const OUT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks/fence");
/** Magenta tint family (R≈B, G<R) — catalog tints per wood tier. */
const POST = [120, 28, 120, 255];
const POST_LIGHT = [170, 45, 170, 255];
const POST_SHADE = [90, 18, 90, 255];
const RAIL = [200, 55, 200, 255];
const RAIL_LIGHT = [230, 75, 230, 255];
const RAIL_SHADE = [150, 35, 150, 255];
const POST_X0 = 6;
const POST_X1 = 9;
const POST_Y0 = 4;
const POST_Y1 = 12;
/** Dual horizontal rail bands (pixel y inclusive). */
const H_RAILS = Object.freeze([
Object.freeze({ y0: 6, y1: 7 }),
Object.freeze({ y0: 9, y1: 10 })
]);
/** Dual vertical rail bands (pixel x inclusive). */
const V_RAILS = Object.freeze([
Object.freeze({ x0: 6, x1: 7 }),
Object.freeze({ x0: 9, x1: 10 })
]);
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;
ihdr[10] = 0;
ihdr[11] = 0;
ihdr[12] = 0;
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 setPx (rgba, x, y, color)
{
if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
{ return; }
const i = (y * SIZE + x) * 4;
rgba[i] = color[0];
rgba[i + 1] = color[1];
rgba[i + 2] = color[2];
rgba[i + 3] = color[3];
}
function fillRect (rgba, x0, y0, x1, y1, color)
{
for (let y = y0; y <= y1; y++)
{
for (let x = x0; x <= x1; x++)
{ setPx(rgba, x, y, color); }
}
}
function paintHorizontalRails (rgba, x0, x1)
{
for (const band of H_RAILS)
{
fillRect(rgba, x0, band.y0, x1, band.y1, RAIL);
fillRect(rgba, x0, band.y0, x1, band.y0, RAIL_LIGHT);
fillRect(rgba, x0, band.y1, x1, band.y1, RAIL_SHADE);
}
}
function paintVerticalRails (rgba, y0, y1)
{
for (const band of V_RAILS)
{
fillRect(rgba, band.x0, y0, band.x1, y1, RAIL);
fillRect(rgba, band.x0, y0, band.x0, y1, RAIL_LIGHT);
fillRect(rgba, band.x1, y0, band.x1, y1, RAIL_SHADE);
}
}
function paintPost (rgba)
{
fillRect(rgba, POST_X0, POST_Y0, POST_X1, POST_Y1, POST);
fillRect(rgba, POST_X0, POST_Y0, POST_X1, POST_Y0, POST_LIGHT);
fillRect(rgba, POST_X0, POST_Y1, POST_X1, POST_Y1, POST_SHADE);
fillRect(rgba, POST_X0, POST_Y0, POST_X0, POST_Y1, POST_SHADE);
fillRect(rgba, POST_X1, POST_Y0, POST_X1, POST_Y1, POST_LIGHT);
// Cap
fillRect(rgba, POST_X0 - 1, POST_Y0 - 1, POST_X1 + 1, POST_Y0 - 1, POST_SHADE);
fillRect(rgba, POST_X0, POST_Y0 - 1, POST_X1, POST_Y0 - 1, POST_LIGHT);
}
function paintFence (mask)
{
const rgba = new Uint8Array(SIZE * SIZE * 4);
const connectN = (mask & NeighborBit.n) !== 0;
const connectE = (mask & NeighborBit.e) !== 0;
const connectS = (mask & NeighborBit.s) !== 0;
const connectW = (mask & NeighborBit.w) !== 0;
const alone = mask === 0;
const wantH = alone || connectE || connectW;
const wantV = alone || connectN || connectS;
if (wantH)
{
const x0 = alone ? POST_X0 - 2 : (connectW ? 0 : POST_X0);
const x1 = alone ? POST_X1 + 2 : (connectE ? SIZE - 1 : POST_X1);
paintHorizontalRails(rgba, x0, x1);
}
if (wantV)
{
const y0 = alone ? POST_Y0 + 1 : (connectN ? 0 : POST_Y0);
const y1 = alone ? POST_Y1 - 1 : (connectS ? SIZE - 1 : POST_Y1);
paintVerticalRails(rgba, y0, y1);
}
paintPost(rgba);
return rgba;
}
mkdirSync(OUT, { recursive: true });
for (let mask = 0; mask < 16; mask++)
{
writeFileSync(join(OUT, `${mask}.png`), encodePng(paintFence(mask)));
}
console.log(`Wrote magenta fence sprites 0–15 to ${OUT}`);
@@ -0,0 +1,190 @@/** * Generate 16×16 magenta wooden fence PNGs for neighbor-connect masks 0–15. * Top-down posts + dual rails; rails extend to tile edges where connected so * adjacent same-wood fences read as one continuous run (same as tables). */import { mkdirSync, writeFileSync } from "node:fs";import { deflateSync } from "node:zlib";import { fileURLToPath } from "node:url";import { dirname, join } from "node:path";import { NeighborBit } from "../../shared/world/neighborConnect.js";const SIZE = 16;const OUT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks/fence");/** Magenta tint family (R≈B, G<R) — catalog tints per wood tier. */const POST = [120, 28, 120, 255];const POST_LIGHT = [170, 45, 170, 255];const POST_SHADE = [90, 18, 90, 255];const RAIL = [200, 55, 200, 255];const RAIL_LIGHT = [230, 75, 230, 255];const RAIL_SHADE = [150, 35, 150, 255];const POST_X0 = 6;const POST_X1 = 9;const POST_Y0 = 4;const POST_Y1 = 12;/** Dual horizontal rail bands (pixel y inclusive). */const H_RAILS = Object.freeze([ Object.freeze({ y0: 6, y1: 7 }), Object.freeze({ y0: 9, y1: 10 })]);/** Dual vertical rail bands (pixel x inclusive). */const V_RAILS = Object.freeze([ Object.freeze({ x0: 6, x1: 7 }), Object.freeze({ x0: 9, x1: 10 })]);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; ihdr[10] = 0; ihdr[11] = 0; ihdr[12] = 0; 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 setPx (rgba, x, y, color){ if (x < 0 || y < 0 || x >= SIZE || y >= SIZE) { return; } const i = (y * SIZE + x) * 4; rgba[i] = color[0]; rgba[i + 1] = color[1]; rgba[i + 2] = color[2]; rgba[i + 3] = color[3];}function fillRect (rgba, x0, y0, x1, y1, color){ for (let y = y0; y <= y1; y++) { for (let x = x0; x <= x1; x++) { setPx(rgba, x, y, color); } }}function paintHorizontalRails (rgba, x0, x1){ for (const band of H_RAILS) { fillRect(rgba, x0, band.y0, x1, band.y1, RAIL); fillRect(rgba, x0, band.y0, x1, band.y0, RAIL_LIGHT); fillRect(rgba, x0, band.y1, x1, band.y1, RAIL_SHADE); }}function paintVerticalRails (rgba, y0, y1){ for (const band of V_RAILS) { fillRect(rgba, band.x0, y0, band.x1, y1, RAIL); fillRect(rgba, band.x0, y0, band.x0, y1, RAIL_LIGHT); fillRect(rgba, band.x1, y0, band.x1, y1, RAIL_SHADE); }}function paintPost (rgba){ fillRect(rgba, POST_X0, POST_Y0, POST_X1, POST_Y1, POST); fillRect(rgba, POST_X0, POST_Y0, POST_X1, POST_Y0, POST_LIGHT); fillRect(rgba, POST_X0, POST_Y1, POST_X1, POST_Y1, POST_SHADE); fillRect(rgba, POST_X0, POST_Y0, POST_X0, POST_Y1, POST_SHADE); fillRect(rgba, POST_X1, POST_Y0, POST_X1, POST_Y1, POST_LIGHT); // Cap fillRect(rgba, POST_X0 - 1, POST_Y0 - 1, POST_X1 + 1, POST_Y0 - 1, POST_SHADE); fillRect(rgba, POST_X0, POST_Y0 - 1, POST_X1, POST_Y0 - 1, POST_LIGHT);}function paintFence (mask){ const rgba = new Uint8Array(SIZE * SIZE * 4); const connectN = (mask & NeighborBit.n) !== 0; const connectE = (mask & NeighborBit.e) !== 0; const connectS = (mask & NeighborBit.s) !== 0; const connectW = (mask & NeighborBit.w) !== 0; const alone = mask === 0; const wantH = alone || connectE || connectW; const wantV = alone || connectN || connectS; if (wantH) { const x0 = alone ? POST_X0 - 2 : (connectW ? 0 : POST_X0); const x1 = alone ? POST_X1 + 2 : (connectE ? SIZE - 1 : POST_X1); paintHorizontalRails(rgba, x0, x1); } if (wantV) { const y0 = alone ? POST_Y0 + 1 : (connectN ? 0 : POST_Y0); const y1 = alone ? POST_Y1 - 1 : (connectS ? SIZE - 1 : POST_Y1); paintVerticalRails(rgba, y0, y1); } paintPost(rgba); return rgba;}mkdirSync(OUT, { recursive: true });for (let mask = 0; mask < 16; mask++){ writeFileSync(join(OUT, `${mask}.png`), encodePng(paintFence(mask)));}console.log(`Wrote magenta fence sprites 0–15 to ${OUT}`);@@ -27,7 +27,7 @@ import
spriteImageName
} from "../../../shared/definitions/tileSprites.js";
import { preferredSeasonalDefaultState, typeHasSeasonalStates, isSeasonalOverlayVariant } from "../../../shared/world/season.js";
import { composeNeighborConnectState, NEIGHBOR_CONNECT_MASK_COUNT } from "../../../shared/world/neighborConnect.js";
import { composeNeighborConnectState, NEIGHBOR_CONNECT_MASK_COUNT, definitionUsesMaterialNeighborConnect } from "../../../shared/world/neighborConnect.js";
const CHARACTER_DEFINITIONS = Object.freeze({
"player-body-male": Object.freeze({ key: "player-body-male", id: "player-body-male" }),
@@ -339,9 +339,9 @@ function scanLayer (layerDir, definitions, layer, urlFolder)
blooms = nextBlooms;
}
if (layer === "block" && def.key === "table")
if (layer === "block" && definitionUsesMaterialNeighborConnect(def))
{
// Magenta mask sources `0`–`15` (+ optional artist `wood`); expand per wood tier.
// Magenta mask sources `0`–`15`; expand per wood tier (`pine-0` …).
states = [];
for (const material of WOOD_TIER_ORDER)
{
@@ -27,7 +27,7 @@ import spriteImageName spriteImageName } from "../../../shared/definitions/tileSprites.js"; } from "../../../shared/definitions/tileSprites.js";import { preferredSeasonalDefaultState, typeHasSeasonalStates, isSeasonalOverlayVariant } from "../../../shared/world/season.js";import { preferredSeasonalDefaultState, typeHasSeasonalStates, isSeasonalOverlayVariant } from "../../../shared/world/season.js";import { composeNeighborConnectState, NEIGHBOR_CONNECT_MASK_COUNT } from "../../../shared/world/neighborConnect.js";import { composeNeighborConnectState, NEIGHBOR_CONNECT_MASK_COUNT, definitionUsesMaterialNeighborConnect } from "../../../shared/world/neighborConnect.js";const CHARACTER_DEFINITIONS = Object.freeze({const CHARACTER_DEFINITIONS = Object.freeze({ "player-body-male": Object.freeze({ key: "player-body-male", id: "player-body-male" }), "player-body-male": Object.freeze({ key: "player-body-male", id: "player-body-male" }),@@ -339,9 +339,9 @@ function scanLayer (layerDir, definitions, layer, urlFolder) blooms = nextBlooms; blooms = nextBlooms; } } if (layer === "block" && def.key === "table") if (layer === "block" && definitionUsesMaterialNeighborConnect(def)) { { // Magenta mask sources `0`–`15` (+ optional artist `wood`); expand per wood tier. // Magenta mask sources `0`–`15`; expand per wood tier (`pine-0` …). states = []; states = []; for (const material of WOOD_TIER_ORDER) for (const material of WOOD_TIER_ORDER) { {@@ -40,6 +40,21 @@ test("material neighbor-connect states keep wood id and only match same material
assert.equal(neighborConnectBlocksMatch(pine, oakNeighbor, def), false);
});
test("wooden fences use the same material neighbor-connect as tables", () =>
{
const def = BLOCK_DEFINITIONS[BlockType.fence];
assert.equal(def.neighborConnect, true);
assert.equal(def.neighborConnectByMaterial, true);
assert.equal(def.passable, false);
assert.equal(def.blocksLight, false);
assert.equal(composeNeighborConnectState(def, "heartwood", 12), "heartwood-12");
const pine = { typeId: BlockType.fence, state: "pine-0" };
const pineNeighbor = { typeId: BlockType.fence, state: "pine-4" };
const oakNeighbor = { typeId: BlockType.fence, state: "oak-4" };
assert.equal(neighborConnectBlocksMatch(pine, pineNeighbor, def), true);
assert.equal(neighborConnectBlocksMatch(pine, oakNeighbor, def), false);
});
test("CE staff entries include sex labels and pickExchangeClerk returns a name", () =>
{
assert.ok(CENTRAL_EXCHANGE_STAFF.length >= 2);
@@ -40,6 +40,21 @@ test("material neighbor-connect states keep wood id and only match same material assert.equal(neighborConnectBlocksMatch(pine, oakNeighbor, def), false); assert.equal(neighborConnectBlocksMatch(pine, oakNeighbor, def), false);});});test("wooden fences use the same material neighbor-connect as tables", () =>{ const def = BLOCK_DEFINITIONS[BlockType.fence]; assert.equal(def.neighborConnect, true); assert.equal(def.neighborConnectByMaterial, true); assert.equal(def.passable, false); assert.equal(def.blocksLight, false); assert.equal(composeNeighborConnectState(def, "heartwood", 12), "heartwood-12"); const pine = { typeId: BlockType.fence, state: "pine-0" }; const pineNeighbor = { typeId: BlockType.fence, state: "pine-4" }; const oakNeighbor = { typeId: BlockType.fence, state: "oak-4" }; assert.equal(neighborConnectBlocksMatch(pine, pineNeighbor, def), true); assert.equal(neighborConnectBlocksMatch(pine, oakNeighbor, def), false);});test("CE staff entries include sex labels and pickExchangeClerk returns a name", () =>test("CE staff entries include sex labels and pickExchangeClerk returns a name", () =>{{ assert.ok(CENTRAL_EXCHANGE_STAFF.length >= 2); assert.ok(CENTRAL_EXCHANGE_STAFF.length >= 2);