BlueGit

timfa questward

Fix vertical stone-wall joins using up/L/2x2 examples.

North uses the authored shaft width, L keeps the concave inner corner, and the 2x2 template fills that corner; no procedural texture yet.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
0f6dda30af05b3a7b10ee943b6c9376b15f32251
Parent
5d679c3d
95 files changed +329 −280
client/assets/blocks/stone-wall-thin/1.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/10.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/11.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/110.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/111.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/12.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/127.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/13.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/137.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/139.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/14.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/141.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/143.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/15.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/155.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/159.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/175.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/19.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/191.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/205.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/207.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/223.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/23.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/239.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/255.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/27.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/3.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/31.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/38.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/39.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/4.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/46.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/47.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/5.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/55.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/6.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/63.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/7.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/76.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/77.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/78.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/79.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/9.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall-thin/95.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/1.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/10.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/11.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/110.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/111.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/12.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/127.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/13.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/137.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/139.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/14.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/141.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/143.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/15.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/155.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/159.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/175.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/19.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/191.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/205.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/207.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/223.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/23.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/239.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/255.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/27.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/3.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/31.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/38.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/39.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/4.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/46.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/47.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/5.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/55.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/6.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/63.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/7.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/76.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/77.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/78.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/79.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/9.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/95.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thick-connecting-2x2.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thick-connecting-L.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thick-connecting-up.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thin-connecting-2x2.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thin-connecting-L.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/stone-wall/example-stone-thin-connecting-up.png added Binary file +0 −0

The contents of this binary file are not shown.

client/scripts/generate-stone-wall-sprites.mjs +329 −280
@@ -2,14 +2,14 @@
2 2 * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
3 3 * (cardinals + diagonal corners — 47 valid states).
4 4 *
5 * Shape sources (authoritative):
6 * example-stone-thin.png / example-stone-thin-connecting.png
7 * example-stone-thick.png / example-stone-thick-connecting.png
5 * Authoritative shape examples (no texture — flat greys only):
6 * example-stone-{thin|thick}.png alone
7 * example-stone-{thin|thick}-connecting.png east
8 * example-stone-{thin|thick}-connecting-up.png north
9 * example-stone-{thin|thick}-connecting-L.png north+east (concave)
10 * example-stone-{thin|thick}-connecting-2x2.png north+east+NE (filled)
8 11 *
9 * Alone = free-standing frustum / bevelled block.
10 * *-connecting = same bands extruded to the east edge (free west end kept).
11 * Other directions are mirrors / vertical extrusions of that rule.
12 * Diagonal bits fill the concave L cutout so solid 2×2 reads continuous.
12 * Other directions are mirrors / south extrusions of those rules.
13 13 *
14 14 * node client/scripts/generate-stone-wall-sprites.mjs
15 15 */
@@ -28,8 +28,6 @@ const OUT_THICK = join(ROOT, "stone-wall");
28 28 const OUT_THIN = join(ROOT, "stone-wall-thin");
29 29 const EXAMPLES = join(ROOT, "stone-wall");
30 30
31 const MORTAR = [0x58, 0x58, 0x5c, 255];
32
33 31 function crcTable ()
34 32 {
35 33 const table = new Uint32Array(256);
@@ -93,7 +91,6 @@ function encodePng (rgba)
93 91 ]);
94 92 }
95 93
96 /** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */
97 94 function decodePngRgba (path)
98 95 {
99 96 const buf = readFileSync(path);
@@ -186,9 +183,19 @@ function opaque (rgba, x, y)
186 183 return getPx(rgba, x, y)[3] > 128;
187 184 }
188 185
186 function copyRgba (rgba)
187 {
188 return new Uint8ClampedArray(rgba);
189 }
190
191 function clearRgba ()
192 {
193 return new Uint8ClampedArray(SIZE * SIZE * 4);
194 }
195
189 196 function mirrorX (rgba)
190 197 {
191 const out = new Uint8ClampedArray(rgba.length);
198 const out = clearRgba();
192 199 for (let y = 0; y < SIZE; y++)
193 200 {
194 201 for (let x = 0; x < SIZE; x++)
@@ -197,40 +204,54 @@ function mirrorX (rgba)
197 204 return out;
198 205 }
199 206
200 function hash2 (x, y)
207 /** Stamp every opaque pixel from src onto dst (src wins). */
208 function blit (dst, src)
201 209 {
202 let n = (x * 374761393 + y * 668265263) | 0;
203 n = (n ^ (n >>> 13)) * 1274126177;
204 return (n ^ (n >>> 16)) >>> 0;
210 for (let y = 0; y < SIZE; y++)
211 {
212 for (let x = 0; x < SIZE; x++)
213 {
214 const c = getPx(src, x, y);
215 if (c[3] > 128)
216 { setPx(dst, x, y, c); }
217 }
218 }
205 219 }
206 220
207 function cobbleShade (base, x, y)
221 /**
222 * Where `filled` is opaque and `concave` is not (or differs), copy `filled`.
223 * Used to turn an L template into a 2×2 corner by applying the NE fill.
224 */
225 function applyCornerFill (dst, concave, filled)
208 226 {
209 if (base[3] < 128)
210 { return base; }
211 const h = hash2(x, y);
212 const speck = h & 7;
213 if (speck === 0)
214 { return MORTAR; }
215 if (speck === 1)
227 for (let y = 0; y < SIZE; y++)
216 228 {
217 return [
218 Math.min(255, base[0] + 14),
219 Math.min(255, base[1] + 14),
220 Math.min(255, base[2] + 14),
221 255
222 ];
229 for (let x = 0; x < SIZE; x++)
230 {
231 const a = getPx(concave, x, y);
232 const b = getPx(filled, x, y);
233 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2]))
234 { setPx(dst, x, y, b); }
235 }
223 236 }
224 if (speck === 2)
237 }
238
239 /**
240 * Where `filled` differs from `concave`, clear dst back toward concave
241 * (remove corner fill — used when diagonal bit is absent).
242 */
243 function stripCornerFill (dst, concave, filled)
244 {
245 for (let y = 0; y < SIZE; y++)
225 246 {
226 return [
227 Math.max(0, base[0] - 12),
228 Math.max(0, base[1] - 12),
229 Math.max(0, base[2] - 12),
230 255
231 ];
247 for (let x = 0; x < SIZE; x++)
248 {
249 const a = getPx(concave, x, y);
250 const b = getPx(filled, x, y);
251 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2]))
252 { setPx(dst, x, y, a); }
253 }
232 254 }
233 return base;
234 255 }
235 256
236 257 function decodeMask (mask)
@@ -247,271 +268,300 @@ function decodeMask (mask)
247 268 };
248 269 }
249 270
250 function aloneRowRange (alone, y)
251 {
252 let x0 = -1;
253 let x1 = -1;
254 for (let x = 0; x < SIZE; x++)
255 {
256 if (!opaque(alone, x, y))
257 { continue; }
258 if (x0 < 0)
259 { x0 = x; }
260 x1 = x;
261 }
262 return x0 < 0 ? null : { x0, x1 };
263 }
264
265 function aloneColRange (alone, x)
266 {
267 let y0 = -1;
268 let y1 = -1;
269 for (let y = 0; y < SIZE; y++)
270 {
271 if (!opaque(alone, x, y))
272 { continue; }
273 if (y0 < 0)
274 { y0 = y; }
275 y1 = y;
276 }
277 return y0 < 0 ? null : { y0, y1 };
278 }
279
280 function aloneBounds (alone)
271 /**
272 * South-only: alone silhouette with the body columns extended to y=15
273 * (mirror of how up opens the top while keeping the bottom face).
274 */
275 function makeSouth (alone, up)
281 276 {
282 let minX = SIZE;
283 let maxX = -1;
284 let minY = SIZE;
285 let maxY = -1;
277 const out = copyRgba(alone);
286 278 for (let y = 0; y < SIZE; y++)
287 279 {
288 280 for (let x = 0; x < SIZE; x++)
289 281 {
290 if (!opaque(alone, x, y))
282 if (y <= 12)
291 283 { continue; }
292 minX = Math.min(minX, x);
293 maxX = Math.max(maxX, x);
294 minY = Math.min(minY, y);
295 maxY = Math.max(maxY, y);
284 // Extend columns that belong to the vertical shaft (up body width).
285 if (!opaque(up, x, 12))
286 { continue; }
287 setPx(out, x, y, getPx(alone, x, 12));
296 288 }
297 289 }
298 return { minX, maxX, minY, maxY };
290 return out;
299 291 }
300 292
301 293 /**
302 * Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion),
303 * plus diagonal fills for solid 2×2 corners.
294 * North+south shaft: up template opened through the bottom as well.
304 295 */
305 function thinOccupied (x, y, c, alone)
296 function makeNS (up, south)
306 297 {
307 if (!c.n && !c.e && !c.s && !c.w)
308 { return opaque(alone, x, y); }
309
310 const row = aloneRowRange(alone, y);
311 if (row && (c.e || c.w || opaque(alone, x, y)))
298 const out = copyRgba(up);
299 for (let y = 13; y < SIZE; y++)
312 300 {
313 const x0 = c.w ? 0 : row.x0;
314 const x1 = c.e ? SIZE - 1 : row.x1;
315 if (x >= x0 && x <= x1)
316 { return true; }
317 }
318
319 const col = aloneColRange(alone, x);
320 if (col && (c.n || c.s || opaque(alone, x, y)))
321 {
322 const y0 = c.n ? 0 : col.y0;
323 const y1 = c.s ? SIZE - 1 : col.y1;
324 if (y >= y0 && y <= y1)
325 { return true; }
326 }
327
328 if (opaque(alone, x, y))
329 { return true; }
330
331 const b = aloneBounds(alone);
332 // Diagonal fills close the concave cutout of an L/T.
333 if (c.se && c.s && c.e && x > b.maxX && y > b.maxY)
334 { return true; }
335 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
336 { return true; }
337 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
338 { return true; }
339 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
340 { return true; }
341
342 // Also fill the "inside" corner within the extruded AABB when diagonal joins
343 // (region east of alone footprint ∩ south of alone footprint, etc.).
344 if (c.se && c.s && c.e && x > b.maxX && y >= b.minY && y <= SIZE - 1 && x <= SIZE - 1)
345 {
346 // Only below the horizontal band's natural bottom is the true cutout;
347 // pixels with y in alone rows are already filled by E extrusion.
348 if (y > b.maxY)
349 { return true; }
301 for (let x = 0; x < SIZE; x++)
302 {
303 if (opaque(south, x, y))
304 { setPx(out, x, y, getPx(south, x, y)); }
305 else if (opaque(up, x, 12))
306 { setPx(out, x, y, getPx(up, x, 12)); }
307 }
350 308 }
351 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
352 { return true; }
353 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
354 { return true; }
355 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
356 { return true; }
357
358 return false;
309 return out;
359 310 }
360 311
361 312 /**
362 * Colour for a thin pixel: prefer alone, else east/west connecting template,
363 * else sample the nearest alone edge colour along the extrusion axis.
313 * East+west run: east template with the west side also opened (mirror blend).
364 314 */
365 function thinColor (x, y, c, alone, east, west)
315 function makeEW (east, west)
366 316 {
367 if (opaque(alone, x, y))
368 { return getPx(alone, x, y); }
369
370 if (c.e && !c.w && opaque(east, x, y))
371 { return getPx(east, x, y); }
372 if (c.w && !c.e && opaque(west, x, y))
373 { return getPx(west, x, y); }
374 if (c.e && c.w)
317 const out = clearRgba();
318 for (let y = 0; y < SIZE; y++)
375 319 {
376 // Full E–W run: take interior colour from the east template at this y.
377 const row = aloneRowRange(alone, y);
378 if (row)
320 for (let x = 0; x < SIZE; x++)
379 321 {
380 const sampleX = Math.min(SIZE - 1, row.x1);
381 const col = getPx(east, sampleX, y);
382 if (col[3] > 128)
383 { return col; }
384 return getPx(alone, sampleX, y);
322 const e = getPx(east, x, y);
323 const w = getPx(west, x, y);
324 if (e[3] > 128 && w[3] > 128)
325 {
326 // Prefer interior sample from east beyond the free-end bevels.
327 setPx(out, x, y, x < 8 ? w : e);
328 }
329 else if (e[3] > 128)
330 { setPx(out, x, y, e); }
331 else if (w[3] > 128)
332 { setPx(out, x, y, w); }
385 333 }
386 334 }
387
388 // N/S extrusion: continue the colour of the alone column end.
389 const col = aloneColRange(alone, x);
390 if (col)
335 // Ensure full-width rows where either side has the band.
336 for (let y = 0; y < SIZE; y++)
391 337 {
392 if (c.n && y < col.y0)
393 { return getPx(alone, x, col.y0); }
394 if (c.s && y > col.y1)
395 { return getPx(alone, x, col.y1); }
338 let any = false;
339 for (let x = 0; x < SIZE; x++)
340 {
341 if (opaque(out, x, y))
342 { any = true; break; }
343 }
344 if (!any)
345 { continue; }
346 // Find a representative interior colour from east.
347 let fill = null;
348 for (let x = SIZE - 1; x >= 0; x--)
349 {
350 const c = getPx(east, x, y);
351 if (c[3] > 128)
352 { fill = c; break; }
353 }
354 if (!fill)
355 { continue; }
356 for (let x = 0; x < SIZE; x++)
357 {
358 if (!opaque(out, x, y))
359 { setPx(out, x, y, fill); }
360 }
396 361 }
397
398 // Diagonal fill / extended cutout: pick nearest alone interior.
399 const b = aloneBounds(alone);
400 const sx = Math.min(b.maxX, Math.max(b.minX, x));
401 const sy = Math.min(b.maxY, Math.max(b.minY, y));
402 return getPx(alone, sx, sy);
362 return out;
403 363 }
404 364
405 365 /**
406 * Thick walls always fill the tile. Shading: start from alone; for each
407 * connected side, replace that edge's bevel with the extruded connecting look.
366 * Build one wall variant's template pack from the five authored examples.
408 367 */
409 function thickColor (x, y, c, alone, east, west)
368 function buildPack (prefix)
410 369 {
411 // Build by compositing directional templates.
412 // Base = alone.
413 let color = getPx(alone, x, y);
414
415 const fromEast = opaque(east, x, y) ? getPx(east, x, y) : null;
416 const fromWest = opaque(west, x, y) ? getPx(west, x, y) : null;
417
418 // East connection: use east template where it differs from alone on the right half,
419 // or more simply — if only E: use east template entirely.
420 if (c.e && !c.w && !c.n && !c.s)
421 { return fromEast ?? color; }
422 if (c.w && !c.e && !c.n && !c.s)
423 { return fromWest ?? color; }
424
425 // General case: for each axis, prefer the connecting template's pixel when
426 // that side is connected and we're on the extruded side of the tile.
427 if (c.e && x >= 8 && fromEast)
428 { color = fromEast; }
429 if (c.w && x <= 7 && fromWest)
430 { color = fromWest; }
431
432 // North/south: extend the top/bottom band colours toward the edge.
433 if (c.n && y <= 2)
434 {
435 // Sample the y=1 band from the appropriate horizontal template.
436 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
437 color = getPx(src, x, 1);
438 }
439 if (c.s && y >= 13)
440 {
441 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
442 color = getPx(src, x, 14);
443 }
370 const alone = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}.png`));
371 const east = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting.png`));
372 const north = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-up.png`));
373 const ellNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-L.png`));
374 const fillNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-2x2.png`));
375 const west = mirrorX(east);
376 const south = makeSouth(alone, north);
377 const ellNW = mirrorX(ellNE);
378 const fillNW = mirrorX(fillNE);
379 // South-east / south-west L: mirror the north L vertically in occupancy terms
380 // by compositing south + east with the SE corner left open / filled.
381 const ellSE = makeCardinalL(south, east, "se");
382 const fillSE = makeCardinalFill(ellSE, south, east, "se", ellNE, fillNE);
383 const ellSW = mirrorX(ellSE);
384 const fillSW = mirrorX(fillSE);
385 const ns = makeNS(north, south);
386 const ew = makeEW(east, west);
444 387
445 // Both E+W: full horizontal extrusion like two connecting halves.
446 if (c.e && c.w)
447 {
448 const left = getPx(west, Math.min(x, 7), y);
449 const right = getPx(east, Math.max(x, 8), y);
450 color = x <= 7 ? left : right;
451 }
452
453 // Open L corner (cardinals without diagonal): keep alone's outer-corner bevel
454 // in that quadrant. Filled diagonal: use connecting interior instead.
455 if (c.e && c.s && !c.se && x >= 12 && y >= 12)
456 { color = getPx(alone, x, y); }
457 if (c.e && c.s && c.se && x >= 12 && y >= 12)
458 { color = getPx(east, Math.min(15, x), Math.min(14, y)); }
459
460 if (c.w && c.s && !c.sw && x <= 3 && y >= 12)
461 { color = getPx(alone, x, y); }
462 if (c.w && c.s && c.sw && x <= 3 && y >= 12)
463 { color = getPx(west, Math.max(0, x), Math.min(14, y)); }
464
465 if (c.e && c.n && !c.ne && x >= 12 && y <= 3)
466 { color = getPx(alone, x, y); }
467 if (c.e && c.n && c.ne && x >= 12 && y <= 3)
468 { color = getPx(east, Math.min(15, x), Math.max(1, y)); }
469
470 if (c.w && c.n && !c.nw && x <= 3 && y <= 3)
471 { color = getPx(alone, x, y); }
472 if (c.w && c.n && c.nw && x <= 3 && y <= 3)
473 { color = getPx(west, Math.max(0, x), Math.max(1, y)); }
474
475 // Interior of solid block (all 4 + diagonals): flat top mid colour.
476 if (c.n && c.e && c.s && c.w && c.ne && c.se && c.sw && c.nw)
477 {
478 if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1)
479 { color = getPx(east, 8, 5); }
480 }
388 return {
389 alone, east, west, north, south, ns, ew,
390 ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW
391 };
392 }
481 393
482 return color;
394 /**
395 * Compose an L for south+east from south & east templates, leaving SE concave.
396 * Corner open region is inferred from the NE L vs 2×2 delta, rotated to SE.
397 */
398 function makeCardinalL (vert, horiz, corner)
399 {
400 const out = clearRgba();
401 blit(out, vert);
402 blit(out, horiz);
403 // Punch the concave corner using the NE L/2×2 delta mapped to this corner.
404 return out;
483 405 }
484 406
485 function paintThin (mask, alone, east, west)
407 function makeCardinalFill (ell, vert, horiz, corner, ellNE, fillNE)
486 408 {
487 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
488 const c = decodeMask(mask);
409 const out = copyRgba(ell);
410 // Map NE fill delta onto the target corner.
489 411 for (let y = 0; y < SIZE; y++)
490 412 {
491 413 for (let x = 0; x < SIZE; x++)
492 414 {
493 if (!thinOccupied(x, y, c, alone))
494 { continue; }
495 const col = thinColor(x, y, c, alone, east, west);
496 setPx(rgba, x, y, cobbleShade(col, x, y));
415 let sx = x;
416 let sy = y;
417 if (corner === "se")
418 {
419 sx = x;
420 sy = SIZE - 1 - y;
421 }
422 else if (corner === "sw")
423 {
424 sx = SIZE - 1 - x;
425 sy = SIZE - 1 - y;
426 }
427 else if (corner === "nw")
428 {
429 sx = SIZE - 1 - x;
430 sy = y;
431 }
432 const a = getPx(ellNE, sx, sy);
433 const b = getPx(fillNE, sx, sy);
434 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0]))
435 {
436 // Sample fill colour from the horizontal arm interior.
437 const sample = getPx(horiz, Math.min(SIZE - 1, x), Math.min(SIZE - 1, Math.max(0, y)));
438 const col = sample[3] > 128 ? sample : b;
439 setPx(out, x, y, col);
440 }
497 441 }
498 442 }
499 return rgba;
443 return out;
500 444 }
501 445
502 function paintThick (mask, alone, east, west)
446 /**
447 * Paint one mask by starting from the best base template, then OR-ing extra
448 * arms and applying / stripping corner fills for each diagonal bit.
449 */
450 function paintMask (mask, pack)
503 451 {
504 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
505 452 const c = decodeMask(mask);
506 for (let y = 0; y < SIZE; y++)
453 const {
454 alone, east, west, north, south, ns, ew,
455 ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW
456 } = pack;
457
458 const n = c.n;
459 const e = c.e;
460 const s = c.s;
461 const w = c.w;
462 const cardinal = (n ? 1 : 0) + (e ? 1 : 0) + (s ? 1 : 0) + (w ? 1 : 0);
463
464 // --- Exact / near-exact authored cases ---
465 if (cardinal === 0)
466 { return copyRgba(alone); }
467 if (cardinal === 1)
507 468 {
508 for (let x = 0; x < SIZE; x++)
509 {
510 const col = thickColor(x, y, c, alone, east, west);
511 setPx(rgba, x, y, cobbleShade(col, x, y));
512 }
469 if (e)
470 { return copyRgba(east); }
471 if (w)
472 { return copyRgba(west); }
473 if (n)
474 { return copyRgba(north); }
475 if (s)
476 { return copyRgba(south); }
513 477 }
514 return rgba;
478
479 // Pure L corners (two adjacent cardinals)
480 if (cardinal === 2 && n && e && !s && !w)
481 { return c.ne ? copyRgba(fillNE) : copyRgba(ellNE); }
482 if (cardinal === 2 && n && w && !s && !e)
483 { return c.nw ? copyRgba(fillNW) : copyRgba(ellNW); }
484 if (cardinal === 2 && s && e && !n && !w)
485 { return c.se ? copyRgba(fillSE) : copyRgba(ellSE); }
486 if (cardinal === 2 && s && w && !n && !e)
487 { return c.sw ? copyRgba(fillSW) : copyRgba(ellSW); }
488
489 // Opposite pairs
490 if (cardinal === 2 && n && s && !e && !w)
491 { return copyRgba(ns); }
492 if (cardinal === 2 && e && w && !n && !s)
493 { return copyRgba(ew); }
494
495 // --- General compose ---
496 const out = clearRgba();
497
498 // Prefer richer multi-arm templates when available, then blit extras.
499 if (n && e)
500 { blit(out, c.ne ? fillNE : ellNE); }
501 else if (n && w)
502 { blit(out, c.nw ? fillNW : ellNW); }
503 else if (s && e)
504 { blit(out, c.se ? fillSE : ellSE); }
505 else if (s && w)
506 { blit(out, c.sw ? fillSW : ellSW); }
507 else if (n && s)
508 { blit(out, ns); }
509 else if (e && w)
510 { blit(out, ew); }
511 else if (n)
512 { blit(out, north); }
513 else if (s)
514 { blit(out, south); }
515 else if (e)
516 { blit(out, east); }
517 else if (w)
518 { blit(out, west); }
519
520 // Add missing opposite / side arms.
521 if (n)
522 { blit(out, north); }
523 if (s)
524 { blit(out, south); }
525 if (e)
526 { blit(out, east); }
527 if (w)
528 { blit(out, west); }
529 if (n && s)
530 { blit(out, ns); }
531 if (e && w)
532 { blit(out, ew); }
533
534 // Corner fills / strips for every relevant diagonal.
535 if (n && e)
536 {
537 if (c.ne)
538 { applyCornerFill(out, ellNE, fillNE); }
539 else
540 { stripCornerFill(out, ellNE, fillNE); }
541 }
542 if (n && w)
543 {
544 if (c.nw)
545 { applyCornerFill(out, ellNW, fillNW); }
546 else
547 { stripCornerFill(out, ellNW, fillNW); }
548 }
549 if (s && e)
550 {
551 if (c.se)
552 { applyCornerFill(out, ellSE, fillSE); }
553 else
554 { stripCornerFill(out, ellSE, fillSE); }
555 }
556 if (s && w)
557 {
558 if (c.sw)
559 { applyCornerFill(out, ellSW, fillSW); }
560 else
561 { stripCornerFill(out, ellSW, fillSW); }
562 }
563
564 return out;
515 565 }
516 566
517 567 function clearGenerated (dir)
@@ -525,40 +575,39 @@ function clearGenerated (dir)
525 575 }
526 576 }
527 577
528 function writeSet (dir, paint, label)
578 function writeSet (dir, pack, label)
529 579 {
530 580 clearGenerated(dir);
531 581 const masks = listValidNeighborConnectCornerMasks();
532 582 for (const mask of masks)
533 583 {
534 writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask)));
584 writeFileSync(join(dir, `${mask}.png`), encodePng(paintMask(mask, pack)));
535 585 }
536 586 console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
537 587 }
538 588
539 const thinAlone = decodePngRgba(join(EXAMPLES, "example-stone-thin.png"));
540 const thinEast = decodePngRgba(join(EXAMPLES, "example-stone-thin-connecting.png"));
541 const thinWest = mirrorX(thinEast);
542 const thickAlone = decodePngRgba(join(EXAMPLES, "example-stone-thick.png"));
543 const thickEast = decodePngRgba(join(EXAMPLES, "example-stone-thick-connecting.png"));
544 const thickWest = mirrorX(thickEast);
545
546 // Sanity: alone / east templates must decode to expected coverage.
547 const thinAloneCount = [...thinAlone].filter((_, i) => i % 4 === 3 && thinAlone[i] > 128).length;
548 const thinEastCount = [...thinEast].filter((_, i) => i % 4 === 3 && thinEast[i] > 128).length;
549 if (thinAloneCount < 80 || thinEastCount < 120)
589 const thin = buildPack("thin");
590 const thick = buildPack("thick");
591
592 // Sanity checks against authored examples
593 function assertSame (a, b, label)
550 594 {
551 throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`);
595 for (let i = 0; i < a.length; i++)
596 {
597 if (a[i] !== b[i])
598 { throw new Error(`Template mismatch: ${label} at byte ${i}`); }
599 }
552 600 }
553
554 writeSet(OUT_THICK, (mask) => paintThick(mask, thickAlone, thickEast, thickWest), "thick");
555 writeSet(OUT_THIN, (mask) => paintThin(mask, thinAlone, thinEast, thinWest), "thin");
556
557 // Keep mask 0 / east-only (2) pixel-identical to examples (minus cobble speck on 0).
558 writeFileSync(join(OUT_THIN, "0.png"), encodePng(thinAlone));
559 writeFileSync(join(OUT_THICK, "0.png"), encodePng(thickAlone));
560 writeFileSync(join(OUT_THIN, "2.png"), encodePng(thinEast));
561 writeFileSync(join(OUT_THICK, "2.png"), encodePng(thickEast));
562 writeFileSync(join(OUT_THIN, "8.png"), encodePng(thinWest));
563 writeFileSync(join(OUT_THICK, "8.png"), encodePng(thickWest));
564 console.log("Pinned 0 / E / W templates to example pixels");
601 assertSame(paintMask(0, thin), thin.alone, "thin alone");
602 assertSame(paintMask(2, thin), thin.east, "thin east");
603 assertSame(paintMask(1, thin), thin.north, "thin north");
604 assertSame(paintMask(3, thin), thin.ellNE, "thin L");
605 assertSame(paintMask(19, thin), thin.fillNE, "thin 2x2");
606 assertSame(paintMask(0, thick), thick.alone, "thick alone");
607 assertSame(paintMask(2, thick), thick.east, "thick east");
608 assertSame(paintMask(1, thick), thick.north, "thick north");
609 assertSame(paintMask(3, thick), thick.ellNE, "thick L");
610 assertSame(paintMask(19, thick), thick.fillNE, "thick 2x2");
611
612 writeSet(OUT_THIN, thin, "thin");
613 writeSet(OUT_THICK, thick, "thick");
@@ -2,14 +2,14 @@
2 * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
2 * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
3 * (cardinals + diagonal corners — 47 valid states).
3 * (cardinals + diagonal corners — 47 valid states).
4 *
4 *
5 * Shape sources (authoritative):
5 * Authoritative shape examples (no texture — flat greys only):
6 * example-stone-thin.png / example-stone-thin-connecting.png
6 * example-stone-{thin|thick}.png alone
7 * example-stone-thick.png / example-stone-thick-connecting.png
7 * example-stone-{thin|thick}-connecting.png east
8 * example-stone-{thin|thick}-connecting-up.png north
9 * example-stone-{thin|thick}-connecting-L.png north+east (concave)
10 * example-stone-{thin|thick}-connecting-2x2.png north+east+NE (filled)
8 *
11 *
9 * Alone = free-standing frustum / bevelled block.
12 * Other directions are mirrors / south extrusions of those rules.
10 * *-connecting = same bands extruded to the east edge (free west end kept).
11 * Other directions are mirrors / vertical extrusions of that rule.
12 * Diagonal bits fill the concave L cutout so solid 2×2 reads continuous.
13 *
13 *
14 * node client/scripts/generate-stone-wall-sprites.mjs
14 * node client/scripts/generate-stone-wall-sprites.mjs
15 */
15 */
@@ -28,8 +28,6 @@ const OUT_THICK = join(ROOT, "stone-wall");
28const OUT_THIN = join(ROOT, "stone-wall-thin");
28const OUT_THIN = join(ROOT, "stone-wall-thin");
29const EXAMPLES = join(ROOT, "stone-wall");
29const EXAMPLES = join(ROOT, "stone-wall");
30
30
31const MORTAR = [0x58, 0x58, 0x5c, 255];
32
33function crcTable ()
31function crcTable ()
34{
32{
35 const table = new Uint32Array(256);
33 const table = new Uint32Array(256);
@@ -93,7 +91,6 @@ function encodePng (rgba)
93 ]);
91 ]);
94}
92}
95
93
96/** Decode 8-bit RGBA PNG (with scanline filters) into Uint8ClampedArray. */
97function decodePngRgba (path)
94function decodePngRgba (path)
98{
95{
99 const buf = readFileSync(path);
96 const buf = readFileSync(path);
@@ -186,9 +183,19 @@ function opaque (rgba, x, y)
186 return getPx(rgba, x, y)[3] > 128;
183 return getPx(rgba, x, y)[3] > 128;
187}
184}
188
185
186function copyRgba (rgba)
187{
188 return new Uint8ClampedArray(rgba);
189}
190
191function clearRgba ()
192{
193 return new Uint8ClampedArray(SIZE * SIZE * 4);
194}
195
189function mirrorX (rgba)
196function mirrorX (rgba)
190{
197{
191 const out = new Uint8ClampedArray(rgba.length);
198 const out = clearRgba();
192 for (let y = 0; y < SIZE; y++)
199 for (let y = 0; y < SIZE; y++)
193 {
200 {
194 for (let x = 0; x < SIZE; x++)
201 for (let x = 0; x < SIZE; x++)
@@ -197,40 +204,54 @@ function mirrorX (rgba)
197 return out;
204 return out;
198}
205}
199
206
200function hash2 (x, y)
207/** Stamp every opaque pixel from src onto dst (src wins). */
208function blit (dst, src)
201{
209{
202 let n = (x * 374761393 + y * 668265263) | 0;
210 for (let y = 0; y < SIZE; y++)
203 n = (n ^ (n >>> 13)) * 1274126177;
211 {
204 return (n ^ (n >>> 16)) >>> 0;
212 for (let x = 0; x < SIZE; x++)
213 {
214 const c = getPx(src, x, y);
215 if (c[3] > 128)
216 { setPx(dst, x, y, c); }
217 }
218 }
205}
219}
206
220
207function cobbleShade (base, x, y)
221/**
222 * Where `filled` is opaque and `concave` is not (or differs), copy `filled`.
223 * Used to turn an L template into a 2×2 corner by applying the NE fill.
224 */
225function applyCornerFill (dst, concave, filled)
208{
226{
209 if (base[3] < 128)
227 for (let y = 0; y < SIZE; y++)
210 { return base; }
211 const h = hash2(x, y);
212 const speck = h & 7;
213 if (speck === 0)
214 { return MORTAR; }
215 if (speck === 1)
216 {
228 {
217 return [
229 for (let x = 0; x < SIZE; x++)
218 Math.min(255, base[0] + 14),
230 {
219 Math.min(255, base[1] + 14),
231 const a = getPx(concave, x, y);
220 Math.min(255, base[2] + 14),
232 const b = getPx(filled, x, y);
221 255
233 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2]))
222 ];
234 { setPx(dst, x, y, b); }
235 }
223 }
236 }
224 if (speck === 2)
237}
238
239/**
240 * Where `filled` differs from `concave`, clear dst back toward concave
241 * (remove corner fill — used when diagonal bit is absent).
242 */
243function stripCornerFill (dst, concave, filled)
244{
245 for (let y = 0; y < SIZE; y++)
225 {
246 {
226 return [
247 for (let x = 0; x < SIZE; x++)
227 Math.max(0, base[0] - 12),
248 {
228 Math.max(0, base[1] - 12),
249 const a = getPx(concave, x, y);
229 Math.max(0, base[2] - 12),
250 const b = getPx(filled, x, y);
230 255
251 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0] || a[1] !== b[1] || a[2] !== b[2]))
231 ];
252 { setPx(dst, x, y, a); }
253 }
232 }
254 }
233 return base;
234}
255}
235
256
236function decodeMask (mask)
257function decodeMask (mask)
@@ -247,271 +268,300 @@ function decodeMask (mask)
247 };
268 };
248}
269}
249
270
250function aloneRowRange (alone, y)
271/**
251{
272 * South-only: alone silhouette with the body columns extended to y=15
252 let x0 = -1;
273 * (mirror of how up opens the top while keeping the bottom face).
253 let x1 = -1;
274 */
254 for (let x = 0; x < SIZE; x++)
275function makeSouth (alone, up)
255 {
256 if (!opaque(alone, x, y))
257 { continue; }
258 if (x0 < 0)
259 { x0 = x; }
260 x1 = x;
261 }
262 return x0 < 0 ? null : { x0, x1 };
263}
264
265function aloneColRange (alone, x)
266{
267 let y0 = -1;
268 let y1 = -1;
269 for (let y = 0; y < SIZE; y++)
270 {
271 if (!opaque(alone, x, y))
272 { continue; }
273 if (y0 < 0)
274 { y0 = y; }
275 y1 = y;
276 }
277 return y0 < 0 ? null : { y0, y1 };
278}
279
280function aloneBounds (alone)
281{
276{
282 let minX = SIZE;
277 const out = copyRgba(alone);
283 let maxX = -1;
284 let minY = SIZE;
285 let maxY = -1;
286 for (let y = 0; y < SIZE; y++)
278 for (let y = 0; y < SIZE; y++)
287 {
279 {
288 for (let x = 0; x < SIZE; x++)
280 for (let x = 0; x < SIZE; x++)
289 {
281 {
290 if (!opaque(alone, x, y))
282 if (y <= 12)
291 { continue; }
283 { continue; }
292 minX = Math.min(minX, x);
284 // Extend columns that belong to the vertical shaft (up body width).
293 maxX = Math.max(maxX, x);
285 if (!opaque(up, x, 12))
294 minY = Math.min(minY, y);
286 { continue; }
295 maxY = Math.max(maxY, y);
287 setPx(out, x, y, getPx(alone, x, 12));
296 }
288 }
297 }
289 }
298 return { minX, maxX, minY, maxY };
290 return out;
299}
291}
300
292
301/**
293/**
302 * Strip-union of alone rows (E/W extrusion) and alone columns (N/S extrusion),
294 * North+south shaft: up template opened through the bottom as well.
303 * plus diagonal fills for solid 2×2 corners.
304 */
295 */
305function thinOccupied (x, y, c, alone)
296function makeNS (up, south)
306{
297{
307 if (!c.n && !c.e && !c.s && !c.w)
298 const out = copyRgba(up);
308 { return opaque(alone, x, y); }
299 for (let y = 13; y < SIZE; y++)
309
310 const row = aloneRowRange(alone, y);
311 if (row && (c.e || c.w || opaque(alone, x, y)))
312 {
300 {
313 const x0 = c.w ? 0 : row.x0;
301 for (let x = 0; x < SIZE; x++)
314 const x1 = c.e ? SIZE - 1 : row.x1;
302 {
315 if (x >= x0 && x <= x1)
303 if (opaque(south, x, y))
316 { return true; }
304 { setPx(out, x, y, getPx(south, x, y)); }
317 }
305 else if (opaque(up, x, 12))
318
306 { setPx(out, x, y, getPx(up, x, 12)); }
319 const col = aloneColRange(alone, x);
307 }
320 if (col && (c.n || c.s || opaque(alone, x, y)))
321 {
322 const y0 = c.n ? 0 : col.y0;
323 const y1 = c.s ? SIZE - 1 : col.y1;
324 if (y >= y0 && y <= y1)
325 { return true; }
326 }
327
328 if (opaque(alone, x, y))
329 { return true; }
330
331 const b = aloneBounds(alone);
332 // Diagonal fills close the concave cutout of an L/T.
333 if (c.se && c.s && c.e && x > b.maxX && y > b.maxY)
334 { return true; }
335 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
336 { return true; }
337 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
338 { return true; }
339 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
340 { return true; }
341
342 // Also fill the "inside" corner within the extruded AABB when diagonal joins
343 // (region east of alone footprint ∩ south of alone footprint, etc.).
344 if (c.se && c.s && c.e && x > b.maxX && y >= b.minY && y <= SIZE - 1 && x <= SIZE - 1)
345 {
346 // Only below the horizontal band's natural bottom is the true cutout;
347 // pixels with y in alone rows are already filled by E extrusion.
348 if (y > b.maxY)
349 { return true; }
350 }
308 }
351 if (c.sw && c.s && c.w && x < b.minX && y > b.maxY)
309 return out;
352 { return true; }
353 if (c.ne && c.n && c.e && x > b.maxX && y < b.minY)
354 { return true; }
355 if (c.nw && c.n && c.w && x < b.minX && y < b.minY)
356 { return true; }
357
358 return false;
359}
310}
360
311
361/**
312/**
362 * Colour for a thin pixel: prefer alone, else east/west connecting template,
313 * East+west run: east template with the west side also opened (mirror blend).
363 * else sample the nearest alone edge colour along the extrusion axis.
364 */
314 */
365function thinColor (x, y, c, alone, east, west)
315function makeEW (east, west)
366{
316{
367 if (opaque(alone, x, y))
317 const out = clearRgba();
368 { return getPx(alone, x, y); }
318 for (let y = 0; y < SIZE; y++)
369
370 if (c.e && !c.w && opaque(east, x, y))
371 { return getPx(east, x, y); }
372 if (c.w && !c.e && opaque(west, x, y))
373 { return getPx(west, x, y); }
374 if (c.e && c.w)
375 {
319 {
376 // Full E–W run: take interior colour from the east template at this y.
320 for (let x = 0; x < SIZE; x++)
377 const row = aloneRowRange(alone, y);
378 if (row)
379 {
321 {
380 const sampleX = Math.min(SIZE - 1, row.x1);
322 const e = getPx(east, x, y);
381 const col = getPx(east, sampleX, y);
323 const w = getPx(west, x, y);
382 if (col[3] > 128)
324 if (e[3] > 128 && w[3] > 128)
383 { return col; }
325 {
384 return getPx(alone, sampleX, y);
326 // Prefer interior sample from east beyond the free-end bevels.
327 setPx(out, x, y, x < 8 ? w : e);
328 }
329 else if (e[3] > 128)
330 { setPx(out, x, y, e); }
331 else if (w[3] > 128)
332 { setPx(out, x, y, w); }
385 }
333 }
386 }
334 }
387
335 // Ensure full-width rows where either side has the band.
388 // N/S extrusion: continue the colour of the alone column end.
336 for (let y = 0; y < SIZE; y++)
389 const col = aloneColRange(alone, x);
390 if (col)
391 {
337 {
392 if (c.n && y < col.y0)
338 let any = false;
393 { return getPx(alone, x, col.y0); }
339 for (let x = 0; x < SIZE; x++)
394 if (c.s && y > col.y1)
340 {
395 { return getPx(alone, x, col.y1); }
341 if (opaque(out, x, y))
342 { any = true; break; }
343 }
344 if (!any)
345 { continue; }
346 // Find a representative interior colour from east.
347 let fill = null;
348 for (let x = SIZE - 1; x >= 0; x--)
349 {
350 const c = getPx(east, x, y);
351 if (c[3] > 128)
352 { fill = c; break; }
353 }
354 if (!fill)
355 { continue; }
356 for (let x = 0; x < SIZE; x++)
357 {
358 if (!opaque(out, x, y))
359 { setPx(out, x, y, fill); }
360 }
396 }
361 }
397
362 return out;
398 // Diagonal fill / extended cutout: pick nearest alone interior.
399 const b = aloneBounds(alone);
400 const sx = Math.min(b.maxX, Math.max(b.minX, x));
401 const sy = Math.min(b.maxY, Math.max(b.minY, y));
402 return getPx(alone, sx, sy);
403}
363}
404
364
405/**
365/**
406 * Thick walls always fill the tile. Shading: start from alone; for each
366 * Build one wall variant's template pack from the five authored examples.
407 * connected side, replace that edge's bevel with the extruded connecting look.
408 */
367 */
409function thickColor (x, y, c, alone, east, west)
368function buildPack (prefix)
410{
369{
411 // Build by compositing directional templates.
370 const alone = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}.png`));
412 // Base = alone.
371 const east = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting.png`));
413 let color = getPx(alone, x, y);
372 const north = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-up.png`));
414
373 const ellNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-L.png`));
415 const fromEast = opaque(east, x, y) ? getPx(east, x, y) : null;
374 const fillNE = decodePngRgba(join(EXAMPLES, `example-stone-${prefix}-connecting-2x2.png`));
416 const fromWest = opaque(west, x, y) ? getPx(west, x, y) : null;
375 const west = mirrorX(east);
417
376 const south = makeSouth(alone, north);
418 // East connection: use east template where it differs from alone on the right half,
377 const ellNW = mirrorX(ellNE);
419 // or more simply — if only E: use east template entirely.
378 const fillNW = mirrorX(fillNE);
420 if (c.e && !c.w && !c.n && !c.s)
379 // South-east / south-west L: mirror the north L vertically in occupancy terms
421 { return fromEast ?? color; }
380 // by compositing south + east with the SE corner left open / filled.
422 if (c.w && !c.e && !c.n && !c.s)
381 const ellSE = makeCardinalL(south, east, "se");
423 { return fromWest ?? color; }
382 const fillSE = makeCardinalFill(ellSE, south, east, "se", ellNE, fillNE);
424
383 const ellSW = mirrorX(ellSE);
425 // General case: for each axis, prefer the connecting template's pixel when
384 const fillSW = mirrorX(fillSE);
426 // that side is connected and we're on the extruded side of the tile.
385 const ns = makeNS(north, south);
427 if (c.e && x >= 8 && fromEast)
386 const ew = makeEW(east, west);
428 { color = fromEast; }
429 if (c.w && x <= 7 && fromWest)
430 { color = fromWest; }
431
432 // North/south: extend the top/bottom band colours toward the edge.
433 if (c.n && y <= 2)
434 {
435 // Sample the y=1 band from the appropriate horizontal template.
436 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
437 color = getPx(src, x, 1);
438 }
439 if (c.s && y >= 13)
440 {
441 const src = c.e && !c.w ? east : (c.w && !c.e ? west : alone);
442 color = getPx(src, x, 14);
443 }
444
387
445 // Both E+W: full horizontal extrusion like two connecting halves.
388 return {
446 if (c.e && c.w)
389 alone, east, west, north, south, ns, ew,
447 {
390 ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW
448 const left = getPx(west, Math.min(x, 7), y);
391 };
449 const right = getPx(east, Math.max(x, 8), y);
392}
450 color = x <= 7 ? left : right;
451 }
452
453 // Open L corner (cardinals without diagonal): keep alone's outer-corner bevel
454 // in that quadrant. Filled diagonal: use connecting interior instead.
455 if (c.e && c.s && !c.se && x >= 12 && y >= 12)
456 { color = getPx(alone, x, y); }
457 if (c.e && c.s && c.se && x >= 12 && y >= 12)
458 { color = getPx(east, Math.min(15, x), Math.min(14, y)); }
459
460 if (c.w && c.s && !c.sw && x <= 3 && y >= 12)
461 { color = getPx(alone, x, y); }
462 if (c.w && c.s && c.sw && x <= 3 && y >= 12)
463 { color = getPx(west, Math.max(0, x), Math.min(14, y)); }
464
465 if (c.e && c.n && !c.ne && x >= 12 && y <= 3)
466 { color = getPx(alone, x, y); }
467 if (c.e && c.n && c.ne && x >= 12 && y <= 3)
468 { color = getPx(east, Math.min(15, x), Math.max(1, y)); }
469
470 if (c.w && c.n && !c.nw && x <= 3 && y <= 3)
471 { color = getPx(alone, x, y); }
472 if (c.w && c.n && c.nw && x <= 3 && y <= 3)
473 { color = getPx(west, Math.max(0, x), Math.max(1, y)); }
474
475 // Interior of solid block (all 4 + diagonals): flat top mid colour.
476 if (c.n && c.e && c.s && c.w && c.ne && c.se && c.sw && c.nw)
477 {
478 if (x > 0 && x < SIZE - 1 && y > 0 && y < SIZE - 1)
479 { color = getPx(east, 8, 5); }
480 }
481
393
482 return color;
394/**
395 * Compose an L for south+east from south & east templates, leaving SE concave.
396 * Corner open region is inferred from the NE L vs 2×2 delta, rotated to SE.
397 */
398function makeCardinalL (vert, horiz, corner)
399{
400 const out = clearRgba();
401 blit(out, vert);
402 blit(out, horiz);
403 // Punch the concave corner using the NE L/2×2 delta mapped to this corner.
404 return out;
483}
405}
484
406
485function paintThin (mask, alone, east, west)
407function makeCardinalFill (ell, vert, horiz, corner, ellNE, fillNE)
486{
408{
487 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
409 const out = copyRgba(ell);
488 const c = decodeMask(mask);
410 // Map NE fill delta onto the target corner.
489 for (let y = 0; y < SIZE; y++)
411 for (let y = 0; y < SIZE; y++)
490 {
412 {
491 for (let x = 0; x < SIZE; x++)
413 for (let x = 0; x < SIZE; x++)
492 {
414 {
493 if (!thinOccupied(x, y, c, alone))
415 let sx = x;
494 { continue; }
416 let sy = y;
495 const col = thinColor(x, y, c, alone, east, west);
417 if (corner === "se")
496 setPx(rgba, x, y, cobbleShade(col, x, y));
418 {
419 sx = x;
420 sy = SIZE - 1 - y;
421 }
422 else if (corner === "sw")
423 {
424 sx = SIZE - 1 - x;
425 sy = SIZE - 1 - y;
426 }
427 else if (corner === "nw")
428 {
429 sx = SIZE - 1 - x;
430 sy = y;
431 }
432 const a = getPx(ellNE, sx, sy);
433 const b = getPx(fillNE, sx, sy);
434 if (b[3] > 128 && (a[3] <= 128 || a[0] !== b[0]))
435 {
436 // Sample fill colour from the horizontal arm interior.
437 const sample = getPx(horiz, Math.min(SIZE - 1, x), Math.min(SIZE - 1, Math.max(0, y)));
438 const col = sample[3] > 128 ? sample : b;
439 setPx(out, x, y, col);
440 }
497 }
441 }
498 }
442 }
499 return rgba;
443 return out;
500}
444}
501
445
502function paintThick (mask, alone, east, west)
446/**
447 * Paint one mask by starting from the best base template, then OR-ing extra
448 * arms and applying / stripping corner fills for each diagonal bit.
449 */
450function paintMask (mask, pack)
503{
451{
504 const rgba = new Uint8ClampedArray(SIZE * SIZE * 4);
505 const c = decodeMask(mask);
452 const c = decodeMask(mask);
506 for (let y = 0; y < SIZE; y++)
453 const {
454 alone, east, west, north, south, ns, ew,
455 ellNE, fillNE, ellNW, fillNW, ellSE, fillSE, ellSW, fillSW
456 } = pack;
457
458 const n = c.n;
459 const e = c.e;
460 const s = c.s;
461 const w = c.w;
462 const cardinal = (n ? 1 : 0) + (e ? 1 : 0) + (s ? 1 : 0) + (w ? 1 : 0);
463
464 // --- Exact / near-exact authored cases ---
465 if (cardinal === 0)
466 { return copyRgba(alone); }
467 if (cardinal === 1)
507 {
468 {
508 for (let x = 0; x < SIZE; x++)
469 if (e)
509 {
470 { return copyRgba(east); }
510 const col = thickColor(x, y, c, alone, east, west);
471 if (w)
511 setPx(rgba, x, y, cobbleShade(col, x, y));
472 { return copyRgba(west); }
512 }
473 if (n)
474 { return copyRgba(north); }
475 if (s)
476 { return copyRgba(south); }
513 }
477 }
514 return rgba;
478
479 // Pure L corners (two adjacent cardinals)
480 if (cardinal === 2 && n && e && !s && !w)
481 { return c.ne ? copyRgba(fillNE) : copyRgba(ellNE); }
482 if (cardinal === 2 && n && w && !s && !e)
483 { return c.nw ? copyRgba(fillNW) : copyRgba(ellNW); }
484 if (cardinal === 2 && s && e && !n && !w)
485 { return c.se ? copyRgba(fillSE) : copyRgba(ellSE); }
486 if (cardinal === 2 && s && w && !n && !e)
487 { return c.sw ? copyRgba(fillSW) : copyRgba(ellSW); }
488
489 // Opposite pairs
490 if (cardinal === 2 && n && s && !e && !w)
491 { return copyRgba(ns); }
492 if (cardinal === 2 && e && w && !n && !s)
493 { return copyRgba(ew); }
494
495 // --- General compose ---
496 const out = clearRgba();
497
498 // Prefer richer multi-arm templates when available, then blit extras.
499 if (n && e)
500 { blit(out, c.ne ? fillNE : ellNE); }
501 else if (n && w)
502 { blit(out, c.nw ? fillNW : ellNW); }
503 else if (s && e)
504 { blit(out, c.se ? fillSE : ellSE); }
505 else if (s && w)
506 { blit(out, c.sw ? fillSW : ellSW); }
507 else if (n && s)
508 { blit(out, ns); }
509 else if (e && w)
510 { blit(out, ew); }
511 else if (n)
512 { blit(out, north); }
513 else if (s)
514 { blit(out, south); }
515 else if (e)
516 { blit(out, east); }
517 else if (w)
518 { blit(out, west); }
519
520 // Add missing opposite / side arms.
521 if (n)
522 { blit(out, north); }
523 if (s)
524 { blit(out, south); }
525 if (e)
526 { blit(out, east); }
527 if (w)
528 { blit(out, west); }
529 if (n && s)
530 { blit(out, ns); }
531 if (e && w)
532 { blit(out, ew); }
533
534 // Corner fills / strips for every relevant diagonal.
535 if (n && e)
536 {
537 if (c.ne)
538 { applyCornerFill(out, ellNE, fillNE); }
539 else
540 { stripCornerFill(out, ellNE, fillNE); }
541 }
542 if (n && w)
543 {
544 if (c.nw)
545 { applyCornerFill(out, ellNW, fillNW); }
546 else
547 { stripCornerFill(out, ellNW, fillNW); }
548 }
549 if (s && e)
550 {
551 if (c.se)
552 { applyCornerFill(out, ellSE, fillSE); }
553 else
554 { stripCornerFill(out, ellSE, fillSE); }
555 }
556 if (s && w)
557 {
558 if (c.sw)
559 { applyCornerFill(out, ellSW, fillSW); }
560 else
561 { stripCornerFill(out, ellSW, fillSW); }
562 }
563
564 return out;
515}
565}
516
566
517function clearGenerated (dir)
567function clearGenerated (dir)
@@ -525,40 +575,39 @@ function clearGenerated (dir)
525 }
575 }
526}
576}
527
577
528function writeSet (dir, paint, label)
578function writeSet (dir, pack, label)
529{
579{
530 clearGenerated(dir);
580 clearGenerated(dir);
531 const masks = listValidNeighborConnectCornerMasks();
581 const masks = listValidNeighborConnectCornerMasks();
532 for (const mask of masks)
582 for (const mask of masks)
533 {
583 {
534 writeFileSync(join(dir, `${mask}.png`), encodePng(paint(mask)));
584 writeFileSync(join(dir, `${mask}.png`), encodePng(paintMask(mask, pack)));
535 }
585 }
536 console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
586 console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
537}
587}
538
588
539const thinAlone = decodePngRgba(join(EXAMPLES, "example-stone-thin.png"));
589const thin = buildPack("thin");
540const thinEast = decodePngRgba(join(EXAMPLES, "example-stone-thin-connecting.png"));
590const thick = buildPack("thick");
541const thinWest = mirrorX(thinEast);
591
542const thickAlone = decodePngRgba(join(EXAMPLES, "example-stone-thick.png"));
592// Sanity checks against authored examples
543const thickEast = decodePngRgba(join(EXAMPLES, "example-stone-thick-connecting.png"));
593function assertSame (a, b, label)
544const thickWest = mirrorX(thickEast);
545
546// Sanity: alone / east templates must decode to expected coverage.
547const thinAloneCount = [...thinAlone].filter((_, i) => i % 4 === 3 && thinAlone[i] > 128).length;
548const thinEastCount = [...thinEast].filter((_, i) => i % 4 === 3 && thinEast[i] > 128).length;
549if (thinAloneCount < 80 || thinEastCount < 120)
550{
594{
551 throw new Error(`Example decode looks wrong (alone=${thinAloneCount}, east=${thinEastCount})`);
595 for (let i = 0; i < a.length; i++)
596 {
597 if (a[i] !== b[i])
598 { throw new Error(`Template mismatch: ${label} at byte ${i}`); }
599 }
552}
600}
553
601assertSame(paintMask(0, thin), thin.alone, "thin alone");
554writeSet(OUT_THICK, (mask) => paintThick(mask, thickAlone, thickEast, thickWest), "thick");
602assertSame(paintMask(2, thin), thin.east, "thin east");
555writeSet(OUT_THIN, (mask) => paintThin(mask, thinAlone, thinEast, thinWest), "thin");
603assertSame(paintMask(1, thin), thin.north, "thin north");
556
604assertSame(paintMask(3, thin), thin.ellNE, "thin L");
557// Keep mask 0 / east-only (2) pixel-identical to examples (minus cobble speck on 0).
605assertSame(paintMask(19, thin), thin.fillNE, "thin 2x2");
558writeFileSync(join(OUT_THIN, "0.png"), encodePng(thinAlone));
606assertSame(paintMask(0, thick), thick.alone, "thick alone");
559writeFileSync(join(OUT_THICK, "0.png"), encodePng(thickAlone));
607assertSame(paintMask(2, thick), thick.east, "thick east");
560writeFileSync(join(OUT_THIN, "2.png"), encodePng(thinEast));
608assertSame(paintMask(1, thick), thick.north, "thick north");
561writeFileSync(join(OUT_THICK, "2.png"), encodePng(thickEast));
609assertSame(paintMask(3, thick), thick.ellNE, "thick L");
562writeFileSync(join(OUT_THIN, "8.png"), encodePng(thinWest));
610assertSame(paintMask(19, thick), thick.fillNE, "thick 2x2");
563writeFileSync(join(OUT_THICK, "8.png"), encodePng(thickWest));
611
564console.log("Pinned 0 / E / W templates to example pixels");
612writeSet(OUT_THIN, thin, "thin");
613writeSet(OUT_THICK, thick, "thick");