BlueGit

timfa questward

Merge branch 'feature/thin-thick-stone-walls'

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
89b1543f573f2e0a9191a6f20cd70443575126e3
232 files changed +1984 −198
client/assets/blocks/_examples/stone-wall/ref-thick-all-variants.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-alone-256.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-face-id-16.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-face-id-256.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-face-legend.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-height-16.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-height-256.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-textured-alone-256.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thick-textured-variants.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thin-textured-alone-256.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/ref-thin-textured-variants.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thick-stone-wall-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/_examples/stone-wall/thin-stone-wall-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-brick-wall/thick-brick-wall.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-cliff/thick-cliff.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-smooth-stone-wall/thick-smooth-stone-wall-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/0.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/1.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/10.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/11.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/12.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/13.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/14.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/15.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/2.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/3.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/4.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/5.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/6.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/7.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/8.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thick-wood-wall/9.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-brick-wall/thin-brick-wall.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-cliff/thin-cliff.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-e.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-es.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-esw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-n.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-ne.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-nes.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-nesw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-ns.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-s.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-sw.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-swn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-w.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-we.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-wn.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-smooth-stone-wall/thin-smooth-stone-wall-wne.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

client/assets/blocks/thin-wood-wall/0.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/thin-wood-wall/1.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

client/assets/blocks/thin-wood-wall/2.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

client/assets/blocks/thin-wood-wall/8.png added Binary file +0 −0

The contents of this binary file are not shown.

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

The contents of this binary file are not shown.

client/scripts/export-thick-wall-refs.py added +120 −0
@@ -0,0 +1,120 @@
1 #!/usr/bin/env python3
2 """Export face-id / heightmap / upscaled refs from thick-stone-wall alone.
3
4 Run from repo root:
5 python3 client/scripts/export-thick-wall-refs.py
6
7 Requires: Pillow
8 """
9 from __future__ import annotations
10
11 from pathlib import Path
12
13 from PIL import Image, ImageDraw
14
15 ROOT = Path(__file__).resolve().parents[1]
16 ALONE = ROOT / "assets/blocks/_examples/stone-wall/thick-stone-wall.png"
17 OUT = ROOT / "assets/blocks/_examples/stone-wall"
18
19 # Source greys → semantic face roles (see docs/STONE_WALL_SHAPES.md)
20 FACE_RGB = {
21 (175, 175, 175): (255, 255, 255), # N bevel
22 (149, 149, 149): (220, 60, 60), # W face
23 (108, 108, 108): (60, 100, 220), # E face
24 (84, 84, 84): (60, 180, 80), # S face
25 (128, 128, 128): (220, 180, 60), # top plateau
26 (64, 64, 64): (20, 20, 20), # outline
27 }
28
29 HEIGHT = {
30 (64, 64, 64): 40,
31 (84, 84, 84): 80,
32 (108, 108, 108): 140,
33 (149, 149, 149): 160,
34 (128, 128, 128): 200,
35 (175, 175, 175): 220,
36 }
37
38
39 def main() -> None:
40 OUT.mkdir(parents=True, exist_ok=True)
41 alone = Image.open(ALONE).convert("RGBA")
42 w, h = alone.size
43 face = Image.new("RGBA", (w, h), (0, 0, 0, 0))
44 height = Image.new("L", (w, h), 0)
45
46 for y in range(h):
47 for x in range(w):
48 r, g, b, a = alone.getpixel((x, y))
49 if a == 0:
50 continue
51 key = (r, g, b)
52 if key not in FACE_RGB:
53 raise SystemExit(f"Unknown grey {key} at ({x},{y})")
54 fr, fg, fb = FACE_RGB[key]
55 face.putpixel((x, y), (fr, fg, fb, 255))
56 height.putpixel((x, y), HEIGHT[key])
57
58 face.save(OUT / "ref-thick-face-id-16.png")
59 face.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-face-id-256.png")
60 height.save(OUT / "ref-thick-height-16.png")
61 height.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-height-256.png")
62 alone.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-alone-256.png")
63
64 leg = Image.new("RGBA", (280, 200), (30, 30, 30, 255))
65 d = ImageDraw.Draw(leg)
66 items = [
67 ((255, 255, 255), "North bevel 0xAF"),
68 ((220, 60, 60), "West face 0x95"),
69 ((60, 100, 220), "East face 0x6C"),
70 ((60, 180, 80), "South face 0x54"),
71 ((220, 180, 60), "Top plateau 0x80"),
72 ((20, 20, 20), "Outline 0x40"),
73 ]
74 for i, (c, label) in enumerate(items):
75 yy = 16 + i * 28
76 d.rectangle([16, yy, 40, yy + 20], fill=(*c, 255))
77 d.text((52, yy + 2), label, fill=(230, 230, 230, 255))
78 leg.save(OUT / "ref-thick-face-legend.png")
79
80 # Labeled contact sheet of all 16 thick *shape* states (bit order).
81 wall_dir = OUT
82 names = [
83 ("alone", "thick-stone-wall.png"),
84 ("n", "thick-stone-wall-n.png"),
85 ("e", "thick-stone-wall-e.png"),
86 ("ne", "thick-stone-wall-ne.png"),
87 ("s", "thick-stone-wall-s.png"),
88 ("ns", "thick-stone-wall-ns.png"),
89 ("es", "thick-stone-wall-es.png"),
90 ("nes", "thick-stone-wall-nes.png"),
91 ("w", "thick-stone-wall-w.png"),
92 ("wn", "thick-stone-wall-wn.png"),
93 ("we", "thick-stone-wall-we.png"),
94 ("wne", "thick-stone-wall-wne.png"),
95 ("sw", "thick-stone-wall-sw.png"),
96 ("swn", "thick-stone-wall-swn.png"),
97 ("esw", "thick-stone-wall-esw.png"),
98 ("nesw", "thick-stone-wall-nesw.png"),
99 ]
100 scale, pad, label_h, cols = 8, 28, 14, 4
101 cell = 16 * scale
102 rows = 4
103 sheet_w = cols * cell + (cols + 1) * pad
104 sheet_h = rows * (cell + label_h) + (rows + 1) * pad
105 sheet = Image.new("RGBA", (sheet_w, sheet_h), (24, 24, 28, 255))
106 draw = ImageDraw.Draw(sheet)
107 for i, (label, fname) in enumerate(names):
108 r, c = divmod(i, cols)
109 x = pad + c * (cell + pad)
110 y = pad + r * (cell + label_h + pad)
111 im = Image.open(wall_dir / fname).convert("RGBA").resize((cell, cell), Image.NEAREST)
112 sheet.paste(im, (x, y), im)
113 draw.text((x, y + cell + 2), label, fill=(220, 220, 220, 255))
114 sheet.save(OUT / "ref-thick-all-variants.png")
115
116 print(f"Wrote refs to {OUT}")
117
118
119 if __name__ == "__main__":
120 main()
@@ -0,0 +1,120 @@
1#!/usr/bin/env python3
2"""Export face-id / heightmap / upscaled refs from thick-stone-wall alone.
3
4Run from repo root:
5 python3 client/scripts/export-thick-wall-refs.py
6
7Requires: Pillow
8"""
9from __future__ import annotations
10
11from pathlib import Path
12
13from PIL import Image, ImageDraw
14
15ROOT = Path(__file__).resolve().parents[1]
16ALONE = ROOT / "assets/blocks/_examples/stone-wall/thick-stone-wall.png"
17OUT = ROOT / "assets/blocks/_examples/stone-wall"
18
19# Source greys → semantic face roles (see docs/STONE_WALL_SHAPES.md)
20FACE_RGB = {
21 (175, 175, 175): (255, 255, 255), # N bevel
22 (149, 149, 149): (220, 60, 60), # W face
23 (108, 108, 108): (60, 100, 220), # E face
24 (84, 84, 84): (60, 180, 80), # S face
25 (128, 128, 128): (220, 180, 60), # top plateau
26 (64, 64, 64): (20, 20, 20), # outline
27}
28
29HEIGHT = {
30 (64, 64, 64): 40,
31 (84, 84, 84): 80,
32 (108, 108, 108): 140,
33 (149, 149, 149): 160,
34 (128, 128, 128): 200,
35 (175, 175, 175): 220,
36}
37
38
39def main() -> None:
40 OUT.mkdir(parents=True, exist_ok=True)
41 alone = Image.open(ALONE).convert("RGBA")
42 w, h = alone.size
43 face = Image.new("RGBA", (w, h), (0, 0, 0, 0))
44 height = Image.new("L", (w, h), 0)
45
46 for y in range(h):
47 for x in range(w):
48 r, g, b, a = alone.getpixel((x, y))
49 if a == 0:
50 continue
51 key = (r, g, b)
52 if key not in FACE_RGB:
53 raise SystemExit(f"Unknown grey {key} at ({x},{y})")
54 fr, fg, fb = FACE_RGB[key]
55 face.putpixel((x, y), (fr, fg, fb, 255))
56 height.putpixel((x, y), HEIGHT[key])
57
58 face.save(OUT / "ref-thick-face-id-16.png")
59 face.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-face-id-256.png")
60 height.save(OUT / "ref-thick-height-16.png")
61 height.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-height-256.png")
62 alone.resize((w * 16, h * 16), Image.NEAREST).save(OUT / "ref-thick-alone-256.png")
63
64 leg = Image.new("RGBA", (280, 200), (30, 30, 30, 255))
65 d = ImageDraw.Draw(leg)
66 items = [
67 ((255, 255, 255), "North bevel 0xAF"),
68 ((220, 60, 60), "West face 0x95"),
69 ((60, 100, 220), "East face 0x6C"),
70 ((60, 180, 80), "South face 0x54"),
71 ((220, 180, 60), "Top plateau 0x80"),
72 ((20, 20, 20), "Outline 0x40"),
73 ]
74 for i, (c, label) in enumerate(items):
75 yy = 16 + i * 28
76 d.rectangle([16, yy, 40, yy + 20], fill=(*c, 255))
77 d.text((52, yy + 2), label, fill=(230, 230, 230, 255))
78 leg.save(OUT / "ref-thick-face-legend.png")
79
80 # Labeled contact sheet of all 16 thick *shape* states (bit order).
81 wall_dir = OUT
82 names = [
83 ("alone", "thick-stone-wall.png"),
84 ("n", "thick-stone-wall-n.png"),
85 ("e", "thick-stone-wall-e.png"),
86 ("ne", "thick-stone-wall-ne.png"),
87 ("s", "thick-stone-wall-s.png"),
88 ("ns", "thick-stone-wall-ns.png"),
89 ("es", "thick-stone-wall-es.png"),
90 ("nes", "thick-stone-wall-nes.png"),
91 ("w", "thick-stone-wall-w.png"),
92 ("wn", "thick-stone-wall-wn.png"),
93 ("we", "thick-stone-wall-we.png"),
94 ("wne", "thick-stone-wall-wne.png"),
95 ("sw", "thick-stone-wall-sw.png"),
96 ("swn", "thick-stone-wall-swn.png"),
97 ("esw", "thick-stone-wall-esw.png"),
98 ("nesw", "thick-stone-wall-nesw.png"),
99 ]
100 scale, pad, label_h, cols = 8, 28, 14, 4
101 cell = 16 * scale
102 rows = 4
103 sheet_w = cols * cell + (cols + 1) * pad
104 sheet_h = rows * (cell + label_h) + (rows + 1) * pad
105 sheet = Image.new("RGBA", (sheet_w, sheet_h), (24, 24, 28, 255))
106 draw = ImageDraw.Draw(sheet)
107 for i, (label, fname) in enumerate(names):
108 r, c = divmod(i, cols)
109 x = pad + c * (cell + pad)
110 y = pad + r * (cell + label_h + pad)
111 im = Image.open(wall_dir / fname).convert("RGBA").resize((cell, cell), Image.NEAREST)
112 sheet.paste(im, (x, y), im)
113 draw.text((x, y + cell + 2), label, fill=(220, 220, 220, 255))
114 sheet.save(OUT / "ref-thick-all-variants.png")
115
116 print(f"Wrote refs to {OUT}")
117
118
119if __name__ == "__main__":
120 main()
client/scripts/generate-stone-wall-sprites.mjs +327 −137
@@ -1,39 +1,43 @@
1 1 /**
2 * Generate 16×16 gray cobblestone stone-wall PNGs for neighbor-connect masks 0–15.
2 * Generate thin + thick stone-wall PNGs for the 16 cardinal neighbor masks.
3 3 *
4 * Truncated-pyramid / frustum look when alone or at free ends. Connected runs use a
5 * constant cross-section extruded to the tile edge (strip-union like tables/fences)
6 * so N/S and E/W seams match.
4 * Naming: `{key}.png` alone, `{key}-{suffix}.png` when connected.
5 * Suffixes: n/e/s/w, ns, we, ne/es/sw/wn, esw/wne/swn/nes, nesw.
6 *
7 * Examples (shape only, no texture) live in
8 * client/assets/blocks/_examples/stone-wall/
7 9 *
8 10 * node client/scripts/generate-stone-wall-sprites.mjs
9 11 */
10 import { mkdirSync, writeFileSync } from "node:fs";
11 import { deflateSync } from "node:zlib";
12 import
13 {
14 mkdirSync,
15 writeFileSync,
16 readdirSync,
17 unlinkSync,
18 readFileSync,
19 existsSync,
20 cpSync,
21 rmSync
22 } from "node:fs";
23 import { deflateSync, inflateSync } from "node:zlib";
12 24 import { fileURLToPath } from "node:url";
13 25 import { dirname, join } from "node:path";
14 import { NeighborBit } from "../../shared/world/neighborConnect.js";
26 import
27 {
28 NeighborBit,
29 cardinalConnectionSuffix,
30 composeNamedNeighborConnectState
31 } from "../../shared/world/neighborConnect.js";
15 32
16 33 const SIZE = 16;
17 const OUT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks/stone-wall");
18
19 const TOP = [168, 168, 172, 255];
20 const TOP_HI = [198, 198, 202, 255];
21 const TOP_LO = [140, 140, 144, 255];
22 const FACE = [112, 112, 116, 255];
23 const FACE_HI = [132, 132, 136, 255];
24 const FACE_LO = [88, 88, 92, 255];
25 const EDGE = [70, 70, 74, 255];
26 const MORTAR = [78, 78, 82, 255];
27
28 /** Constant core used for connected runs (must meet neighbour tile edges cleanly). */
29 const CORE_X0 = 5;
30 const CORE_X1 = 10;
31 const TOP_Y0 = 3;
32 const TOP_Y1 = 6;
33 const FACE_Y1 = 12;
34 /** Alone / free-end base is wider than the top (frustum). */
35 const BASE_X0 = 3;
36 const BASE_X1 = 12;
34 const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
35 const EXAMPLES = join(ROOT, "_examples/stone-wall");
36 const OUT_THICK = join(ROOT, "thick-stone-wall");
37 const OUT_THIN = join(ROOT, "thin-stone-wall");
38
39 const THICK = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true };
40 const THIN = { key: "thin-stone-wall", neighborConnect: true, neighborConnectNamed: true };
37 41
38 42 function crcTable ()
39 43 {
@@ -98,6 +102,90 @@ function encodePng (rgba)
98 102 ]);
99 103 }
100 104
105 function decodePngRgba (path)
106 {
107 const buf = readFileSync(path);
108 let off = 8;
109 let w = 0;
110 let h = 0;
111 const idat = [];
112 while (off < buf.length)
113 {
114 const len = buf.readUInt32BE(off);
115 const type = buf.slice(off + 4, off + 8).toString("ascii");
116 const data = buf.slice(off + 8, off + 8 + len);
117 if (type === "IHDR")
118 {
119 w = data.readUInt32BE(0);
120 h = data.readUInt32BE(4);
121 if (data[8] !== 8 || data[9] !== 6)
122 { throw new Error(`${path}: expected 8-bit RGBA`); }
123 }
124 else if (type === "IDAT")
125 { idat.push(data); }
126 else if (type === "IEND")
127 { break; }
128 off += 12 + len;
129 }
130 const raw = inflateSync(Buffer.concat(idat));
131 const bpp = 4;
132 const stride = w * bpp;
133 const rgba = new Uint8ClampedArray(w * h * 4);
134 let src = 0;
135 const prev = Buffer.alloc(stride);
136 const cur = Buffer.alloc(stride);
137 for (let y = 0; y < h; y++)
138 {
139 const filter = raw[src++];
140 for (let i = 0; i < stride; i++)
141 { cur[i] = raw[src++]; }
142 for (let i = 0; i < stride; i++)
143 {
144 const left = i >= bpp ? cur[i - bpp] : 0;
145 const up = prev[i];
146 const upLeft = i >= bpp ? prev[i - bpp] : 0;
147 let val = cur[i];
148 if (filter === 1)
149 { val = (val + left) & 255; }
150 else if (filter === 2)
151 { val = (val + up) & 255; }
152 else if (filter === 3)
153 { val = (val + ((left + up) >> 1)) & 255; }
154 else if (filter === 4)
155 {
156 const p = left + up - upLeft;
157 const pa = Math.abs(p - left);
158 const pb = Math.abs(p - up);
159 const pc = Math.abs(p - upLeft);
160 const pr = (pa <= pb && pa <= pc) ? left : (pb <= pc ? up : upLeft);
161 val = (val + pr) & 255;
162 }
163 cur[i] = val;
164 }
165 rgba.set(cur, y * stride);
166 prev.set(cur);
167 }
168 if (w !== SIZE || h !== SIZE)
169 { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
170 return rgba;
171 }
172
173 function loadExample (name)
174 {
175 const path = join(EXAMPLES, name);
176 if (!existsSync(path))
177 { return null; }
178 return decodePngRgba(path);
179 }
180
181 function getPx (rgba, x, y)
182 {
183 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
184 { return [0, 0, 0, 0]; }
185 const i = (y * SIZE + x) * 4;
186 return [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]];
187 }
188
101 189 function setPx (rgba, x, y, color)
102 190 {
103 191 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
@@ -109,148 +197,250 @@ function setPx (rgba, x, y, color)
109 197 rgba[i + 3] = color[3];
110 198 }
111 199
112 /** Frustum half-width in X at row y (alone / free-end silhouette). */
113 function frustumX0X1 (y)
200 function opaque (rgba, x, y)
114 201 {
115 if (y <= TOP_Y1)
116 { return { x0: CORE_X0, x1: CORE_X1 }; }
117 if (y >= FACE_Y1)
118 { return { x0: BASE_X0, x1: BASE_X1 }; }
119 const t = (y - TOP_Y1) / (FACE_Y1 - TOP_Y1);
120 const x0 = Math.round(CORE_X0 + (BASE_X0 - CORE_X0) * t);
121 const x1 = Math.round(CORE_X1 + (BASE_X1 - CORE_X1) * t);
122 return { x0, x1 };
202 return getPx(rgba, x, y)[3] > 128;
123 203 }
124 204
125 /**
126 * Strip-union with constant core thickness on connected sides.
127 * Free ends keep the frustum taper so alone / stubs still read as 3D.
128 */
129 function inWall (x, y, connectN, connectE, connectS, connectW)
205 function copyRgba (rgba)
206 {
207 return new Uint8ClampedArray(rgba);
208 }
209
210 function clearRgba ()
130 211 {
131 const alone = !connectN && !connectE && !connectS && !connectW;
132 const wantH = alone || connectE || connectW;
133 const wantV = alone || connectN || connectS;
212 return new Uint8ClampedArray(SIZE * SIZE * 4);
213 }
134 214
135 if (wantH)
215 function mirrorX (rgba)
216 {
217 const out = clearRgba();
218 for (let y = 0; y < SIZE; y++)
136 219 {
137 const y0 = connectN ? 0 : TOP_Y0;
138 const y1 = connectS ? SIZE - 1 : FACE_Y1;
139 if (y >= y0 && y <= y1)
140 {
141 const { x0: fx0, x1: fx1 } = frustumX0X1(Math.min(FACE_Y1, Math.max(TOP_Y0, y)));
142 // Connected cardinals run to the tile edge (constant seam).
143 // Free ends keep the frustum taper.
144 const x0 = connectW ? 0 : fx0;
145 const x1 = connectE ? SIZE - 1 : fx1;
146 if (x >= x0 && x <= x1)
147 { return true; }
148 }
220 for (let x = 0; x < SIZE; x++)
221 { setPx(out, x, y, getPx(rgba, SIZE - 1 - x, y)); }
149 222 }
223 return out;
224 }
150 225
151 if (wantV)
226 function blit (dst, src)
227 {
228 if (!src)
229 { return; }
230 for (let y = 0; y < SIZE; y++)
152 231 {
153 const x0 = CORE_X0;
154 const x1 = CORE_X1;
155 if (x >= x0 && x <= x1)
232 for (let x = 0; x < SIZE; x++)
156 233 {
157 const y0 = connectN ? 0 : TOP_Y0;
158 const y1 = connectS ? SIZE - 1 : FACE_Y1;
159 if (y >= y0 && y <= y1)
160 { return true; }
234 const c = getPx(src, x, y);
235 if (c[3] > 128)
236 { setPx(dst, x, y, c); }
161 237 }
162 238 }
163
164 return false;
165 239 }
166 240
167 function hash2 (x, y)
241 /** Ensure example folder exists; migrate from legacy stone-wall/ if needed. */
242 function ensureExamples ()
168 243 {
169 let n = (x * 374761393 + y * 668265263) | 0;
170 n = (n ^ (n >>> 13)) * 1274126177;
171 return (n ^ (n >>> 16)) >>> 0;
172 }
173
174 function cobbleShade (base, x, y)
175 {
176 const h = hash2(x, y);
177 const speck = (h & 7);
178 if (speck === 0)
179 { return MORTAR; }
180 if (speck === 1 || speck === 2)
181 { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_HI : FACE_HI; }
182 if (speck === 3)
183 { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_LO : FACE_LO; }
184 return base;
244 mkdirSync(EXAMPLES, { recursive: true });
245 const legacy = join(ROOT, "stone-wall");
246 if (!existsSync(legacy))
247 { return; }
248 for (const name of readdirSync(legacy))
249 {
250 if (!name.startsWith("example-") || !name.endsWith(".png"))
251 { continue; }
252 const dest = join(EXAMPLES, name);
253 if (!existsSync(dest))
254 { cpSync(join(legacy, name), dest); }
255 }
185 256 }
186 257
187 function isTopRow (y, connectN)
258 function buildPack (kind)
188 259 {
189 if (connectN)
190 { return y <= TOP_Y1; }
191 return y >= TOP_Y0 && y <= TOP_Y1;
192 }
260 const alone = loadExample(`example-stone-${kind}.png`);
261 const east = loadExample(`example-stone-${kind}-connecting.png`);
262 const north = loadExample(`example-stone-${kind}-connecting-up.png`);
263 const south = loadExample(`example-stone-${kind}-connecting-down.png`);
264 const ns = loadExample(`example-stone-${kind}-connecting-updown.png`);
265 const ellNE = loadExample(`example-stone-${kind}-connecting-L.png`);
266 const ellSE = loadExample(`example-stone-${kind}-connecting-Ldownright.png`);
267 const teeESW = loadExample(`example-stone-${kind}-T.png`)
268 ?? loadExample(`example-stone-${kind}-connecting-T.png`);
269 const teeNEW = loadExample(`example-stone-${kind}-connecting-T-upsidedown.png`);
193 270
194 function paintWall (mask)
195 {
196 const rgba = new Uint8Array(SIZE * SIZE * 4);
197 const connectN = (mask & NeighborBit.n) !== 0;
198 const connectE = (mask & NeighborBit.e) !== 0;
199 const connectS = (mask & NeighborBit.s) !== 0;
200 const connectW = (mask & NeighborBit.w) !== 0;
271 if (!alone || !east || !north || !ns)
272 { throw new Error(`Missing core ${kind} examples in ${EXAMPLES}`); }
201 273
202 for (let y = 0; y < SIZE; y++)
274 const west = mirrorX(east);
275 const southFinal = south ?? (() =>
203 276 {
204 for (let x = 0; x < SIZE; x++)
277 const out = copyRgba(alone);
278 for (let y = 10; y < SIZE; y++)
205 279 {
206 if (!inWall(x, y, connectN, connectE, connectS, connectW))
207 { continue; }
280 for (let x = 0; x < SIZE; x++)
281 {
282 if (opaque(ns, x, y))
283 { setPx(out, x, y, getPx(ns, x, y)); }
284 }
285 }
286 return out;
287 })();
208 288
209 const n = inWall(x, y - 1, connectN, connectE, connectS, connectW);
210 const e = inWall(x + 1, y, connectN, connectE, connectS, connectW);
211 const s = inWall(x, y + 1, connectN, connectE, connectS, connectW);
212 const w = inWall(x - 1, y, connectN, connectE, connectS, connectW);
289 const ellNEFinal = ellNE ?? (() =>
290 {
291 const out = clearRgba();
292 blit(out, north);
293 blit(out, east);
294 return out;
295 })();
296 const ellSEFinal = ellSE ?? (() =>
297 {
298 const out = clearRgba();
299 blit(out, southFinal);
300 blit(out, east);
301 return out;
302 })();
303 const ellNW = mirrorX(ellNEFinal);
304 const ellSW = mirrorX(ellSEFinal);
213 305
214 let base;
215 if (isTopRow(y, connectN))
306 const ew = (() =>
307 {
308 const out = clearRgba();
309 blit(out, east);
310 blit(out, west);
311 for (let y = 0; y < SIZE; y++)
312 {
313 if (!opaque(east, SIZE - 1, y))
314 { continue; }
315 let fill = null;
316 for (let x = SIZE - 1; x >= 0; x--)
216 317 {
217 if (!n)
218 { base = TOP_HI; }
219 else if (!s && y === TOP_Y1)
220 { base = TOP_LO; }
221 else
222 { base = TOP; }
318 const c = getPx(east, x, y);
319 if (c[3] > 128)
320 { fill = c; break; }
223 321 }
224 else
322 if (!fill)
323 { continue; }
324 for (let x = 0; x < SIZE; x++)
225 325 {
226 if (!s)
227 { base = FACE_LO; }
228 else if (!n)
229 { base = FACE_HI; }
230 else
231 { base = FACE; }
326 if (!opaque(out, x, y))
327 { setPx(out, x, y, fill); }
232 328 }
329 }
330 return out;
331 })();
233 332
234 // Free side bevels (not on edges that continue into a neighbour).
235 const freeW = !w && !(connectW && x === 0);
236 const freeE = !e && !(connectE && x === SIZE - 1);
237 if (freeW || freeE)
238 {
239 if (base === TOP || base === TOP_HI)
240 { base = TOP_LO; }
241 else if (base === FACE || base === FACE_HI)
242 { base = EDGE; }
243 }
333 const teeESWFinal = teeESW ?? (() =>
334 {
335 const out = clearRgba();
336 blit(out, ew);
337 blit(out, southFinal);
338 return out;
339 })();
340 const teeNEWFinal = teeNEW ?? (() =>
341 {
342 const out = clearRgba();
343 blit(out, ew);
344 blit(out, north);
345 return out;
346 })();
347 const teeNES = (() =>
348 {
349 const out = clearRgba();
350 blit(out, north);
351 blit(out, east);
352 blit(out, southFinal);
353 return out;
354 })();
355 const teeNWS = mirrorX(teeNES);
356 const all = (() =>
357 {
358 const out = clearRgba();
359 blit(out, ns);
360 blit(out, ew);
361 return out;
362 })();
244 363
245 setPx(rgba, x, y, cobbleShade(base, x, y));
246 }
364 const byMask = new Map([
365 [0, alone],
366 [NeighborBit.n, north],
367 [NeighborBit.e, east],
368 [NeighborBit.s, southFinal],
369 [NeighborBit.w, west],
370 [NeighborBit.n | NeighborBit.s, ns],
371 [NeighborBit.e | NeighborBit.w, ew],
372 [NeighborBit.n | NeighborBit.e, ellNEFinal],
373 [NeighborBit.e | NeighborBit.s, ellSEFinal],
374 [NeighborBit.s | NeighborBit.w, ellSW],
375 [NeighborBit.w | NeighborBit.n, ellNW],
376 [NeighborBit.e | NeighborBit.s | NeighborBit.w, teeESWFinal],
377 [NeighborBit.w | NeighborBit.n | NeighborBit.e, teeNEWFinal],
378 [NeighborBit.n | NeighborBit.e | NeighborBit.s, teeNES],
379 [NeighborBit.n | NeighborBit.w | NeighborBit.s, teeNWS],
380 [NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w, all]
381 ]);
382
383 return { byMask, alone, east, north, ns, ellNE: ellNEFinal };
384 }
385
386 function clearGenerated (dir)
387 {
388 mkdirSync(dir, { recursive: true });
389 for (const name of readdirSync(dir))
390 {
391 if (!name.endsWith(".png") || name.startsWith("example"))
392 { continue; }
393 unlinkSync(join(dir, name));
247 394 }
248 return rgba;
249 395 }
250 396
251 mkdirSync(OUT, { recursive: true });
252 for (let mask = 0; mask < 16; mask++)
397 function writeSet (dir, def, pack)
253 398 {
254 writeFileSync(join(OUT, `${mask}.png`), encodePng(paintWall(mask)));
399 clearGenerated(dir);
400 for (let mask = 0; mask < 16; mask++)
401 {
402 const rgba = pack.byMask.get(mask);
403 if (!rgba)
404 { throw new Error(`Missing mask ${mask} for ${def.key}`); }
405 const state = composeNamedNeighborConnectState(def, mask);
406 writeFileSync(join(dir, `${state}.png`), encodePng(rgba));
407 }
408 console.log(`Wrote 16 ${def.key} sprites → ${dir}`);
255 409 }
256 console.log(`Wrote cobblestone frustum stone-wall sprites 0–15 to ${OUT}`);
410
411 function removeLegacyFolders ()
412 {
413 for (const name of ["stone-wall", "stone-wall-thin"])
414 {
415 const dir = join(ROOT, name);
416 if (!existsSync(dir))
417 { continue; }
418 // Keep examples only in _examples/; remove entire legacy folder.
419 rmSync(dir, { recursive: true, force: true });
420 console.log(`Removed legacy ${name}/`);
421 }
422 }
423
424 ensureExamples();
425 const thin = buildPack("thin");
426 const thick = buildPack("thick");
427
428 function assertSame (a, b, label)
429 {
430 for (let i = 0; i < a.length; i++)
431 {
432 if (a[i] !== b[i])
433 { throw new Error(`Mismatch ${label}`); }
434 }
435 }
436 assertSame(thin.byMask.get(0), thin.alone, "thin alone");
437 assertSame(thin.byMask.get(1), thin.north, "thin n");
438 assertSame(thin.byMask.get(2), thin.east, "thin e");
439 assertSame(thin.byMask.get(5), thin.ns, "thin ns");
440 assertSame(thick.byMask.get(0), thick.alone, "thick alone");
441
442 writeSet(OUT_THIN, THIN, thin);
443 writeSet(OUT_THICK, THICK, thick);
444 removeLegacyFolders();
445
446 console.log("Suffixes:", [...Array(16)].map((_, m) => `${m}=${cardinalConnectionSuffix(m) || "(alone)"}`).join(", "));
@@ -1,39 +1,43 @@
1/**
1/**
2 * Generate 16×16 gray cobblestone stone-wall PNGs for neighbor-connect masks 0–15.
2 * Generate thin + thick stone-wall PNGs for the 16 cardinal neighbor masks.
3 *
3 *
4 * Truncated-pyramid / frustum look when alone or at free ends. Connected runs use a
4 * Naming: `{key}.png` alone, `{key}-{suffix}.png` when connected.
5 * constant cross-section extruded to the tile edge (strip-union like tables/fences)
5 * Suffixes: n/e/s/w, ns, we, ne/es/sw/wn, esw/wne/swn/nes, nesw.
6 * so N/S and E/W seams match.
6 *
7 * Examples (shape only, no texture) live in
8 * client/assets/blocks/_examples/stone-wall/
7 *
9 *
8 * node client/scripts/generate-stone-wall-sprites.mjs
10 * node client/scripts/generate-stone-wall-sprites.mjs
9 */
11 */
10import { mkdirSync, writeFileSync } from "node:fs";
12import
11import { deflateSync } from "node:zlib";
13 {
14 mkdirSync,
15 writeFileSync,
16 readdirSync,
17 unlinkSync,
18 readFileSync,
19 existsSync,
20 cpSync,
21 rmSync
22 } from "node:fs";
23import { deflateSync, inflateSync } from "node:zlib";
12import { fileURLToPath } from "node:url";
24import { fileURLToPath } from "node:url";
13import { dirname, join } from "node:path";
25import { dirname, join } from "node:path";
14import { NeighborBit } from "../../shared/world/neighborConnect.js";
26import
27 {
28 NeighborBit,
29 cardinalConnectionSuffix,
30 composeNamedNeighborConnectState
31 } from "../../shared/world/neighborConnect.js";
15
32
16const SIZE = 16;
33const SIZE = 16;
17const OUT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks/stone-wall");
34const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
18
35const EXAMPLES = join(ROOT, "_examples/stone-wall");
19const TOP = [168, 168, 172, 255];
36const OUT_THICK = join(ROOT, "thick-stone-wall");
20const TOP_HI = [198, 198, 202, 255];
37const OUT_THIN = join(ROOT, "thin-stone-wall");
21const TOP_LO = [140, 140, 144, 255];
38
22const FACE = [112, 112, 116, 255];
39const THICK = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true };
23const FACE_HI = [132, 132, 136, 255];
40const THIN = { key: "thin-stone-wall", neighborConnect: true, neighborConnectNamed: true };
24const FACE_LO = [88, 88, 92, 255];
25const EDGE = [70, 70, 74, 255];
26const MORTAR = [78, 78, 82, 255];
27
28/** Constant core used for connected runs (must meet neighbour tile edges cleanly). */
29const CORE_X0 = 5;
30const CORE_X1 = 10;
31const TOP_Y0 = 3;
32const TOP_Y1 = 6;
33const FACE_Y1 = 12;
34/** Alone / free-end base is wider than the top (frustum). */
35const BASE_X0 = 3;
36const BASE_X1 = 12;
37
41
38function crcTable ()
42function crcTable ()
39{
43{
@@ -98,6 +102,90 @@ function encodePng (rgba)
98 ]);
102 ]);
99}
103}
100
104
105function decodePngRgba (path)
106{
107 const buf = readFileSync(path);
108 let off = 8;
109 let w = 0;
110 let h = 0;
111 const idat = [];
112 while (off < buf.length)
113 {
114 const len = buf.readUInt32BE(off);
115 const type = buf.slice(off + 4, off + 8).toString("ascii");
116 const data = buf.slice(off + 8, off + 8 + len);
117 if (type === "IHDR")
118 {
119 w = data.readUInt32BE(0);
120 h = data.readUInt32BE(4);
121 if (data[8] !== 8 || data[9] !== 6)
122 { throw new Error(`${path}: expected 8-bit RGBA`); }
123 }
124 else if (type === "IDAT")
125 { idat.push(data); }
126 else if (type === "IEND")
127 { break; }
128 off += 12 + len;
129 }
130 const raw = inflateSync(Buffer.concat(idat));
131 const bpp = 4;
132 const stride = w * bpp;
133 const rgba = new Uint8ClampedArray(w * h * 4);
134 let src = 0;
135 const prev = Buffer.alloc(stride);
136 const cur = Buffer.alloc(stride);
137 for (let y = 0; y < h; y++)
138 {
139 const filter = raw[src++];
140 for (let i = 0; i < stride; i++)
141 { cur[i] = raw[src++]; }
142 for (let i = 0; i < stride; i++)
143 {
144 const left = i >= bpp ? cur[i - bpp] : 0;
145 const up = prev[i];
146 const upLeft = i >= bpp ? prev[i - bpp] : 0;
147 let val = cur[i];
148 if (filter === 1)
149 { val = (val + left) & 255; }
150 else if (filter === 2)
151 { val = (val + up) & 255; }
152 else if (filter === 3)
153 { val = (val + ((left + up) >> 1)) & 255; }
154 else if (filter === 4)
155 {
156 const p = left + up - upLeft;
157 const pa = Math.abs(p - left);
158 const pb = Math.abs(p - up);
159 const pc = Math.abs(p - upLeft);
160 const pr = (pa <= pb && pa <= pc) ? left : (pb <= pc ? up : upLeft);
161 val = (val + pr) & 255;
162 }
163 cur[i] = val;
164 }
165 rgba.set(cur, y * stride);
166 prev.set(cur);
167 }
168 if (w !== SIZE || h !== SIZE)
169 { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
170 return rgba;
171}
172
173function loadExample (name)
174{
175 const path = join(EXAMPLES, name);
176 if (!existsSync(path))
177 { return null; }
178 return decodePngRgba(path);
179}
180
181function getPx (rgba, x, y)
182{
183 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
184 { return [0, 0, 0, 0]; }
185 const i = (y * SIZE + x) * 4;
186 return [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]];
187}
188
101function setPx (rgba, x, y, color)
189function setPx (rgba, x, y, color)
102{
190{
103 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
191 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE)
@@ -109,148 +197,250 @@ function setPx (rgba, x, y, color)
109 rgba[i + 3] = color[3];
197 rgba[i + 3] = color[3];
110}
198}
111
199
112/** Frustum half-width in X at row y (alone / free-end silhouette). */
200function opaque (rgba, x, y)
113function frustumX0X1 (y)
114{
201{
115 if (y <= TOP_Y1)
202 return getPx(rgba, x, y)[3] > 128;
116 { return { x0: CORE_X0, x1: CORE_X1 }; }
117 if (y >= FACE_Y1)
118 { return { x0: BASE_X0, x1: BASE_X1 }; }
119 const t = (y - TOP_Y1) / (FACE_Y1 - TOP_Y1);
120 const x0 = Math.round(CORE_X0 + (BASE_X0 - CORE_X0) * t);
121 const x1 = Math.round(CORE_X1 + (BASE_X1 - CORE_X1) * t);
122 return { x0, x1 };
123}
203}
124
204
125/**
205function copyRgba (rgba)
126 * Strip-union with constant core thickness on connected sides.
206{
127 * Free ends keep the frustum taper so alone / stubs still read as 3D.
207 return new Uint8ClampedArray(rgba);
128 */
208}
129function inWall (x, y, connectN, connectE, connectS, connectW)
209
210function clearRgba ()
130{
211{
131 const alone = !connectN && !connectE && !connectS && !connectW;
212 return new Uint8ClampedArray(SIZE * SIZE * 4);
132 const wantH = alone || connectE || connectW;
213}
133 const wantV = alone || connectN || connectS;
134
214
135 if (wantH)
215function mirrorX (rgba)
216{
217 const out = clearRgba();
218 for (let y = 0; y < SIZE; y++)
136 {
219 {
137 const y0 = connectN ? 0 : TOP_Y0;
220 for (let x = 0; x < SIZE; x++)
138 const y1 = connectS ? SIZE - 1 : FACE_Y1;
221 { setPx(out, x, y, getPx(rgba, SIZE - 1 - x, y)); }
139 if (y >= y0 && y <= y1)
140 {
141 const { x0: fx0, x1: fx1 } = frustumX0X1(Math.min(FACE_Y1, Math.max(TOP_Y0, y)));
142 // Connected cardinals run to the tile edge (constant seam).
143 // Free ends keep the frustum taper.
144 const x0 = connectW ? 0 : fx0;
145 const x1 = connectE ? SIZE - 1 : fx1;
146 if (x >= x0 && x <= x1)
147 { return true; }
148 }
149 }
222 }
223 return out;
224}
150
225
151 if (wantV)
226function blit (dst, src)
227{
228 if (!src)
229 { return; }
230 for (let y = 0; y < SIZE; y++)
152 {
231 {
153 const x0 = CORE_X0;
232 for (let x = 0; x < SIZE; x++)
154 const x1 = CORE_X1;
155 if (x >= x0 && x <= x1)
156 {
233 {
157 const y0 = connectN ? 0 : TOP_Y0;
234 const c = getPx(src, x, y);
158 const y1 = connectS ? SIZE - 1 : FACE_Y1;
235 if (c[3] > 128)
159 if (y >= y0 && y <= y1)
236 { setPx(dst, x, y, c); }
160 { return true; }
161 }
237 }
162 }
238 }
163
164 return false;
165}
239}
166
240
167function hash2 (x, y)
241/** Ensure example folder exists; migrate from legacy stone-wall/ if needed. */
242function ensureExamples ()
168{
243{
169 let n = (x * 374761393 + y * 668265263) | 0;
244 mkdirSync(EXAMPLES, { recursive: true });
170 n = (n ^ (n >>> 13)) * 1274126177;
245 const legacy = join(ROOT, "stone-wall");
171 return (n ^ (n >>> 16)) >>> 0;
246 if (!existsSync(legacy))
172}
247 { return; }
173
248 for (const name of readdirSync(legacy))
174function cobbleShade (base, x, y)
249 {
175{
250 if (!name.startsWith("example-") || !name.endsWith(".png"))
176 const h = hash2(x, y);
251 { continue; }
177 const speck = (h & 7);
252 const dest = join(EXAMPLES, name);
178 if (speck === 0)
253 if (!existsSync(dest))
179 { return MORTAR; }
254 { cpSync(join(legacy, name), dest); }
180 if (speck === 1 || speck === 2)
255 }
181 { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_HI : FACE_HI; }
182 if (speck === 3)
183 { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_LO : FACE_LO; }
184 return base;
185}
256}
186
257
187function isTopRow (y, connectN)
258function buildPack (kind)
188{
259{
189 if (connectN)
260 const alone = loadExample(`example-stone-${kind}.png`);
190 { return y <= TOP_Y1; }
261 const east = loadExample(`example-stone-${kind}-connecting.png`);
191 return y >= TOP_Y0 && y <= TOP_Y1;
262 const north = loadExample(`example-stone-${kind}-connecting-up.png`);
192}
263 const south = loadExample(`example-stone-${kind}-connecting-down.png`);
264 const ns = loadExample(`example-stone-${kind}-connecting-updown.png`);
265 const ellNE = loadExample(`example-stone-${kind}-connecting-L.png`);
266 const ellSE = loadExample(`example-stone-${kind}-connecting-Ldownright.png`);
267 const teeESW = loadExample(`example-stone-${kind}-T.png`)
268 ?? loadExample(`example-stone-${kind}-connecting-T.png`);
269 const teeNEW = loadExample(`example-stone-${kind}-connecting-T-upsidedown.png`);
193
270
194function paintWall (mask)
271 if (!alone || !east || !north || !ns)
195{
272 { throw new Error(`Missing core ${kind} examples in ${EXAMPLES}`); }
196 const rgba = new Uint8Array(SIZE * SIZE * 4);
197 const connectN = (mask & NeighborBit.n) !== 0;
198 const connectE = (mask & NeighborBit.e) !== 0;
199 const connectS = (mask & NeighborBit.s) !== 0;
200 const connectW = (mask & NeighborBit.w) !== 0;
201
273
202 for (let y = 0; y < SIZE; y++)
274 const west = mirrorX(east);
275 const southFinal = south ?? (() =>
203 {
276 {
204 for (let x = 0; x < SIZE; x++)
277 const out = copyRgba(alone);
278 for (let y = 10; y < SIZE; y++)
205 {
279 {
206 if (!inWall(x, y, connectN, connectE, connectS, connectW))
280 for (let x = 0; x < SIZE; x++)
207 { continue; }
281 {
282 if (opaque(ns, x, y))
283 { setPx(out, x, y, getPx(ns, x, y)); }
284 }
285 }
286 return out;
287 })();
208
288
209 const n = inWall(x, y - 1, connectN, connectE, connectS, connectW);
289 const ellNEFinal = ellNE ?? (() =>
210 const e = inWall(x + 1, y, connectN, connectE, connectS, connectW);
290 {
211 const s = inWall(x, y + 1, connectN, connectE, connectS, connectW);
291 const out = clearRgba();
212 const w = inWall(x - 1, y, connectN, connectE, connectS, connectW);
292 blit(out, north);
293 blit(out, east);
294 return out;
295 })();
296 const ellSEFinal = ellSE ?? (() =>
297 {
298 const out = clearRgba();
299 blit(out, southFinal);
300 blit(out, east);
301 return out;
302 })();
303 const ellNW = mirrorX(ellNEFinal);
304 const ellSW = mirrorX(ellSEFinal);
213
305
214 let base;
306 const ew = (() =>
215 if (isTopRow(y, connectN))
307 {
308 const out = clearRgba();
309 blit(out, east);
310 blit(out, west);
311 for (let y = 0; y < SIZE; y++)
312 {
313 if (!opaque(east, SIZE - 1, y))
314 { continue; }
315 let fill = null;
316 for (let x = SIZE - 1; x >= 0; x--)
216 {
317 {
217 if (!n)
318 const c = getPx(east, x, y);
218 { base = TOP_HI; }
319 if (c[3] > 128)
219 else if (!s && y === TOP_Y1)
320 { fill = c; break; }
220 { base = TOP_LO; }
221 else
222 { base = TOP; }
223 }
321 }
224 else
322 if (!fill)
323 { continue; }
324 for (let x = 0; x < SIZE; x++)
225 {
325 {
226 if (!s)
326 if (!opaque(out, x, y))
227 { base = FACE_LO; }
327 { setPx(out, x, y, fill); }
228 else if (!n)
229 { base = FACE_HI; }
230 else
231 { base = FACE; }
232 }
328 }
329 }
330 return out;
331 })();
233
332
234 // Free side bevels (not on edges that continue into a neighbour).
333 const teeESWFinal = teeESW ?? (() =>
235 const freeW = !w && !(connectW && x === 0);
334 {
236 const freeE = !e && !(connectE && x === SIZE - 1);
335 const out = clearRgba();
237 if (freeW || freeE)
336 blit(out, ew);
238 {
337 blit(out, southFinal);
239 if (base === TOP || base === TOP_HI)
338 return out;
240 { base = TOP_LO; }
339 })();
241 else if (base === FACE || base === FACE_HI)
340 const teeNEWFinal = teeNEW ?? (() =>
242 { base = EDGE; }
341 {
243 }
342 const out = clearRgba();
343 blit(out, ew);
344 blit(out, north);
345 return out;
346 })();
347 const teeNES = (() =>
348 {
349 const out = clearRgba();
350 blit(out, north);
351 blit(out, east);
352 blit(out, southFinal);
353 return out;
354 })();
355 const teeNWS = mirrorX(teeNES);
356 const all = (() =>
357 {
358 const out = clearRgba();
359 blit(out, ns);
360 blit(out, ew);
361 return out;
362 })();
244
363
245 setPx(rgba, x, y, cobbleShade(base, x, y));
364 const byMask = new Map([
246 }
365 [0, alone],
366 [NeighborBit.n, north],
367 [NeighborBit.e, east],
368 [NeighborBit.s, southFinal],
369 [NeighborBit.w, west],
370 [NeighborBit.n | NeighborBit.s, ns],
371 [NeighborBit.e | NeighborBit.w, ew],
372 [NeighborBit.n | NeighborBit.e, ellNEFinal],
373 [NeighborBit.e | NeighborBit.s, ellSEFinal],
374 [NeighborBit.s | NeighborBit.w, ellSW],
375 [NeighborBit.w | NeighborBit.n, ellNW],
376 [NeighborBit.e | NeighborBit.s | NeighborBit.w, teeESWFinal],
377 [NeighborBit.w | NeighborBit.n | NeighborBit.e, teeNEWFinal],
378 [NeighborBit.n | NeighborBit.e | NeighborBit.s, teeNES],
379 [NeighborBit.n | NeighborBit.w | NeighborBit.s, teeNWS],
380 [NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w, all]
381 ]);
382
383 return { byMask, alone, east, north, ns, ellNE: ellNEFinal };
384}
385
386function clearGenerated (dir)
387{
388 mkdirSync(dir, { recursive: true });
389 for (const name of readdirSync(dir))
390 {
391 if (!name.endsWith(".png") || name.startsWith("example"))
392 { continue; }
393 unlinkSync(join(dir, name));
247 }
394 }
248 return rgba;
249}
395}
250
396
251mkdirSync(OUT, { recursive: true });
397function writeSet (dir, def, pack)
252for (let mask = 0; mask < 16; mask++)
253{
398{
254 writeFileSync(join(OUT, `${mask}.png`), encodePng(paintWall(mask)));
399 clearGenerated(dir);
400 for (let mask = 0; mask < 16; mask++)
401 {
402 const rgba = pack.byMask.get(mask);
403 if (!rgba)
404 { throw new Error(`Missing mask ${mask} for ${def.key}`); }
405 const state = composeNamedNeighborConnectState(def, mask);
406 writeFileSync(join(dir, `${state}.png`), encodePng(rgba));
407 }
408 console.log(`Wrote 16 ${def.key} sprites → ${dir}`);
255}
409}
256console.log(`Wrote cobblestone frustum stone-wall sprites 0–15 to ${OUT}`);
410
411function removeLegacyFolders ()
412{
413 for (const name of ["stone-wall", "stone-wall-thin"])
414 {
415 const dir = join(ROOT, name);
416 if (!existsSync(dir))
417 { continue; }
418 // Keep examples only in _examples/; remove entire legacy folder.
419 rmSync(dir, { recursive: true, force: true });
420 console.log(`Removed legacy ${name}/`);
421 }
422}
423
424ensureExamples();
425const thin = buildPack("thin");
426const thick = buildPack("thick");
427
428function assertSame (a, b, label)
429{
430 for (let i = 0; i < a.length; i++)
431 {
432 if (a[i] !== b[i])
433 { throw new Error(`Mismatch ${label}`); }
434 }
435}
436assertSame(thin.byMask.get(0), thin.alone, "thin alone");
437assertSame(thin.byMask.get(1), thin.north, "thin n");
438assertSame(thin.byMask.get(2), thin.east, "thin e");
439assertSame(thin.byMask.get(5), thin.ns, "thin ns");
440assertSame(thick.byMask.get(0), thick.alone, "thick alone");
441
442writeSet(OUT_THIN, THIN, thin);
443writeSet(OUT_THICK, THICK, thick);
444removeLegacyFolders();
445
446console.log("Suffixes:", [...Array(16)].map((_, m) => `${m}=${cardinalConnectionSuffix(m) || "(alone)"}`).join(", "));
client/scripts/texture-stone-wall-sprites.mjs added +13 −0
@@ -0,0 +1,13 @@
1 /**
2 * Bake grey cobblestone onto thick/thin stone-wall shape masks.
3 * Delegates to texture-wall-sprites.mjs --variant=cobble
4 *
5 * node client/scripts/texture-stone-wall-sprites.mjs
6 */
7 import { spawnSync } from "node:child_process";
8 import { fileURLToPath } from "node:url";
9 import { dirname, join } from "node:path";
10
11 const script = join(dirname(fileURLToPath(import.meta.url)), "texture-wall-sprites.mjs");
12 const result = spawnSync(process.execPath, [script, "--variant=cobble"], { stdio: "inherit" });
13 process.exit(result.status ?? 1);
@@ -0,0 +1,13 @@
1/**
2 * Bake grey cobblestone onto thick/thin stone-wall shape masks.
3 * Delegates to texture-wall-sprites.mjs --variant=cobble
4 *
5 * node client/scripts/texture-stone-wall-sprites.mjs
6 */
7import { spawnSync } from "node:child_process";
8import { fileURLToPath } from "node:url";
9import { dirname, join } from "node:path";
10
11const script = join(dirname(fileURLToPath(import.meta.url)), "texture-wall-sprites.mjs");
12const result = spawnSync(process.execPath, [script, "--variant=cobble"], { stdio: "inherit" });
13process.exit(result.status ?? 1);
client/scripts/texture-wall-sprites.mjs added +714 −0
@@ -0,0 +1,714 @@
1 /**
2 * Bake wall textures onto thick/thin greyscale face-id shape masks.
3 *
4 * Shape masks (greyscale face-IDs) belong in:
5 * client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png
6 *
7 * Workflow when editing shapes in the live gameplay folders:
8 * 1. Paint face-id greys in thick-stone-wall / thin-stone-wall
9 * 2. node client/scripts/texture-wall-sprites.mjs --sync-shapes
10 * (copies live → examples only if files are still face-id greyscale)
11 * 3. node client/scripts/texture-wall-sprites.mjs --variant=…
12 *
13 * Usage:
14 * node client/scripts/texture-wall-sprites.mjs --sync-shapes
15 * node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff|--all
16 *
17 * cobble overwrites thick/thin-stone-wall — pass --force (required) so hand tweaks are not clobbered.
18 */
19 import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync, cpSync } from "node:fs";
20 import { deflateSync, inflateSync } from "node:zlib";
21 import { fileURLToPath } from "node:url";
22 import { dirname, join } from "node:path";
23 import { cardinalConnectionSuffix } from "../../shared/world/neighborConnect.js";
24
25 const SIZE = 16;
26 const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
27 const EXAMPLES = join(ROOT, "_examples/stone-wall");
28 const GROUNDS = join(dirname(fileURLToPath(import.meta.url)), "../assets/grounds");
29
30 const THICK_ROLE = {
31 0xaf: "N",
32 0x95: "W",
33 0x80: "T",
34 0x6c: "E",
35 0x54: "S",
36 0x40: "O"
37 };
38
39 const THIN_ROLE = {
40 0xb6: "W",
41 0x95: "N",
42 0x80: "E",
43 0x73: "S",
44 0x40: "O"
45 };
46
47 function roleOf (prefix, g)
48 {
49 const map = prefix.startsWith("thin") ? THIN_ROLE : THICK_ROLE;
50 return map[g] ?? null;
51 }
52
53 function isTopRole (role)
54 {
55 return role === "T" || role === "N";
56 }
57
58 function crcTable ()
59 {
60 const table = new Uint32Array(256);
61 for (let n = 0; n < 256; n++)
62 {
63 let c = n;
64 for (let k = 0; k < 8; k++)
65 { c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); }
66 table[n] = c >>> 0;
67 }
68 return table;
69 }
70
71 const CRC_TABLE = crcTable();
72
73 function crc32 (buf)
74 {
75 let c = 0xffffffff;
76 for (let i = 0; i < buf.length; i++)
77 { c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); }
78 return (c ^ 0xffffffff) >>> 0;
79 }
80
81 function chunk (type, data)
82 {
83 const len = Buffer.alloc(4);
84 len.writeUInt32BE(data.length);
85 const typeBuf = Buffer.from(type, "ascii");
86 const crcBuf = Buffer.alloc(4);
87 crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])));
88 return Buffer.concat([len, typeBuf, data, crcBuf]);
89 }
90
91 function encodePng (rgba)
92 {
93 const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE);
94 for (let y = 0; y < SIZE; y++)
95 {
96 const row = y * (SIZE * 4 + 1);
97 raw[row] = 0;
98 for (let x = 0; x < SIZE; x++)
99 {
100 const i = (y * SIZE + x) * 4;
101 const o = row + 1 + x * 4;
102 raw[o] = rgba[i];
103 raw[o + 1] = rgba[i + 1];
104 raw[o + 2] = rgba[i + 2];
105 raw[o + 3] = rgba[i + 3];
106 }
107 }
108 const ihdr = Buffer.alloc(13);
109 ihdr.writeUInt32BE(SIZE, 0);
110 ihdr.writeUInt32BE(SIZE, 4);
111 ihdr[8] = 8;
112 ihdr[9] = 6;
113 return Buffer.concat([
114 Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
115 chunk("IHDR", ihdr),
116 chunk("IDAT", deflateSync(raw, { level: 9 })),
117 chunk("IEND", Buffer.alloc(0))
118 ]);
119 }
120
121 function decodePngRgba (path)
122 {
123 const buf = readFileSync(path);
124 let off = 8;
125 let w = 0;
126 let h = 0;
127 let colorType = 6;
128 const idat = [];
129 while (off < buf.length)
130 {
131 const len = buf.readUInt32BE(off);
132 const type = buf.slice(off + 4, off + 8).toString("ascii");
133 const data = buf.slice(off + 8, off + 8 + len);
134 if (type === "IHDR")
135 {
136 w = data.readUInt32BE(0);
137 h = data.readUInt32BE(4);
138 colorType = data[9];
139 }
140 else if (type === "IDAT")
141 { idat.push(data); }
142 else if (type === "IEND")
143 { break; }
144 off += 12 + len;
145 }
146 const channels = colorType === 2 ? 3 : colorType === 6 ? 4 : 0;
147 if (!channels)
148 { throw new Error(`${path}: unsupported PNG color type ${colorType}`); }
149 const inflated = inflateSync(Buffer.concat(idat));
150 const rgba = new Uint8Array(w * h * 4);
151 let src = 0;
152 const prevRow = new Uint8Array(w * channels);
153 const curRow = new Uint8Array(w * channels);
154 for (let y = 0; y < h; y++)
155 {
156 const filter = inflated[src++];
157 for (let i = 0; i < w * channels; i++)
158 {
159 let v = inflated[src++];
160 if (filter === 1)
161 { v = (v + (i >= channels ? curRow[i - channels] : 0)) & 255; }
162 else if (filter === 2)
163 { v = (v + prevRow[i]) & 255; }
164 else if (filter === 3)
165 {
166 const a = i >= channels ? curRow[i - channels] : 0;
167 v = (v + Math.floor((a + prevRow[i]) / 2)) & 255;
168 }
169 else if (filter === 4)
170 {
171 const a = i >= channels ? curRow[i - channels] : 0;
172 const b = prevRow[i];
173 const c = i >= channels ? prevRow[i - channels] : 0;
174 const p = a + b - c;
175 const pa = Math.abs(p - a);
176 const pb = Math.abs(p - b);
177 const pc = Math.abs(p - c);
178 v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255;
179 }
180 curRow[i] = v;
181 }
182 for (let x = 0; x < w; x++)
183 {
184 const si = x * channels;
185 const di = (y * w + x) * 4;
186 rgba[di] = curRow[si];
187 rgba[di + 1] = curRow[si + 1];
188 rgba[di + 2] = curRow[si + 2];
189 rgba[di + 3] = channels === 4 ? curRow[si + 3] : 255;
190 }
191 prevRow.set(curRow);
192 }
193 if (w !== SIZE || h !== SIZE)
194 { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
195 return rgba;
196 }
197
198 function hash2 (x, y)
199 {
200 let n = (x * 374761393 + y * 668265263) | 0;
201 n = (n ^ (n >>> 13)) * 1274126177;
202 return (n ^ (n >>> 16)) >>> 0;
203 }
204
205 function rgba (r, g, b, a = 255)
206 {
207 return [r, g, b, a];
208 }
209
210 function mulRgb (c, factor)
211 {
212 return rgba(
213 Math.min(255, Math.round(c[0] * factor)),
214 Math.min(255, Math.round(c[1] * factor)),
215 Math.min(255, Math.round(c[2] * factor)),
216 c[3] ?? 255
217 );
218 }
219
220 function mixRgb (a, b, t)
221 {
222 return rgba(
223 Math.round(a[0] + (b[0] - a[0]) * t),
224 Math.round(a[1] + (b[1] - a[1]) * t),
225 Math.round(a[2] + (b[2] - a[2]) * t),
226 255
227 );
228 }
229
230 /** Face role → lighting factor (NW light). */
231 const ROLE_LIT = { N: 1.15, W: 1.0, T: 1.05, E: 0.82, S: 0.62, O: 0.45 };
232
233 function faceLit (role)
234 {
235 return ROLE_LIT[role] ?? 0.9;
236 }
237
238 function loadDirt ()
239 {
240 const path = join(GROUNDS, "dirt/dirt.png");
241 if (!existsSync(path))
242 { throw new Error(`Missing dirt texture: ${path}`); }
243 return decodePngRgba(path);
244 }
245
246 let dirtRgba = null;
247 function dirtAt (x, y)
248 {
249 if (!dirtRgba)
250 { dirtRgba = loadDirt(); }
251 const i = ((y & 15) * SIZE + (x & 15)) * 4;
252 return rgba(dirtRgba[i], dirtRgba[i + 1], dirtRgba[i + 2]);
253 }
254
255 /* ---- palettes ---- */
256
257 const COBBLE = {
258 N: rgba(198, 198, 202),
259 W: rgba(132, 132, 136),
260 T: rgba(168, 168, 172),
261 E: rgba(112, 112, 116),
262 S: rgba(88, 88, 92),
263 O: rgba(70, 70, 74),
264 mortar: rgba(78, 78, 82),
265 hiN: rgba(210, 210, 214),
266 loS: rgba(78, 78, 82)
267 };
268
269 const BRICK = {
270 N: rgba(196, 92, 72),
271 W: rgba(168, 72, 56),
272 T: rgba(178, 78, 60),
273 E: rgba(148, 58, 46),
274 S: rgba(118, 48, 38),
275 O: rgba(72, 36, 30),
276 mortar: rgba(92, 78, 68),
277 hi: rgba(210, 110, 88),
278 lo: rgba(100, 42, 34),
279 /** Flat cement cap (no brick bond on tops). */
280 cement: rgba(168, 160, 152),
281 cementHi: rgba(184, 176, 168),
282 cementLo: rgba(148, 140, 132)
283 };
284
285 function cobbleLike (basePal, x, y, role, gritMask)
286 {
287 if (role === "O")
288 {
289 const h = hash2(x, y);
290 return (h & 15) === 0 ? basePal.mortar : basePal.O;
291 }
292 const base = basePal[role] ?? basePal.T;
293 const h = hash2(x, y);
294 const speck = h & gritMask;
295 if (speck === 0)
296 { return basePal.mortar; }
297 if (gritMask === 7)
298 {
299 if (speck === 1 || speck === 2)
300 { return role === "N" || role === "T" ? (basePal.hiN ?? basePal.hi ?? mulRgb(base, 1.12)) : (basePal.hi ?? mulRgb(base, 1.1)); }
301 if (speck === 3)
302 { return role === "S" ? (basePal.loS ?? basePal.lo ?? mulRgb(base, 0.88)) : (basePal.lo ?? mulRgb(base, 0.9)); }
303 }
304 else if (gritMask === 31)
305 {
306 // Smooth: rare soft variation only.
307 if (speck === 1)
308 { return mulRgb(base, 1.06); }
309 if (speck === 2)
310 { return mulRgb(base, 0.94); }
311 }
312 return base;
313 }
314
315 /**
316 * Brick mortar follows each face:
317 * - T (thick) / N (thin ridge): flat cement cap
318 * - S: running bond elevation
319 * - N (thick bevel): vertical joints along the rim
320 * - W / E: diagonal course marks — outer column 1px below inner
321 */
322 function brickShade (x, y, role, shapePrefix, faceRgba)
323 {
324 if (role === "O")
325 { return BRICK.O; }
326
327 const thin = shapePrefix.startsWith("thin");
328 const isCap = role === "T" || (thin && role === "N");
329 if (isCap)
330 {
331 const h = hash2(x, y);
332 if ((h & 31) === 0)
333 { return BRICK.cementHi; }
334 if ((h & 31) === 1)
335 { return BRICK.cementLo; }
336 return BRICK.cement;
337 }
338
339 const courseH = 4;
340 const brickW = 6;
341 let onMortar = false;
342
343 if (role === "W" || role === "E")
344 {
345 const phase = y % courseH;
346 const outer = role === "W"
347 ? !isSameFace(faceRgba, x - 1, y, role, shapePrefix)
348 : !isSameFace(faceRgba, x + 1, y, role, shapePrefix);
349 // Diagonal: ·O then O· on west (outer 1px down); mirrored on east.
350 if (phase === 0)
351 { onMortar = !outer; }
352 else if (phase === 1)
353 { onMortar = outer; }
354 }
355 else if (role === "N")
356 {
357 onMortar = (x % brickW) === 0;
358 }
359 else
360 {
361 const row = Math.floor(y / courseH);
362 const brickX = x + (row & 1) * Math.floor(brickW / 2);
363 onMortar = (y % courseH) === 0 || (brickX % brickW) === 0;
364 }
365
366 if (onMortar)
367 { return BRICK.mortar; }
368
369 const h = hash2(x + role.charCodeAt(0) * 17, y);
370 if ((h & 15) === 0)
371 { return BRICK.hi; }
372 if ((h & 15) === 1)
373 { return BRICK.lo; }
374 return BRICK[role] ?? BRICK.T;
375 }
376
377 function isSameFace (faceRgba, x, y, role, shapePrefix)
378 {
379 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE || !faceRgba)
380 { return false; }
381 const i = (y * SIZE + x) * 4;
382 if (faceRgba[i + 3] === 0)
383 { return false; }
384 return roleOf(shapePrefix, faceRgba[i]) === role;
385 }
386
387 function woodMagenta (role)
388 {
389 // Flat fallback (role only) — prefer woodShade for textured planks.
390 const L = {
391 O: 55,
392 S: 95,
393 E: 113,
394 W: 143,
395 T: 177,
396 N: 205
397 }[role] ?? 140;
398 const gHi = role === "N" || role === "T" ? Math.min(L - 20, 50) : 0;
399 return rgba(L, gHi, L);
400 }
401
402 /** Magenta (R=B, G<R) with face-aware plank grain, matching authored thick 1×1. */
403 function mag (L, g = 0)
404 {
405 const lit = Math.max(1, Math.min(255, L | 0));
406 const gv = Math.max(0, Math.min(lit - 1, g | 0));
407 return rgba(lit, gv, lit);
408 }
409
410 /**
411 * Wood planks by face (from thick-wood-wall/0.png reference):
412 * - S: vertical boards (~4px), alternating grain by board+row
413 * - W/E: horizontal plank bands; outer/inner columns swap each band (diagonal step)
414 * - T: N–S boards with brighter center grain + slight G highlight
415 * - N: bright rim, two-tone split
416 */
417 function woodShade (x, y, role, shapePrefix, faceRgba)
418 {
419 if (role === "O")
420 { return mag(55); }
421
422 if (role === "S")
423 {
424 const board = Math.floor(x / 4);
425 const light = ((board + y) & 1) !== 0;
426 return mag(light ? 102 : 95);
427 }
428
429 if (role === "W" || role === "E")
430 {
431 const lo = role === "W" ? 143 : 113;
432 const hi = role === "W" ? 155 : 120;
433 // Plank bands ~5px tall, aligned like authored alone (y2–6, y7–11, …).
434 const band = Math.floor(Math.max(0, y - 2) / 5);
435 const outer = role === "W"
436 ? !isSameFace(faceRgba, x - 1, y, role, shapePrefix)
437 : !isSameFace(faceRgba, x + 1, y, role, shapePrefix);
438 const swap = (band & 1) !== 0;
439 let useHi;
440 if (outer)
441 { useHi = swap; }
442 else
443 { useHi = !swap; }
444 return mag(useHi ? hi : lo);
445 }
446
447 if (role === "T" || (shapePrefix.startsWith("thin") && role === "N"))
448 {
449 const rowTone = (y & 1) !== 0;
450 const leftEdge = !isSameFace(faceRgba, x - 1, y, role, shapePrefix);
451 const rightEdge = !isSameFace(faceRgba, x + 1, y, role, shapePrefix);
452 const edge = leftEdge || rightEdge;
453 let L;
454 if (edge)
455 { L = rowTone ? 161 : 159; }
456 else
457 { L = rowTone ? 177 : 168; }
458 const g = rowTone ? 20 : 0;
459 return mag(L, g);
460 }
461
462 if (role === "N")
463 {
464 // Thick north bevel: split highlight
465 const L = x < 8 ? 200 : 210;
466 return mag(L, x < 8 ? 47 : 50);
467 }
468
469 return woodMagenta(role);
470 }
471
472 /**
473 * Cliff magenta tops: thick = plateau only (N is a dirt north face).
474 * Thin has no separate T — ridge top is role N.
475 */
476 function isCliffTopRole (role, shapePrefix)
477 {
478 if (shapePrefix.startsWith("thin"))
479 { return role === "N"; }
480 return role === "T";
481 }
482
483 function cliffShade (x, y, role, shapePrefix)
484 {
485 if (isCliffTopRole(role, shapePrefix))
486 {
487 // Full magenta top — replaced in-game by ground sample shader.
488 return rgba(255, 0, 255);
489 }
490 if (role === "O")
491 {
492 const d = dirtAt(x, y);
493 return mulRgb(d, 0.35);
494 }
495 const d = dirtAt(x, y);
496 return mulRgb(d, faceLit(role));
497 }
498
499 function paintPixel (variant, prefix, g, x, y, faceRgba = null)
500 {
501 const role = roleOf(prefix, g);
502 if (!role)
503 {
504 // Unknown grey: luminance fallback toward mid face.
505 const lit = g / 128;
506 if (variant === "wood")
507 { return rgba(Math.round(140 * lit), 0, Math.round(140 * lit)); }
508 if (variant === "cliff")
509 { return mulRgb(dirtAt(x, y), lit); }
510 if (variant === "brick")
511 { return mulRgb(BRICK.cement, lit); }
512 return mulRgb(COBBLE.T, lit);
513 }
514 if (variant === "cobble")
515 { return cobbleLike(COBBLE, x, y, role, 7); }
516 if (variant === "smooth")
517 { return cobbleLike(COBBLE, x, y, role, 31); }
518 if (variant === "brick")
519 { return brickShade(x, y, role, prefix, faceRgba); }
520 if (variant === "wood")
521 { return woodShade(x, y, role, prefix, faceRgba); }
522 if (variant === "cliff")
523 { return cliffShade(x, y, role, prefix); }
524 throw new Error(`Unknown variant ${variant}`);
525 }
526
527 function textureMask (rgbaIn, variant, shapePrefix)
528 {
529 const out = new Uint8Array(SIZE * SIZE * 4);
530 for (let y = 0; y < SIZE; y++)
531 {
532 for (let x = 0; x < SIZE; x++)
533 {
534 const i = (y * SIZE + x) * 4;
535 if (rgbaIn[i + 3] === 0)
536 { continue; }
537 const color = paintPixel(variant, shapePrefix, rgbaIn[i], x, y, rgbaIn);
538 out[i] = color[0];
539 out[i + 1] = color[1];
540 out[i + 2] = color[2];
541 out[i + 3] = 255;
542 }
543 }
544 return out;
545 }
546
547 const VARIANT_OUT = {
548 cobble: {
549 thick: { dir: "thick-stone-wall", named: true, prefix: "thick-stone-wall" },
550 thin: { dir: "thin-stone-wall", named: true, prefix: "thin-stone-wall" }
551 },
552 smooth: {
553 thick: { dir: "thick-smooth-stone-wall", named: true, prefix: "thick-smooth-stone-wall" },
554 thin: { dir: "thin-smooth-stone-wall", named: true, prefix: "thin-smooth-stone-wall" }
555 },
556 brick: {
557 thick: { dir: "thick-brick-wall", named: true, prefix: "thick-brick-wall" },
558 thin: { dir: "thin-brick-wall", named: true, prefix: "thin-brick-wall" }
559 },
560 wood: {
561 thick: { dir: "thick-wood-wall", named: false, prefix: "thick-stone-wall" },
562 thin: { dir: "thin-wood-wall", named: false, prefix: "thin-stone-wall" }
563 },
564 cliff: {
565 thick: { dir: "thick-cliff", named: true, prefix: "thick-cliff" },
566 thin: { dir: "thin-cliff", named: true, prefix: "thin-cliff" }
567 }
568 };
569
570 function shapeFiles (shapeKey)
571 {
572 return readdirSync(EXAMPLES)
573 .filter((name) => name.startsWith(shapeKey) && name.endsWith(".png") && !name.includes("ref-"))
574 .sort();
575 }
576
577 function namedOutName (outPrefix, shapeName, shapeKey)
578 {
579 // thick-stone-wall-esw.png → thick-smooth-stone-wall-esw.png
580 const suffix = shapeName.slice(shapeKey.length); // "" or "-esw"
581 return `${outPrefix}${suffix}`;
582 }
583
584 const FACE_ID_GREYS = new Set([
585 0x40, 0x54, 0x6c, 0x73, 0x80, 0x95, 0xaf, 0xb6
586 ]);
587
588 function isFaceIdMask (rgba)
589 {
590 for (let i = 0; i < rgba.length; i += 4)
591 {
592 if (rgba[i + 3] === 0)
593 { continue; }
594 if (rgba[i] !== rgba[i + 1] || rgba[i] !== rgba[i + 2])
595 { return false; }
596 if (!FACE_ID_GREYS.has(rgba[i]))
597 { return false; }
598 }
599 return true;
600 }
601
602 /** Copy face-id greyscale from live thick/thin-stone-wall → _examples (never textured art). */
603 function syncShapesFromLive ()
604 {
605 mkdirSync(EXAMPLES, { recursive: true });
606 let copied = 0;
607 for (const kind of ["thick", "thin"])
608 {
609 const shapeKey = `${kind}-stone-wall`;
610 const liveDir = join(ROOT, shapeKey);
611 if (!existsSync(liveDir))
612 { throw new Error(`Missing live folder ${liveDir}`); }
613 const files = readdirSync(liveDir)
614 .filter((name) => name.startsWith(shapeKey) && name.endsWith(".png"))
615 .sort();
616 if (files.length !== 16)
617 { throw new Error(`Expected 16 live ${shapeKey} sprites, found ${files.length}`); }
618 for (const name of files)
619 {
620 const rgba = decodePngRgba(join(liveDir, name));
621 if (!isFaceIdMask(rgba))
622 {
623 throw new Error(
624 `${shapeKey}/${name} is not a face-id greyscale mask (already textured?). ` +
625 `Paint face-id greys in the live folder, then re-run --sync-shapes.`
626 );
627 }
628 cpSync(join(liveDir, name), join(EXAMPLES, name));
629 copied++;
630 }
631 console.log(` synced ${kind} → ${EXAMPLES}`);
632 }
633 console.log(`Synced ${copied} face-id masks into examples.`);
634 }
635
636 function bakeVariant (variant, { force = false } = {})
637 {
638 const cfg = VARIANT_OUT[variant];
639 if (!cfg)
640 { throw new Error(`Unknown variant: ${variant}`); }
641 if (variant === "cobble" && !force)
642 {
643 throw new Error(
644 "Refusing to overwrite thick/thin-stone-wall without --force " +
645 "(hand-tweaked gameplay sprites). Sync shapes with --sync-shapes first if needed."
646 );
647 }
648 let wrote = 0;
649 for (const kind of ["thick", "thin"])
650 {
651 const shapeKey = `${kind}-stone-wall`;
652 const out = cfg[kind];
653 const outDir = join(ROOT, out.dir);
654 mkdirSync(outDir, { recursive: true });
655 const files = shapeFiles(shapeKey);
656 if (files.length !== 16)
657 { throw new Error(`Expected 16 ${shapeKey} masks, found ${files.length}`); }
658
659 if (out.named)
660 {
661 for (const name of files)
662 {
663 const shaped = decodePngRgba(join(EXAMPLES, name));
664 const textured = textureMask(shaped, variant, shapeKey);
665 const outName = namedOutName(out.prefix, name, shapeKey);
666 writeFileSync(join(outDir, outName), encodePng(textured));
667 wrote++;
668 }
669 }
670 else
671 {
672 for (let mask = 0; mask < 16; mask++)
673 {
674 const suffix = cardinalConnectionSuffix(mask);
675 const shapeName = suffix ? `${shapeKey}-${suffix}.png` : `${shapeKey}.png`;
676 const shaped = decodePngRgba(join(EXAMPLES, shapeName));
677 const textured = textureMask(shaped, variant, shapeKey);
678 writeFileSync(join(outDir, `${mask}.png`), encodePng(textured));
679 wrote++;
680 }
681 }
682 console.log(` ${variant} ${kind} → ${outDir} (${out.named ? "named" : "0–15"})`);
683 }
684 return wrote;
685 }
686
687 if (process.argv.includes("--sync-shapes"))
688 {
689 syncShapesFromLive();
690 process.exit(0);
691 }
692
693 const arg = process.argv.find((a) => a.startsWith("--variant="));
694 const variant = arg ? arg.slice("--variant=".length) : null;
695 if (!variant)
696 {
697 console.error("Usage: --sync-shapes | --variant=cobble|smooth|brick|wood|cliff|all [--force]");
698 process.exit(1);
699 }
700 const force = process.argv.includes("--force");
701 const list = variant === "all"
702 ? ["cobble", "smooth", "brick", "wood", "cliff"]
703 : [variant];
704
705 if (!existsSync(EXAMPLES))
706 { throw new Error(`Missing ${EXAMPLES}`); }
707
708 let total = 0;
709 for (const v of list)
710 {
711 console.log(`Baking ${v}…`);
712 total += bakeVariant(v, { force });
713 }
714 console.log(`Done (${total} sprites).`);
@@ -0,0 +1,714 @@
1/**
2 * Bake wall textures onto thick/thin greyscale face-id shape masks.
3 *
4 * Shape masks (greyscale face-IDs) belong in:
5 * client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png
6 *
7 * Workflow when editing shapes in the live gameplay folders:
8 * 1. Paint face-id greys in thick-stone-wall / thin-stone-wall
9 * 2. node client/scripts/texture-wall-sprites.mjs --sync-shapes
10 * (copies live → examples only if files are still face-id greyscale)
11 * 3. node client/scripts/texture-wall-sprites.mjs --variant=…
12 *
13 * Usage:
14 * node client/scripts/texture-wall-sprites.mjs --sync-shapes
15 * node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff|--all
16 *
17 * cobble overwrites thick/thin-stone-wall — pass --force (required) so hand tweaks are not clobbered.
18 */
19import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync, cpSync } from "node:fs";
20import { deflateSync, inflateSync } from "node:zlib";
21import { fileURLToPath } from "node:url";
22import { dirname, join } from "node:path";
23import { cardinalConnectionSuffix } from "../../shared/world/neighborConnect.js";
24
25const SIZE = 16;
26const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
27const EXAMPLES = join(ROOT, "_examples/stone-wall");
28const GROUNDS = join(dirname(fileURLToPath(import.meta.url)), "../assets/grounds");
29
30const THICK_ROLE = {
31 0xaf: "N",
32 0x95: "W",
33 0x80: "T",
34 0x6c: "E",
35 0x54: "S",
36 0x40: "O"
37};
38
39const THIN_ROLE = {
40 0xb6: "W",
41 0x95: "N",
42 0x80: "E",
43 0x73: "S",
44 0x40: "O"
45};
46
47function roleOf (prefix, g)
48{
49 const map = prefix.startsWith("thin") ? THIN_ROLE : THICK_ROLE;
50 return map[g] ?? null;
51}
52
53function isTopRole (role)
54{
55 return role === "T" || role === "N";
56}
57
58function crcTable ()
59{
60 const table = new Uint32Array(256);
61 for (let n = 0; n < 256; n++)
62 {
63 let c = n;
64 for (let k = 0; k < 8; k++)
65 { c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); }
66 table[n] = c >>> 0;
67 }
68 return table;
69}
70
71const CRC_TABLE = crcTable();
72
73function crc32 (buf)
74{
75 let c = 0xffffffff;
76 for (let i = 0; i < buf.length; i++)
77 { c = CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8); }
78 return (c ^ 0xffffffff) >>> 0;
79}
80
81function chunk (type, data)
82{
83 const len = Buffer.alloc(4);
84 len.writeUInt32BE(data.length);
85 const typeBuf = Buffer.from(type, "ascii");
86 const crcBuf = Buffer.alloc(4);
87 crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])));
88 return Buffer.concat([len, typeBuf, data, crcBuf]);
89}
90
91function encodePng (rgba)
92{
93 const raw = Buffer.alloc((SIZE * 4 + 1) * SIZE);
94 for (let y = 0; y < SIZE; y++)
95 {
96 const row = y * (SIZE * 4 + 1);
97 raw[row] = 0;
98 for (let x = 0; x < SIZE; x++)
99 {
100 const i = (y * SIZE + x) * 4;
101 const o = row + 1 + x * 4;
102 raw[o] = rgba[i];
103 raw[o + 1] = rgba[i + 1];
104 raw[o + 2] = rgba[i + 2];
105 raw[o + 3] = rgba[i + 3];
106 }
107 }
108 const ihdr = Buffer.alloc(13);
109 ihdr.writeUInt32BE(SIZE, 0);
110 ihdr.writeUInt32BE(SIZE, 4);
111 ihdr[8] = 8;
112 ihdr[9] = 6;
113 return Buffer.concat([
114 Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
115 chunk("IHDR", ihdr),
116 chunk("IDAT", deflateSync(raw, { level: 9 })),
117 chunk("IEND", Buffer.alloc(0))
118 ]);
119}
120
121function decodePngRgba (path)
122{
123 const buf = readFileSync(path);
124 let off = 8;
125 let w = 0;
126 let h = 0;
127 let colorType = 6;
128 const idat = [];
129 while (off < buf.length)
130 {
131 const len = buf.readUInt32BE(off);
132 const type = buf.slice(off + 4, off + 8).toString("ascii");
133 const data = buf.slice(off + 8, off + 8 + len);
134 if (type === "IHDR")
135 {
136 w = data.readUInt32BE(0);
137 h = data.readUInt32BE(4);
138 colorType = data[9];
139 }
140 else if (type === "IDAT")
141 { idat.push(data); }
142 else if (type === "IEND")
143 { break; }
144 off += 12 + len;
145 }
146 const channels = colorType === 2 ? 3 : colorType === 6 ? 4 : 0;
147 if (!channels)
148 { throw new Error(`${path}: unsupported PNG color type ${colorType}`); }
149 const inflated = inflateSync(Buffer.concat(idat));
150 const rgba = new Uint8Array(w * h * 4);
151 let src = 0;
152 const prevRow = new Uint8Array(w * channels);
153 const curRow = new Uint8Array(w * channels);
154 for (let y = 0; y < h; y++)
155 {
156 const filter = inflated[src++];
157 for (let i = 0; i < w * channels; i++)
158 {
159 let v = inflated[src++];
160 if (filter === 1)
161 { v = (v + (i >= channels ? curRow[i - channels] : 0)) & 255; }
162 else if (filter === 2)
163 { v = (v + prevRow[i]) & 255; }
164 else if (filter === 3)
165 {
166 const a = i >= channels ? curRow[i - channels] : 0;
167 v = (v + Math.floor((a + prevRow[i]) / 2)) & 255;
168 }
169 else if (filter === 4)
170 {
171 const a = i >= channels ? curRow[i - channels] : 0;
172 const b = prevRow[i];
173 const c = i >= channels ? prevRow[i - channels] : 0;
174 const p = a + b - c;
175 const pa = Math.abs(p - a);
176 const pb = Math.abs(p - b);
177 const pc = Math.abs(p - c);
178 v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255;
179 }
180 curRow[i] = v;
181 }
182 for (let x = 0; x < w; x++)
183 {
184 const si = x * channels;
185 const di = (y * w + x) * 4;
186 rgba[di] = curRow[si];
187 rgba[di + 1] = curRow[si + 1];
188 rgba[di + 2] = curRow[si + 2];
189 rgba[di + 3] = channels === 4 ? curRow[si + 3] : 255;
190 }
191 prevRow.set(curRow);
192 }
193 if (w !== SIZE || h !== SIZE)
194 { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
195 return rgba;
196}
197
198function hash2 (x, y)
199{
200 let n = (x * 374761393 + y * 668265263) | 0;
201 n = (n ^ (n >>> 13)) * 1274126177;
202 return (n ^ (n >>> 16)) >>> 0;
203}
204
205function rgba (r, g, b, a = 255)
206{
207 return [r, g, b, a];
208}
209
210function mulRgb (c, factor)
211{
212 return rgba(
213 Math.min(255, Math.round(c[0] * factor)),
214 Math.min(255, Math.round(c[1] * factor)),
215 Math.min(255, Math.round(c[2] * factor)),
216 c[3] ?? 255
217 );
218}
219
220function mixRgb (a, b, t)
221{
222 return rgba(
223 Math.round(a[0] + (b[0] - a[0]) * t),
224 Math.round(a[1] + (b[1] - a[1]) * t),
225 Math.round(a[2] + (b[2] - a[2]) * t),
226 255
227 );
228}
229
230/** Face role → lighting factor (NW light). */
231const ROLE_LIT = { N: 1.15, W: 1.0, T: 1.05, E: 0.82, S: 0.62, O: 0.45 };
232
233function faceLit (role)
234{
235 return ROLE_LIT[role] ?? 0.9;
236}
237
238function loadDirt ()
239{
240 const path = join(GROUNDS, "dirt/dirt.png");
241 if (!existsSync(path))
242 { throw new Error(`Missing dirt texture: ${path}`); }
243 return decodePngRgba(path);
244}
245
246let dirtRgba = null;
247function dirtAt (x, y)
248{
249 if (!dirtRgba)
250 { dirtRgba = loadDirt(); }
251 const i = ((y & 15) * SIZE + (x & 15)) * 4;
252 return rgba(dirtRgba[i], dirtRgba[i + 1], dirtRgba[i + 2]);
253}
254
255/* ---- palettes ---- */
256
257const COBBLE = {
258 N: rgba(198, 198, 202),
259 W: rgba(132, 132, 136),
260 T: rgba(168, 168, 172),
261 E: rgba(112, 112, 116),
262 S: rgba(88, 88, 92),
263 O: rgba(70, 70, 74),
264 mortar: rgba(78, 78, 82),
265 hiN: rgba(210, 210, 214),
266 loS: rgba(78, 78, 82)
267};
268
269const BRICK = {
270 N: rgba(196, 92, 72),
271 W: rgba(168, 72, 56),
272 T: rgba(178, 78, 60),
273 E: rgba(148, 58, 46),
274 S: rgba(118, 48, 38),
275 O: rgba(72, 36, 30),
276 mortar: rgba(92, 78, 68),
277 hi: rgba(210, 110, 88),
278 lo: rgba(100, 42, 34),
279 /** Flat cement cap (no brick bond on tops). */
280 cement: rgba(168, 160, 152),
281 cementHi: rgba(184, 176, 168),
282 cementLo: rgba(148, 140, 132)
283};
284
285function cobbleLike (basePal, x, y, role, gritMask)
286{
287 if (role === "O")
288 {
289 const h = hash2(x, y);
290 return (h & 15) === 0 ? basePal.mortar : basePal.O;
291 }
292 const base = basePal[role] ?? basePal.T;
293 const h = hash2(x, y);
294 const speck = h & gritMask;
295 if (speck === 0)
296 { return basePal.mortar; }
297 if (gritMask === 7)
298 {
299 if (speck === 1 || speck === 2)
300 { return role === "N" || role === "T" ? (basePal.hiN ?? basePal.hi ?? mulRgb(base, 1.12)) : (basePal.hi ?? mulRgb(base, 1.1)); }
301 if (speck === 3)
302 { return role === "S" ? (basePal.loS ?? basePal.lo ?? mulRgb(base, 0.88)) : (basePal.lo ?? mulRgb(base, 0.9)); }
303 }
304 else if (gritMask === 31)
305 {
306 // Smooth: rare soft variation only.
307 if (speck === 1)
308 { return mulRgb(base, 1.06); }
309 if (speck === 2)
310 { return mulRgb(base, 0.94); }
311 }
312 return base;
313}
314
315/**
316 * Brick mortar follows each face:
317 * - T (thick) / N (thin ridge): flat cement cap
318 * - S: running bond elevation
319 * - N (thick bevel): vertical joints along the rim
320 * - W / E: diagonal course marks — outer column 1px below inner
321 */
322function brickShade (x, y, role, shapePrefix, faceRgba)
323{
324 if (role === "O")
325 { return BRICK.O; }
326
327 const thin = shapePrefix.startsWith("thin");
328 const isCap = role === "T" || (thin && role === "N");
329 if (isCap)
330 {
331 const h = hash2(x, y);
332 if ((h & 31) === 0)
333 { return BRICK.cementHi; }
334 if ((h & 31) === 1)
335 { return BRICK.cementLo; }
336 return BRICK.cement;
337 }
338
339 const courseH = 4;
340 const brickW = 6;
341 let onMortar = false;
342
343 if (role === "W" || role === "E")
344 {
345 const phase = y % courseH;
346 const outer = role === "W"
347 ? !isSameFace(faceRgba, x - 1, y, role, shapePrefix)
348 : !isSameFace(faceRgba, x + 1, y, role, shapePrefix);
349 // Diagonal: ·O then O· on west (outer 1px down); mirrored on east.
350 if (phase === 0)
351 { onMortar = !outer; }
352 else if (phase === 1)
353 { onMortar = outer; }
354 }
355 else if (role === "N")
356 {
357 onMortar = (x % brickW) === 0;
358 }
359 else
360 {
361 const row = Math.floor(y / courseH);
362 const brickX = x + (row & 1) * Math.floor(brickW / 2);
363 onMortar = (y % courseH) === 0 || (brickX % brickW) === 0;
364 }
365
366 if (onMortar)
367 { return BRICK.mortar; }
368
369 const h = hash2(x + role.charCodeAt(0) * 17, y);
370 if ((h & 15) === 0)
371 { return BRICK.hi; }
372 if ((h & 15) === 1)
373 { return BRICK.lo; }
374 return BRICK[role] ?? BRICK.T;
375}
376
377function isSameFace (faceRgba, x, y, role, shapePrefix)
378{
379 if (x < 0 || y < 0 || x >= SIZE || y >= SIZE || !faceRgba)
380 { return false; }
381 const i = (y * SIZE + x) * 4;
382 if (faceRgba[i + 3] === 0)
383 { return false; }
384 return roleOf(shapePrefix, faceRgba[i]) === role;
385}
386
387function woodMagenta (role)
388{
389 // Flat fallback (role only) — prefer woodShade for textured planks.
390 const L = {
391 O: 55,
392 S: 95,
393 E: 113,
394 W: 143,
395 T: 177,
396 N: 205
397 }[role] ?? 140;
398 const gHi = role === "N" || role === "T" ? Math.min(L - 20, 50) : 0;
399 return rgba(L, gHi, L);
400}
401
402/** Magenta (R=B, G<R) with face-aware plank grain, matching authored thick 1×1. */
403function mag (L, g = 0)
404{
405 const lit = Math.max(1, Math.min(255, L | 0));
406 const gv = Math.max(0, Math.min(lit - 1, g | 0));
407 return rgba(lit, gv, lit);
408}
409
410/**
411 * Wood planks by face (from thick-wood-wall/0.png reference):
412 * - S: vertical boards (~4px), alternating grain by board+row
413 * - W/E: horizontal plank bands; outer/inner columns swap each band (diagonal step)
414 * - T: N–S boards with brighter center grain + slight G highlight
415 * - N: bright rim, two-tone split
416 */
417function woodShade (x, y, role, shapePrefix, faceRgba)
418{
419 if (role === "O")
420 { return mag(55); }
421
422 if (role === "S")
423 {
424 const board = Math.floor(x / 4);
425 const light = ((board + y) & 1) !== 0;
426 return mag(light ? 102 : 95);
427 }
428
429 if (role === "W" || role === "E")
430 {
431 const lo = role === "W" ? 143 : 113;
432 const hi = role === "W" ? 155 : 120;
433 // Plank bands ~5px tall, aligned like authored alone (y2–6, y7–11, …).
434 const band = Math.floor(Math.max(0, y - 2) / 5);
435 const outer = role === "W"
436 ? !isSameFace(faceRgba, x - 1, y, role, shapePrefix)
437 : !isSameFace(faceRgba, x + 1, y, role, shapePrefix);
438 const swap = (band & 1) !== 0;
439 let useHi;
440 if (outer)
441 { useHi = swap; }
442 else
443 { useHi = !swap; }
444 return mag(useHi ? hi : lo);
445 }
446
447 if (role === "T" || (shapePrefix.startsWith("thin") && role === "N"))
448 {
449 const rowTone = (y & 1) !== 0;
450 const leftEdge = !isSameFace(faceRgba, x - 1, y, role, shapePrefix);
451 const rightEdge = !isSameFace(faceRgba, x + 1, y, role, shapePrefix);
452 const edge = leftEdge || rightEdge;
453 let L;
454 if (edge)
455 { L = rowTone ? 161 : 159; }
456 else
457 { L = rowTone ? 177 : 168; }
458 const g = rowTone ? 20 : 0;
459 return mag(L, g);
460 }
461
462 if (role === "N")
463 {
464 // Thick north bevel: split highlight
465 const L = x < 8 ? 200 : 210;
466 return mag(L, x < 8 ? 47 : 50);
467 }
468
469 return woodMagenta(role);
470}
471
472/**
473 * Cliff magenta tops: thick = plateau only (N is a dirt north face).
474 * Thin has no separate T — ridge top is role N.
475 */
476function isCliffTopRole (role, shapePrefix)
477{
478 if (shapePrefix.startsWith("thin"))
479 { return role === "N"; }
480 return role === "T";
481}
482
483function cliffShade (x, y, role, shapePrefix)
484{
485 if (isCliffTopRole(role, shapePrefix))
486 {
487 // Full magenta top — replaced in-game by ground sample shader.
488 return rgba(255, 0, 255);
489 }
490 if (role === "O")
491 {
492 const d = dirtAt(x, y);
493 return mulRgb(d, 0.35);
494 }
495 const d = dirtAt(x, y);
496 return mulRgb(d, faceLit(role));
497}
498
499function paintPixel (variant, prefix, g, x, y, faceRgba = null)
500{
501 const role = roleOf(prefix, g);
502 if (!role)
503 {
504 // Unknown grey: luminance fallback toward mid face.
505 const lit = g / 128;
506 if (variant === "wood")
507 { return rgba(Math.round(140 * lit), 0, Math.round(140 * lit)); }
508 if (variant === "cliff")
509 { return mulRgb(dirtAt(x, y), lit); }
510 if (variant === "brick")
511 { return mulRgb(BRICK.cement, lit); }
512 return mulRgb(COBBLE.T, lit);
513 }
514 if (variant === "cobble")
515 { return cobbleLike(COBBLE, x, y, role, 7); }
516 if (variant === "smooth")
517 { return cobbleLike(COBBLE, x, y, role, 31); }
518 if (variant === "brick")
519 { return brickShade(x, y, role, prefix, faceRgba); }
520 if (variant === "wood")
521 { return woodShade(x, y, role, prefix, faceRgba); }
522 if (variant === "cliff")
523 { return cliffShade(x, y, role, prefix); }
524 throw new Error(`Unknown variant ${variant}`);
525}
526
527function textureMask (rgbaIn, variant, shapePrefix)
528{
529 const out = new Uint8Array(SIZE * SIZE * 4);
530 for (let y = 0; y < SIZE; y++)
531 {
532 for (let x = 0; x < SIZE; x++)
533 {
534 const i = (y * SIZE + x) * 4;
535 if (rgbaIn[i + 3] === 0)
536 { continue; }
537 const color = paintPixel(variant, shapePrefix, rgbaIn[i], x, y, rgbaIn);
538 out[i] = color[0];
539 out[i + 1] = color[1];
540 out[i + 2] = color[2];
541 out[i + 3] = 255;
542 }
543 }
544 return out;
545}
546
547const VARIANT_OUT = {
548 cobble: {
549 thick: { dir: "thick-stone-wall", named: true, prefix: "thick-stone-wall" },
550 thin: { dir: "thin-stone-wall", named: true, prefix: "thin-stone-wall" }
551 },
552 smooth: {
553 thick: { dir: "thick-smooth-stone-wall", named: true, prefix: "thick-smooth-stone-wall" },
554 thin: { dir: "thin-smooth-stone-wall", named: true, prefix: "thin-smooth-stone-wall" }
555 },
556 brick: {
557 thick: { dir: "thick-brick-wall", named: true, prefix: "thick-brick-wall" },
558 thin: { dir: "thin-brick-wall", named: true, prefix: "thin-brick-wall" }
559 },
560 wood: {
561 thick: { dir: "thick-wood-wall", named: false, prefix: "thick-stone-wall" },
562 thin: { dir: "thin-wood-wall", named: false, prefix: "thin-stone-wall" }
563 },
564 cliff: {
565 thick: { dir: "thick-cliff", named: true, prefix: "thick-cliff" },
566 thin: { dir: "thin-cliff", named: true, prefix: "thin-cliff" }
567 }
568};
569
570function shapeFiles (shapeKey)
571{
572 return readdirSync(EXAMPLES)
573 .filter((name) => name.startsWith(shapeKey) && name.endsWith(".png") && !name.includes("ref-"))
574 .sort();
575}
576
577function namedOutName (outPrefix, shapeName, shapeKey)
578{
579 // thick-stone-wall-esw.png → thick-smooth-stone-wall-esw.png
580 const suffix = shapeName.slice(shapeKey.length); // "" or "-esw"
581 return `${outPrefix}${suffix}`;
582}
583
584const FACE_ID_GREYS = new Set([
585 0x40, 0x54, 0x6c, 0x73, 0x80, 0x95, 0xaf, 0xb6
586]);
587
588function isFaceIdMask (rgba)
589{
590 for (let i = 0; i < rgba.length; i += 4)
591 {
592 if (rgba[i + 3] === 0)
593 { continue; }
594 if (rgba[i] !== rgba[i + 1] || rgba[i] !== rgba[i + 2])
595 { return false; }
596 if (!FACE_ID_GREYS.has(rgba[i]))
597 { return false; }
598 }
599 return true;
600}
601
602/** Copy face-id greyscale from live thick/thin-stone-wall → _examples (never textured art). */
603function syncShapesFromLive ()
604{
605 mkdirSync(EXAMPLES, { recursive: true });
606 let copied = 0;
607 for (const kind of ["thick", "thin"])
608 {
609 const shapeKey = `${kind}-stone-wall`;
610 const liveDir = join(ROOT, shapeKey);
611 if (!existsSync(liveDir))
612 { throw new Error(`Missing live folder ${liveDir}`); }
613 const files = readdirSync(liveDir)
614 .filter((name) => name.startsWith(shapeKey) && name.endsWith(".png"))
615 .sort();
616 if (files.length !== 16)
617 { throw new Error(`Expected 16 live ${shapeKey} sprites, found ${files.length}`); }
618 for (const name of files)
619 {
620 const rgba = decodePngRgba(join(liveDir, name));
621 if (!isFaceIdMask(rgba))
622 {
623 throw new Error(
624 `${shapeKey}/${name} is not a face-id greyscale mask (already textured?). ` +
625 `Paint face-id greys in the live folder, then re-run --sync-shapes.`
626 );
627 }
628 cpSync(join(liveDir, name), join(EXAMPLES, name));
629 copied++;
630 }
631 console.log(` synced ${kind} → ${EXAMPLES}`);
632 }
633 console.log(`Synced ${copied} face-id masks into examples.`);
634}
635
636function bakeVariant (variant, { force = false } = {})
637{
638 const cfg = VARIANT_OUT[variant];
639 if (!cfg)
640 { throw new Error(`Unknown variant: ${variant}`); }
641 if (variant === "cobble" && !force)
642 {
643 throw new Error(
644 "Refusing to overwrite thick/thin-stone-wall without --force " +
645 "(hand-tweaked gameplay sprites). Sync shapes with --sync-shapes first if needed."
646 );
647 }
648 let wrote = 0;
649 for (const kind of ["thick", "thin"])
650 {
651 const shapeKey = `${kind}-stone-wall`;
652 const out = cfg[kind];
653 const outDir = join(ROOT, out.dir);
654 mkdirSync(outDir, { recursive: true });
655 const files = shapeFiles(shapeKey);
656 if (files.length !== 16)
657 { throw new Error(`Expected 16 ${shapeKey} masks, found ${files.length}`); }
658
659 if (out.named)
660 {
661 for (const name of files)
662 {
663 const shaped = decodePngRgba(join(EXAMPLES, name));
664 const textured = textureMask(shaped, variant, shapeKey);
665 const outName = namedOutName(out.prefix, name, shapeKey);
666 writeFileSync(join(outDir, outName), encodePng(textured));
667 wrote++;
668 }
669 }
670 else
671 {
672 for (let mask = 0; mask < 16; mask++)
673 {
674 const suffix = cardinalConnectionSuffix(mask);
675 const shapeName = suffix ? `${shapeKey}-${suffix}.png` : `${shapeKey}.png`;
676 const shaped = decodePngRgba(join(EXAMPLES, shapeName));
677 const textured = textureMask(shaped, variant, shapeKey);
678 writeFileSync(join(outDir, `${mask}.png`), encodePng(textured));
679 wrote++;
680 }
681 }
682 console.log(` ${variant} ${kind} → ${outDir} (${out.named ? "named" : "0–15"})`);
683 }
684 return wrote;
685}
686
687if (process.argv.includes("--sync-shapes"))
688{
689 syncShapesFromLive();
690 process.exit(0);
691}
692
693const arg = process.argv.find((a) => a.startsWith("--variant="));
694const variant = arg ? arg.slice("--variant=".length) : null;
695if (!variant)
696{
697 console.error("Usage: --sync-shapes | --variant=cobble|smooth|brick|wood|cliff|all [--force]");
698 process.exit(1);
699}
700const force = process.argv.includes("--force");
701const list = variant === "all"
702 ? ["cobble", "smooth", "brick", "wood", "cliff"]
703 : [variant];
704
705if (!existsSync(EXAMPLES))
706{ throw new Error(`Missing ${EXAMPLES}`); }
707
708let total = 0;
709for (const v of list)
710{
711 console.log(`Baking ${v}…`);
712 total += bakeVariant(v, { force });
713}
714console.log(`Done (${total} sprites).`);
client/src/editor/main.js +22 −0
@@ -686,6 +686,26 @@ function refreshNeighborConnect (localX, localY, typeId)
686 686 }
687 687 }
688 688
689 /** Fix legacy/wrong connect states (e.g. old diagonal masks saved as nesw) from live neighbors. */
690 function recomputeAllNeighborConnectInDraft ()
691 {
692 if (!draft)
693 { return; }
694 for (let localY = 0; localY < CHUNK_SIZE; localY++)
695 {
696 for (let localX = 0; localX < CHUNK_SIZE; localX++)
697 {
698 const block = draft.blocks[localY * CHUNK_SIZE + localX];
699 if (!block)
700 { continue; }
701 const def = BLOCK_DEFINITIONS[block.typeId];
702 if (!definitionUsesNeighborConnect(def))
703 { continue; }
704 refreshNeighborConnect(localX, localY, block.typeId);
705 }
706 }
707 }
708
689 709 function updateRevisionUI ()
690 710 {
691 711 const applyBtn = $("apply");
@@ -748,6 +768,8 @@ function showSelectedChunk (payload)
748 768 view.applySnapshot(snapshotFromPayload(payload));
749 769 syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners);
750 770 captureDraftBaseline();
771 recomputeAllNeighborConnectInDraft();
772 syncSaveButton();
751 773 if (navigateAfterSave && pendingNavigate)
752 774 {
753 775 const next = pendingNavigate;
@@ -686,6 +686,26 @@ function refreshNeighborConnect (localX, localY, typeId)
686 }
686 }
687}
687}
688
688
689/** Fix legacy/wrong connect states (e.g. old diagonal masks saved as nesw) from live neighbors. */
690function recomputeAllNeighborConnectInDraft ()
691{
692 if (!draft)
693 { return; }
694 for (let localY = 0; localY < CHUNK_SIZE; localY++)
695 {
696 for (let localX = 0; localX < CHUNK_SIZE; localX++)
697 {
698 const block = draft.blocks[localY * CHUNK_SIZE + localX];
699 if (!block)
700 { continue; }
701 const def = BLOCK_DEFINITIONS[block.typeId];
702 if (!definitionUsesNeighborConnect(def))
703 { continue; }
704 refreshNeighborConnect(localX, localY, block.typeId);
705 }
706 }
707}
708
689function updateRevisionUI ()
709function updateRevisionUI ()
690{
710{
691 const applyBtn = $("apply");
711 const applyBtn = $("apply");
@@ -748,6 +768,8 @@ function showSelectedChunk (payload)
748 view.applySnapshot(snapshotFromPayload(payload));
768 view.applySnapshot(snapshotFromPayload(payload));
749 syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners);
769 syncSpawnersOverlay(payload.chunkX, payload.chunkY, draft.spawners);
750 captureDraftBaseline();
770 captureDraftBaseline();
771 recomputeAllNeighborConnectInDraft();
772 syncSaveButton();
751 if (navigateAfterSave && pendingNavigate)
773 if (navigateAfterSave && pendingNavigate)
752 {
774 {
753 const next = pendingNavigate;
775 const next = pendingNavigate;
client/src/render/worldView.js +75 −10
@@ -5,13 +5,14 @@ import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";
5 5 import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
6 6 import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
7 7 import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
8 import {
9 resolveItemTint,
10 resolveEquipTint,
11 resolveItemDualTint,
12 resolveEquipDualTint,
13 normalizeRgb
14 } from "/shared/render/tint.js";
8 import
9 {
10 resolveItemTint,
11 resolveEquipTint,
12 resolveItemDualTint,
13 resolveEquipDualTint,
14 normalizeRgb
15 } from "/shared/render/tint.js";
15 16 import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
16 17 import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
17 18 import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
@@ -352,8 +353,49 @@ const ATLAS_LIGHTING_FRAG = [
352 353 "}"
353 354 ].join("\n");
354 355
356 /**
357 * Block-row atlas: magenta → sample the ground atlas (u_bump) at the same
358 * tile-local UV (1:1 scale). The ground atlas already includes soft-terrain
359 * blending when that preference is on, so cliff tops match the floor beneath.
360 * Darkness matches ATLAS_LIGHTING_FRAG (lightmap in u_secondary).
361 */
362 const ATLAS_BLOCK_GROUND_TOP_FRAG = [
363 "precision mediump float;",
364 "varying vec2 v_texCoord;",
365 "uniform sampler2D u_texture;",
366 "uniform sampler2D u_secondary;",
367 "uniform sampler2D u_bump;",
368 "uniform float u_alpha;",
369 "uniform float u_ambientDark;",
370 "uniform float u_lightRow;",
371 "void main() {",
372 " vec4 color = texture2D(u_texture, v_texCoord);",
373 " if (color.a <= 0.0) { discard; }",
374 " vec3 rgb = color.rgb;",
375 " // Magenta family (R≈B, G<R): replace with blended ground under this pixel.",
376 " float rbDiff = abs(rgb.r - rgb.b);",
377 " if (rbDiff < 0.02 && rgb.g < rgb.r - 0.02) {",
378 " float tileX = floor(v_texCoord.x * 16.0);",
379 " float tileY = max(u_lightRow, 0.0);",
380 " float localX = fract(v_texCoord.x * 16.0);",
381 " float localY = v_texCoord.y;",
382 " vec2 groundUV = vec2((tileX + localX) / 16.0, (tileY + localY) / 16.0);",
383 " rgb = texture2D(u_bump, groundUV).rgb;",
384 " }",
385 " vec2 lightUV = v_texCoord;",
386 " if (u_lightRow >= 0.0) {",
387 " lightUV.y = (u_lightRow + v_texCoord.y) / 16.0;",
388 " }",
389 " float lit = texture2D(u_secondary, lightUV).r;",
390 " float darkness = u_ambientDark * (1.0 - lit);",
391 " rgb = mix(rgb, vec3(0.0), darkness);",
392 " gl_FragColor = vec4(rgb, color.a * u_alpha);",
393 "}"
394 ].join("\n");
395
355 396 let spriteLightingShader = null;
356 397 let atlasLightingShader = null;
398 let atlasBlockGroundTopShader = null;
357 399 let waterGroundShader = null;
358 400 let tintLitSpriteShader = null;
359 401 let dualTintLitSpriteShader = null;
@@ -374,6 +416,13 @@ function getAtlasLightingShader ()
374 416 return atlasLightingShader;
375 417 }
376 418
419 function getAtlasBlockGroundTopShader ()
420 {
421 if (!atlasBlockGroundTopShader)
422 { atlasBlockGroundTopShader = Shader.fragment(ATLAS_BLOCK_GROUND_TOP_FRAG); }
423 return atlasBlockGroundTopShader;
424 }
425
377 426 function getWaterGroundShader ()
378 427 {
379 428 if (!waterGroundShader)
@@ -3297,7 +3346,7 @@ export class WorldView
3297 3346 for (let row = 0; row < CHUNK_SIZE; row++)
3298 3347 {
3299 3348 const object = new GameObject(0, 0, baked.blockImages[row], SORT_BLOCK);
3300 this.#applyAtlasLighting(object, baked.lightmapImage, row);
3349 this.#applyAtlasLighting(object, baked.lightmapImage, row, baked.groundImage);
3301 3350 this.scene.addObject(object);
3302 3351 baked.blockObjects.push(object);
3303 3352 }
@@ -3314,6 +3363,7 @@ export class WorldView
3314 3363 baked.groundCanvas = atlases.ground;
3315 3364 baked.groundImage = groundImage;
3316 3365 baked.groundObject.renderer.sprite = groundImage;
3366 this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1);
3317 3367 }
3318 3368 for (let row = 0; row < CHUNK_SIZE; row++)
3319 3369 {
@@ -3323,6 +3373,12 @@ export class WorldView
3323 3373 baked.blockImages[row] = blockImages[row];
3324 3374 baked.blockObjects[row].renderer.sprite = blockImages[row];
3325 3375 }
3376 this.#applyAtlasLighting(
3377 baked.blockObjects[row],
3378 baked.lightmapImage,
3379 row,
3380 baked.groundImage
3381 );
3326 3382 }
3327 3383 if (baked.bloomCanvas !== atlases.bloom)
3328 3384 {
@@ -3419,12 +3475,21 @@ export class WorldView
3419 3475 { this.#scheduleTextureWarm(); }
3420 3476 }
3421 3477
3422 #applyAtlasLighting (object, lightmapImage, lightRow)
3478 #applyAtlasLighting (object, lightmapImage, lightRow, groundImage = null)
3423 3479 {
3424 3480 if (!object?.renderer)
3425 3481 { return; }
3426 3482 object._lit = true;
3427 object.renderer.shader = getAtlasLightingShader();
3483 if (groundImage)
3484 {
3485 object.renderer.shader = getAtlasBlockGroundTopShader();
3486 object.renderer.bumpMap = groundImage;
3487 }
3488 else
3489 {
3490 object.renderer.shader = getAtlasLightingShader();
3491 object.renderer.bumpMap = null;
3492 }
3428 3493 object.renderer.secondaryMap = lightmapImage;
3429 3494 object.renderer.shaderUniforms = {
3430 3495 u_ambientDark: 0,
@@ -5,13 +5,14 @@ import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";
5import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
5import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
6import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
6import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
7import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
7import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
8import {
8import
9 resolveItemTint,
9 {
10 resolveEquipTint,
10 resolveItemTint,
11 resolveItemDualTint,
11 resolveEquipTint,
12 resolveEquipDualTint,
12 resolveItemDualTint,
13 normalizeRgb
13 resolveEquipDualTint,
14} from "/shared/render/tint.js";
14 normalizeRgb
15 } from "/shared/render/tint.js";
15import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
16import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
16import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
17import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
17import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
18import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
@@ -352,8 +353,49 @@ const ATLAS_LIGHTING_FRAG = [
352 "}"
353 "}"
353].join("\n");
354].join("\n");
354
355
356/**
357 * Block-row atlas: magenta → sample the ground atlas (u_bump) at the same
358 * tile-local UV (1:1 scale). The ground atlas already includes soft-terrain
359 * blending when that preference is on, so cliff tops match the floor beneath.
360 * Darkness matches ATLAS_LIGHTING_FRAG (lightmap in u_secondary).
361 */
362const ATLAS_BLOCK_GROUND_TOP_FRAG = [
363 "precision mediump float;",
364 "varying vec2 v_texCoord;",
365 "uniform sampler2D u_texture;",
366 "uniform sampler2D u_secondary;",
367 "uniform sampler2D u_bump;",
368 "uniform float u_alpha;",
369 "uniform float u_ambientDark;",
370 "uniform float u_lightRow;",
371 "void main() {",
372 " vec4 color = texture2D(u_texture, v_texCoord);",
373 " if (color.a <= 0.0) { discard; }",
374 " vec3 rgb = color.rgb;",
375 " // Magenta family (R≈B, G<R): replace with blended ground under this pixel.",
376 " float rbDiff = abs(rgb.r - rgb.b);",
377 " if (rbDiff < 0.02 && rgb.g < rgb.r - 0.02) {",
378 " float tileX = floor(v_texCoord.x * 16.0);",
379 " float tileY = max(u_lightRow, 0.0);",
380 " float localX = fract(v_texCoord.x * 16.0);",
381 " float localY = v_texCoord.y;",
382 " vec2 groundUV = vec2((tileX + localX) / 16.0, (tileY + localY) / 16.0);",
383 " rgb = texture2D(u_bump, groundUV).rgb;",
384 " }",
385 " vec2 lightUV = v_texCoord;",
386 " if (u_lightRow >= 0.0) {",
387 " lightUV.y = (u_lightRow + v_texCoord.y) / 16.0;",
388 " }",
389 " float lit = texture2D(u_secondary, lightUV).r;",
390 " float darkness = u_ambientDark * (1.0 - lit);",
391 " rgb = mix(rgb, vec3(0.0), darkness);",
392 " gl_FragColor = vec4(rgb, color.a * u_alpha);",
393 "}"
394].join("\n");
395
355let spriteLightingShader = null;
396let spriteLightingShader = null;
356let atlasLightingShader = null;
397let atlasLightingShader = null;
398let atlasBlockGroundTopShader = null;
357let waterGroundShader = null;
399let waterGroundShader = null;
358let tintLitSpriteShader = null;
400let tintLitSpriteShader = null;
359let dualTintLitSpriteShader = null;
401let dualTintLitSpriteShader = null;
@@ -374,6 +416,13 @@ function getAtlasLightingShader ()
374 return atlasLightingShader;
416 return atlasLightingShader;
375}
417}
376
418
419function getAtlasBlockGroundTopShader ()
420{
421 if (!atlasBlockGroundTopShader)
422 { atlasBlockGroundTopShader = Shader.fragment(ATLAS_BLOCK_GROUND_TOP_FRAG); }
423 return atlasBlockGroundTopShader;
424}
425
377function getWaterGroundShader ()
426function getWaterGroundShader ()
378{
427{
379 if (!waterGroundShader)
428 if (!waterGroundShader)
@@ -3297,7 +3346,7 @@ export class WorldView
3297 for (let row = 0; row < CHUNK_SIZE; row++)
3346 for (let row = 0; row < CHUNK_SIZE; row++)
3298 {
3347 {
3299 const object = new GameObject(0, 0, baked.blockImages[row], SORT_BLOCK);
3348 const object = new GameObject(0, 0, baked.blockImages[row], SORT_BLOCK);
3300 this.#applyAtlasLighting(object, baked.lightmapImage, row);
3349 this.#applyAtlasLighting(object, baked.lightmapImage, row, baked.groundImage);
3301 this.scene.addObject(object);
3350 this.scene.addObject(object);
3302 baked.blockObjects.push(object);
3351 baked.blockObjects.push(object);
3303 }
3352 }
@@ -3314,6 +3363,7 @@ export class WorldView
3314 baked.groundCanvas = atlases.ground;
3363 baked.groundCanvas = atlases.ground;
3315 baked.groundImage = groundImage;
3364 baked.groundImage = groundImage;
3316 baked.groundObject.renderer.sprite = groundImage;
3365 baked.groundObject.renderer.sprite = groundImage;
3366 this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1);
3317 }
3367 }
3318 for (let row = 0; row < CHUNK_SIZE; row++)
3368 for (let row = 0; row < CHUNK_SIZE; row++)
3319 {
3369 {
@@ -3323,6 +3373,12 @@ export class WorldView
3323 baked.blockImages[row] = blockImages[row];
3373 baked.blockImages[row] = blockImages[row];
3324 baked.blockObjects[row].renderer.sprite = blockImages[row];
3374 baked.blockObjects[row].renderer.sprite = blockImages[row];
3325 }
3375 }
3376 this.#applyAtlasLighting(
3377 baked.blockObjects[row],
3378 baked.lightmapImage,
3379 row,
3380 baked.groundImage
3381 );
3326 }
3382 }
3327 if (baked.bloomCanvas !== atlases.bloom)
3383 if (baked.bloomCanvas !== atlases.bloom)
3328 {
3384 {
@@ -3419,12 +3475,21 @@ export class WorldView
3419 { this.#scheduleTextureWarm(); }
3475 { this.#scheduleTextureWarm(); }
3420 }
3476 }
3421
3477
3422 #applyAtlasLighting (object, lightmapImage, lightRow)
3478 #applyAtlasLighting (object, lightmapImage, lightRow, groundImage = null)
3423 {
3479 {
3424 if (!object?.renderer)
3480 if (!object?.renderer)
3425 { return; }
3481 { return; }
3426 object._lit = true;
3482 object._lit = true;
3427 object.renderer.shader = getAtlasLightingShader();
3483 if (groundImage)
3484 {
3485 object.renderer.shader = getAtlasBlockGroundTopShader();
3486 object.renderer.bumpMap = groundImage;
3487 }
3488 else
3489 {
3490 object.renderer.shader = getAtlasLightingShader();
3491 object.renderer.bumpMap = null;
3492 }
3428 object.renderer.secondaryMap = lightmapImage;
3493 object.renderer.secondaryMap = lightmapImage;
3429 object.renderer.shaderUniforms = {
3494 object.renderer.shaderUniforms = {
3430 u_ambientDark: 0,
3495 u_ambientDark: 0,
docs/STONE_WALL_SHAPES.md added +342 −0
@@ -0,0 +1,342 @@
1 # Stone wall shape system
2
3 How **thick** stone-wall sprites encode a 3D block as flat greyscale face-IDs, how **connections** open faces into neighbours, and how cobble texture is baked onto those masks for gameplay.
4
5 Thin walls use the same face vocabulary on a narrower frustum; this document centres on **thick**, which is the clearest reference.
6
7 ---
8
9 ## Reference files
10
11 | Path | What it is |
12 |------|------------|
13 | `client/assets/blocks/thick-stone-wall/thick-stone-wall.png` | **Gameplay** alone 1×1 (textured) |
14 | `client/assets/blocks/_examples/stone-wall/thick-stone-wall.png` | **Shape mask** alone 1×1 (face-id greys) |
15 | `client/assets/blocks/thick-stone-wall/thick-stone-wall-*.png` | 15 connected gameplay variants |
16 | `client/assets/blocks/_examples/stone-wall/ref-thick-alone-256.png` | Nearest-neighbour ×16 alone (shape) |
17 | `…/ref-thick-face-id-16.png` / `…-256.png` | False-colour face roles |
18 | `…/ref-thick-height-16.png` / `…-256.png` | Relative heightmap from roles |
19 | `…/ref-thick-face-legend.png` | Colour key for face-id |
20 | `…/ref-thick-all-variants.png` | Labeled 4×4 sheet of all 16 thick states |
21 | `client/scripts/export-thick-wall-refs.py` | Regenerates face-id / height / alone refs |
22
23 Gameplay keys: `thick-stone-wall`, `thin-stone-wall`. Suffixes from cardinal neighbours only (`n`/`e`/`s`/`w` → e.g. `we`, `ns`, `esw`, `wne`, `nesw`). See `shared/world/neighborConnect.js`.
24
25 ---
26
27 ## 1. Camera and axes
28
29 - Tile size: **16×16** px.
30 - **+X = east** (right), **+Y = south** (down on screen).
31 - View: **top-down with a front bias** — you see the flat **top**, thin **west/east** vertical sides, and a tall **south** front face.
32 - Greys are **face identity**, not painted lighting noise. Texture work must stay inside these regions.
33
34 ```text
35 N (−Y)
36 ↑
37 W ← tile → E
38 ↓
39 S (+Y, toward camera)
40 ```
41
42 ---
43
44 ## 2. Greyscale vocabulary (face IDs)
45
46 Exact values from `thick-stone-wall.png`. Six tones only:
47
48 | Grey | Hex | Role | Reads as |
49 |------|-----|------|----------|
50 | 64 | `0x40` | **Outline / crease** | Outer rim + lip between faces |
51 | 175 | `0xAF` | **North bevel** | Top rim facing north (−Y) — brightest body |
52 | 149 | `0x95` | **West face** | Vertical face facing west (−X) |
53 | 128 | `0x80` | **Top plateau** | Flat upper surface of the volume |
54 | 108 | `0x6C` | **East face** | Vertical face facing east (+X) — darker than west |
55 | 84 | `0x54` | **South face** | Vertical face facing south (+Y) — darkest body |
56
57 Mnemonic on a free 1×1:
58
59 ```text
60 N = 0xAF (bright)
61 W = 0x95 E = 0x6C
62 top = 0x80
63 S = 0x54 (dark)
64 outline = 0x40 everywhere edges meet
65 ```
66
67 **Do not invent intermediate greys** when cloning the structure. Remap these six roles to material colours / normals later.
68
69 ---
70
71 ## 3. Alone anatomy (pixel-exact)
72
73 Role map of `thick-stone-wall.png` (`#` outline, `N`/`W`/`E`/`T`/`S` as above):
74
75 ```text
76 y\x 0 1 2 3 4 5 6 7 8 9 A B C D E F
77 0 # # # # # # # # # # # # # # # #
78 1 # # # N N N N N N N N N N # # #
79 2 # W W # # # # # # # # # # E E #
80 3 # W W # T T T T T T T T # E E #
81 4 # W W # T T T T T T T T # E E #
82 5 # W W # T T T T T T T T # E E #
83 6 # W W # T T T T T T T T # E E #
84 7 # W W # T T T T T T T T # E E #
85 8 # W W # T T T T T T T T # E E #
86 9 # W W # # # # # # # # # # E E #
87 10 # W W # S S S S S S S S # E E #
88 11 # W # S S S S S S S S S S # E #
89 12 # W # S S S S S S S S S S # E #
90 13 # # S S S S S S S S S S S S # #
91 14 # # S S S S S S S S S S S S # #
92 15 # # # # # # # # # # # # # # # #
93 ```
94
95 ### Region boxes (inclusive)
96
97 | Role | Pixels | Notes |
98 |------|--------|-------|
99 | Outline | Full perimeter + every lip between faces | Never fill with body grey |
100 | North bevel | `y=1`, `x=3..12` | Only when **north is free** |
101 | West face | `x=1..2`, `y=2..12` (tapers: one px at `y=11..12`) | Only when **west is free** |
102 | East face | `x=13..14`, `y=2..12` (tapers) | Only when **east is free** |
103 | Top plateau | `x=4..11`, `y=3..8` | Surrounded by `0x40` lips |
104 | South face | `y=10..14`, widens downward (`x=4..11` → `x=2..13`) | Only when **south is free** |
105
106 ### Volume model
107
108 Read the tile as a **truncated box / frustum**:
109
110 1. **Roof** — plateau `0x80` with north lip `0xAF`.
111 2. **Side walls** — west `0x95`, east `0x6C` (asymmetry = light from NW).
112 3. **Front wall** — south `0x54`, taller in screen space.
113 4. **Creases** — `0x40` at every face junction and the tile border.
114
115 Corners are mitered: NW = N↔W, NE = N↔E, SW = S↔W, SE = S↔E, resolved by outline pixels.
116
117 ---
118
119 ## 4. Connection rule (core)
120
121 A suffix letter means: **this tile continues into a neighbour on that side**.
122
123 For each connected cardinal:
124
125 1. **Remove** that side’s free-face band (`N`/`E`/`S`/`W` grey).
126 2. **Extrude** interior bands (plateau, remaining free faces, and their outline lips) **to the tile edge** on that side so the neighbour can match.
127 3. **Keep** free-face bands only on sides that are **not** connected.
128
129 | Open | Remove | Extrude to edge |
130 |------|--------|-----------------|
131 | **N** | North bevel `0xAF` (+ north rim treatment) | W / E / T run to `y=0` |
132 | **E** | East face `0x6C` | N (if free) / T / S run to `x=15` |
133 | **S** | South face `0x54` | W / E / T run to `y=15` |
134 | **W** | West face `0x95` | N (if free) / T / S run to `x=0` |
135
136 ### Opposite pairs
137
138 **`ns`** — vertical run: full-height W + T + E columns; no N bevel, no S front.
139
140 ```text
141 ##WW##TTTTTTTT##EE## (repeats y=0..15)
142 ```
143
144 **`we`** — horizontal run: full-width N rim (if free), T band, S band; no W/E sides.
145
146 ```text
147 ################ y0
148 NNNNNNNNNNNNNNNN y1
149 ################ y2
150 TTTTTTTTTTTTTTTT y3..8
151 ################ y9
152 SSSSSSSSSSSSSSSS y10..14
153 ################ y15
154 ```
155
156 ### Seam contract
157
158 Across a shared edge, both tiles paint the **same continuing role** to `x=0|15` or `y=0|15`. Example: A=`…e` and B=`…w` both show plateau `0x80` (and matching N/S bands) meeting mid-edge — **no** side-face grey on that shared edge.
159
160 ---
161
162 ## 5. Corners, T-junctions, and concave pockets
163
164 Corners (`ne`, `es`, `sw`, `wn`) and T’s (`esw`, `wne`, `swn`, `nes`) are **unions** of the open-face rules.
165
166 Where two **free** faces would have met at a concave inner corner after opening the other sides, the art keeps a small **pocket**: outline + a stub of the free face greys. That pocket is what makes an L or T read as a turn rather than a flat extrusion.
167
168 Examples (schematic):
169
170 **`es`** (open E+S → free N+W): south-east corner keeps an E/S pocket while T extrudes east and south elsewhere.
171
172 **`esw`** (T, free N only): full-width N + T like `we`, but south edge shows **two** S/W and S/E pockets at the SW and SE corners (the stem of the T going south).
173
174 **`wne`** (T, free S only): full-width S band; north edge shows N pockets at NW/NE where the stem goes north.
175
176 **`nesw`** (all four open): no full free faces; T fills the centre and runs to all edges, with **four corner pockets** (N stubs at top, S/W/E stubs at bottom corners). Those pockets are intentional — they are the miters where four neighbour walls meet around this cell in a solid fill / 2×2 interior is different from a true cross; authored `nesw` still carries corner detail for visual continuity with T/L art.
177
178 ### 2×2 solid block
179
180 Four tiles use **corner** suffixes, not `nesw`:
181
182 | Cell | Suffix |
183 |------|--------|
184 | NW | `es` |
185 | NE | `sw` |
186 | SW | `ne` |
187 | SE | `wn` |
188
189 Each keeps the two **outer** free faces and opens the two **inner** sides into the cluster. (`nesw` is for a cell with neighbours on all four cardinals — e.g. interior of a thicker shape — not for the four cells of a minimal 2×2.)
190
191 ---
192
193 ## 6. Worked single-open examples
194
195 **`n`** — north open: row 0 becomes the old “interior” W/T/E pattern; south stack unchanged.
196
197 ```text
198 ##WW##TTTTTTTT##EE## y0..8
199 ##WW############EE## y9
200 ##WW##SSSSSSSS##EE## y10
201 … south taper …
202 ################ y15
203 ```
204
205 **`s`** — south open: plateau + sides continue through `y=15`; no `0x54`.
206
207 **`e`** — east open: N/T/S (and W) run to `x=15`; no `0x6C`.
208
209 **`w`** — west open: N/T/S run to `x=0`; free east column remains.
210
211 > **Note:** free east on `thick-stone-wall-w` uses `0x6C` (corrected). When flipping `e`↔`w` art, always reassign face greys — do not keep mirrored luminance.
212
213 ---
214
215 ## 7. Heightmap (for cloning / normals)
216
217 `ref-thick-height-*.png` maps roles → relative height (0–255):
218
219 | Role | Height | Order |
220 |------|--------|-------|
221 | Outline | 40 | Lowest (crease / contact) |
222 | South face | 80 | Front of prism |
223 | East face | 140 | Side |
224 | West face | 160 | Side (slightly higher = lit side) |
225 | Top plateau | 200 | Roof |
226 | North bevel | 220 | Upper lip |
227
228 Ordering to preserve when editing:
229 `outline ≤ south ≤ east ≤ west ≤ top ≤ north`.
230
231 Uses:
232
233 - Extrude a new material with the **same silhouettes**.
234 - Bake normals: up on plateau, −Y on north bevel, ±X on sides, +Y on south.
235 - Validate connection variants (no south-height pixels on the plateau).
236
237 This is a **role-derived** height field, not scanned depth. Absolute values may shift for a shader; keep the order.
238
239 ---
240
241 ## 8. Face-id map (tooling)
242
243 False colour in `ref-thick-face-id-*.png`:
244
245 | Colour | Role |
246 |--------|------|
247 | White | North bevel |
248 | Red | West face |
249 | Blue | East face |
250 | Green | South face |
251 | Amber | Top plateau |
252 | Near-black | Outline |
253
254 Suggested pipeline for a new wall set:
255
256 1. Author or copy **face-id** (or height + face-id) at 16×16.
257 2. Fill each role with albedo / material detail **inside** the mask.
258 3. Optional soft light multiply that still respects N lightest → S darkest.
259 4. Keep outline as mortar/edge or replace with a 1px edge pass.
260 5. Derive the 15 connection variants by applying §4–§5 (or paint from thick examples with recolour-by-role).
261
262 ---
263
264 ## 9. Checklist — new thick-style wall
265
266 **Alone**
267
268 - [ ] Full-tile thick footprint (or intentional inset for a thin family).
269 - [ ] Only the six role greys (or 1:1 mapped equivalents).
270 - [ ] Free N → `0xAF` rim; free W → `0x95`; free E → `0x6C`; free S → `0x54`; centre → `0x80`.
271 - [ ] Outline separates every face pair.
272
273 **Each suffix**
274
275 - [ ] Connected side has no free-face band of that direction.
276 - [ ] Interior bands meet the tile edge on connected sides.
277 - [ ] Free sides keep the correct face grey (`E` = `0x6C`, not a flipped `0x95`).
278 - [ ] Seam matches the opposite suffix on the neighbour (`e`↔`w`, `n`↔`s`).
279 - [ ] L/T/`nesw` keep concave corner pockets where needed.
280
281 **Texturing**
282
283 - [ ] No detail crossing role boundaries without an outline.
284 - [ ] Normals follow face directions in §7.
285 - [ ] After recolour, regenerate face-id/height refs and spot-check all 16 states.
286
287 ---
288
289 ## 10. Thin walls
290
291 `thin-stone-wall` uses the **same idea** on a **narrow frustum**, but a slightly different grey vocabulary:
292
293 | Grey | Hex | Thin role |
294 |------|-----|-----------|
295 | 64 | `0x40` | Outline |
296 | 182 | `0xB6` | West face |
297 | 149 | `0x95` | North rim / ridge top |
298 | 128 | `0x80` | East face (**not** top plateau — differs from thick) |
299 | 115 | `0x73` | South / front body |
300
301 Clone thin silhouettes; recolour via this table (or `texture-stone-wall-sprites.mjs`).
302
303 ---
304
305 ## 11. Baking cobble texture
306
307 Gameplay sprites in `thick-stone-wall/` and `thin-stone-wall/` are **textured**. Greyscale face-id masks stay in `_examples/stone-wall/`.
308
309 ```bash
310 node client/scripts/texture-stone-wall-sprites.mjs
311 ```
312
313 Reads example masks → writes cobble-shaded PNGs using the old cool-grey stone palette (TOP / FACE / EDGE / MORTAR speckles), keyed by face role. Re-run after editing shapes in `_examples`.
314
315 ---
316
317 ## 12. Code touchpoints
318
319 | Concern | Location |
320 |---------|----------|
321 | Cardinal suffix / mask (`& 15`) | `shared/world/neighborConnect.js` |
322 | Block defs | `shared/definitions/tiles.js` |
323 | Textured sprites (gameplay) | `client/assets/blocks/thick-stone-wall/`, `thin-stone-wall/` |
324 | Greyscale shape masks + refs | `client/assets/blocks/_examples/stone-wall/` |
325 | Shape generator from connecting examples | `client/scripts/generate-stone-wall-sprites.mjs` |
326 | Cobble texture bake | `client/scripts/texture-stone-wall-sprites.mjs` |
327 | Ref export | `client/scripts/export-thick-wall-refs.py` |
328
329 Editor recomputes neighbour suffixes on paint and on chunk load so a 2×2 stays on corner suffixes, not `nesw`.
330
331 ---
332
333 ## 13. Regenerate reference maps
334
335 Whenever the thick alone **shape** mask changes:
336
337 ```bash
338 python3 client/scripts/export-thick-wall-refs.py
339 node client/scripts/texture-stone-wall-sprites.mjs
340 ```
341
342 Then update the grey table in §2 / §10 if the vocabulary shifted.
@@ -0,0 +1,342 @@
1# Stone wall shape system
2
3How **thick** stone-wall sprites encode a 3D block as flat greyscale face-IDs, how **connections** open faces into neighbours, and how cobble texture is baked onto those masks for gameplay.
4
5Thin walls use the same face vocabulary on a narrower frustum; this document centres on **thick**, which is the clearest reference.
6
7---
8
9## Reference files
10
11| Path | What it is |
12|------|------------|
13| `client/assets/blocks/thick-stone-wall/thick-stone-wall.png` | **Gameplay** alone 1×1 (textured) |
14| `client/assets/blocks/_examples/stone-wall/thick-stone-wall.png` | **Shape mask** alone 1×1 (face-id greys) |
15| `client/assets/blocks/thick-stone-wall/thick-stone-wall-*.png` | 15 connected gameplay variants |
16| `client/assets/blocks/_examples/stone-wall/ref-thick-alone-256.png` | Nearest-neighbour ×16 alone (shape) |
17| `…/ref-thick-face-id-16.png` / `…-256.png` | False-colour face roles |
18| `…/ref-thick-height-16.png` / `…-256.png` | Relative heightmap from roles |
19| `…/ref-thick-face-legend.png` | Colour key for face-id |
20| `…/ref-thick-all-variants.png` | Labeled 4×4 sheet of all 16 thick states |
21| `client/scripts/export-thick-wall-refs.py` | Regenerates face-id / height / alone refs |
22
23Gameplay keys: `thick-stone-wall`, `thin-stone-wall`. Suffixes from cardinal neighbours only (`n`/`e`/`s`/`w` → e.g. `we`, `ns`, `esw`, `wne`, `nesw`). See `shared/world/neighborConnect.js`.
24
25---
26
27## 1. Camera and axes
28
29- Tile size: **16×16** px.
30- **+X = east** (right), **+Y = south** (down on screen).
31- View: **top-down with a front bias** — you see the flat **top**, thin **west/east** vertical sides, and a tall **south** front face.
32- Greys are **face identity**, not painted lighting noise. Texture work must stay inside these regions.
33
34```text
35 N (−Y)
36 ↑
37 W ← tile → E
38 ↓
39 S (+Y, toward camera)
40```
41
42---
43
44## 2. Greyscale vocabulary (face IDs)
45
46Exact values from `thick-stone-wall.png`. Six tones only:
47
48| Grey | Hex | Role | Reads as |
49|------|-----|------|----------|
50| 64 | `0x40` | **Outline / crease** | Outer rim + lip between faces |
51| 175 | `0xAF` | **North bevel** | Top rim facing north (−Y) — brightest body |
52| 149 | `0x95` | **West face** | Vertical face facing west (−X) |
53| 128 | `0x80` | **Top plateau** | Flat upper surface of the volume |
54| 108 | `0x6C` | **East face** | Vertical face facing east (+X) — darker than west |
55| 84 | `0x54` | **South face** | Vertical face facing south (+Y) — darkest body |
56
57Mnemonic on a free 1×1:
58
59```text
60 N = 0xAF (bright)
61W = 0x95 E = 0x6C
62 top = 0x80
63 S = 0x54 (dark)
64 outline = 0x40 everywhere edges meet
65```
66
67**Do not invent intermediate greys** when cloning the structure. Remap these six roles to material colours / normals later.
68
69---
70
71## 3. Alone anatomy (pixel-exact)
72
73Role map of `thick-stone-wall.png` (`#` outline, `N`/`W`/`E`/`T`/`S` as above):
74
75```text
76 y\x 0 1 2 3 4 5 6 7 8 9 A B C D E F
77 0 # # # # # # # # # # # # # # # #
78 1 # # # N N N N N N N N N N # # #
79 2 # W W # # # # # # # # # # E E #
80 3 # W W # T T T T T T T T # E E #
81 4 # W W # T T T T T T T T # E E #
82 5 # W W # T T T T T T T T # E E #
83 6 # W W # T T T T T T T T # E E #
84 7 # W W # T T T T T T T T # E E #
85 8 # W W # T T T T T T T T # E E #
86 9 # W W # # # # # # # # # # E E #
87 10 # W W # S S S S S S S S # E E #
88 11 # W # S S S S S S S S S S # E #
89 12 # W # S S S S S S S S S S # E #
90 13 # # S S S S S S S S S S S S # #
91 14 # # S S S S S S S S S S S S # #
92 15 # # # # # # # # # # # # # # # #
93```
94
95### Region boxes (inclusive)
96
97| Role | Pixels | Notes |
98|------|--------|-------|
99| Outline | Full perimeter + every lip between faces | Never fill with body grey |
100| North bevel | `y=1`, `x=3..12` | Only when **north is free** |
101| West face | `x=1..2`, `y=2..12` (tapers: one px at `y=11..12`) | Only when **west is free** |
102| East face | `x=13..14`, `y=2..12` (tapers) | Only when **east is free** |
103| Top plateau | `x=4..11`, `y=3..8` | Surrounded by `0x40` lips |
104| South face | `y=10..14`, widens downward (`x=4..11` → `x=2..13`) | Only when **south is free** |
105
106### Volume model
107
108Read the tile as a **truncated box / frustum**:
109
1101. **Roof** — plateau `0x80` with north lip `0xAF`.
1112. **Side walls** — west `0x95`, east `0x6C` (asymmetry = light from NW).
1123. **Front wall** — south `0x54`, taller in screen space.
1134. **Creases** — `0x40` at every face junction and the tile border.
114
115Corners are mitered: NW = N↔W, NE = N↔E, SW = S↔W, SE = S↔E, resolved by outline pixels.
116
117---
118
119## 4. Connection rule (core)
120
121A suffix letter means: **this tile continues into a neighbour on that side**.
122
123For each connected cardinal:
124
1251. **Remove** that side’s free-face band (`N`/`E`/`S`/`W` grey).
1262. **Extrude** interior bands (plateau, remaining free faces, and their outline lips) **to the tile edge** on that side so the neighbour can match.
1273. **Keep** free-face bands only on sides that are **not** connected.
128
129| Open | Remove | Extrude to edge |
130|------|--------|-----------------|
131| **N** | North bevel `0xAF` (+ north rim treatment) | W / E / T run to `y=0` |
132| **E** | East face `0x6C` | N (if free) / T / S run to `x=15` |
133| **S** | South face `0x54` | W / E / T run to `y=15` |
134| **W** | West face `0x95` | N (if free) / T / S run to `x=0` |
135
136### Opposite pairs
137
138**`ns`** — vertical run: full-height W + T + E columns; no N bevel, no S front.
139
140```text
141##WW##TTTTTTTT##EE## (repeats y=0..15)
142```
143
144**`we`** — horizontal run: full-width N rim (if free), T band, S band; no W/E sides.
145
146```text
147################ y0
148NNNNNNNNNNNNNNNN y1
149################ y2
150TTTTTTTTTTTTTTTT y3..8
151################ y9
152SSSSSSSSSSSSSSSS y10..14
153################ y15
154```
155
156### Seam contract
157
158Across a shared edge, both tiles paint the **same continuing role** to `x=0|15` or `y=0|15`. Example: A=`…e` and B=`…w` both show plateau `0x80` (and matching N/S bands) meeting mid-edge — **no** side-face grey on that shared edge.
159
160---
161
162## 5. Corners, T-junctions, and concave pockets
163
164Corners (`ne`, `es`, `sw`, `wn`) and T’s (`esw`, `wne`, `swn`, `nes`) are **unions** of the open-face rules.
165
166Where two **free** faces would have met at a concave inner corner after opening the other sides, the art keeps a small **pocket**: outline + a stub of the free face greys. That pocket is what makes an L or T read as a turn rather than a flat extrusion.
167
168Examples (schematic):
169
170**`es`** (open E+S → free N+W): south-east corner keeps an E/S pocket while T extrudes east and south elsewhere.
171
172**`esw`** (T, free N only): full-width N + T like `we`, but south edge shows **two** S/W and S/E pockets at the SW and SE corners (the stem of the T going south).
173
174**`wne`** (T, free S only): full-width S band; north edge shows N pockets at NW/NE where the stem goes north.
175
176**`nesw`** (all four open): no full free faces; T fills the centre and runs to all edges, with **four corner pockets** (N stubs at top, S/W/E stubs at bottom corners). Those pockets are intentional — they are the miters where four neighbour walls meet around this cell in a solid fill / 2×2 interior is different from a true cross; authored `nesw` still carries corner detail for visual continuity with T/L art.
177
178### 2×2 solid block
179
180Four tiles use **corner** suffixes, not `nesw`:
181
182| Cell | Suffix |
183|------|--------|
184| NW | `es` |
185| NE | `sw` |
186| SW | `ne` |
187| SE | `wn` |
188
189Each keeps the two **outer** free faces and opens the two **inner** sides into the cluster. (`nesw` is for a cell with neighbours on all four cardinals — e.g. interior of a thicker shape — not for the four cells of a minimal 2×2.)
190
191---
192
193## 6. Worked single-open examples
194
195**`n`** — north open: row 0 becomes the old “interior” W/T/E pattern; south stack unchanged.
196
197```text
198##WW##TTTTTTTT##EE## y0..8
199##WW############EE## y9
200##WW##SSSSSSSS##EE## y10
201… south taper …
202################ y15
203```
204
205**`s`** — south open: plateau + sides continue through `y=15`; no `0x54`.
206
207**`e`** — east open: N/T/S (and W) run to `x=15`; no `0x6C`.
208
209**`w`** — west open: N/T/S run to `x=0`; free east column remains.
210
211> **Note:** free east on `thick-stone-wall-w` uses `0x6C` (corrected). When flipping `e`↔`w` art, always reassign face greys — do not keep mirrored luminance.
212
213---
214
215## 7. Heightmap (for cloning / normals)
216
217`ref-thick-height-*.png` maps roles → relative height (0–255):
218
219| Role | Height | Order |
220|------|--------|-------|
221| Outline | 40 | Lowest (crease / contact) |
222| South face | 80 | Front of prism |
223| East face | 140 | Side |
224| West face | 160 | Side (slightly higher = lit side) |
225| Top plateau | 200 | Roof |
226| North bevel | 220 | Upper lip |
227
228Ordering to preserve when editing:
229`outline ≤ south ≤ east ≤ west ≤ top ≤ north`.
230
231Uses:
232
233- Extrude a new material with the **same silhouettes**.
234- Bake normals: up on plateau, −Y on north bevel, ±X on sides, +Y on south.
235- Validate connection variants (no south-height pixels on the plateau).
236
237This is a **role-derived** height field, not scanned depth. Absolute values may shift for a shader; keep the order.
238
239---
240
241## 8. Face-id map (tooling)
242
243False colour in `ref-thick-face-id-*.png`:
244
245| Colour | Role |
246|--------|------|
247| White | North bevel |
248| Red | West face |
249| Blue | East face |
250| Green | South face |
251| Amber | Top plateau |
252| Near-black | Outline |
253
254Suggested pipeline for a new wall set:
255
2561. Author or copy **face-id** (or height + face-id) at 16×16.
2572. Fill each role with albedo / material detail **inside** the mask.
2583. Optional soft light multiply that still respects N lightest → S darkest.
2594. Keep outline as mortar/edge or replace with a 1px edge pass.
2605. Derive the 15 connection variants by applying §4–§5 (or paint from thick examples with recolour-by-role).
261
262---
263
264## 9. Checklist — new thick-style wall
265
266**Alone**
267
268- [ ] Full-tile thick footprint (or intentional inset for a thin family).
269- [ ] Only the six role greys (or 1:1 mapped equivalents).
270- [ ] Free N → `0xAF` rim; free W → `0x95`; free E → `0x6C`; free S → `0x54`; centre → `0x80`.
271- [ ] Outline separates every face pair.
272
273**Each suffix**
274
275- [ ] Connected side has no free-face band of that direction.
276- [ ] Interior bands meet the tile edge on connected sides.
277- [ ] Free sides keep the correct face grey (`E` = `0x6C`, not a flipped `0x95`).
278- [ ] Seam matches the opposite suffix on the neighbour (`e`↔`w`, `n`↔`s`).
279- [ ] L/T/`nesw` keep concave corner pockets where needed.
280
281**Texturing**
282
283- [ ] No detail crossing role boundaries without an outline.
284- [ ] Normals follow face directions in §7.
285- [ ] After recolour, regenerate face-id/height refs and spot-check all 16 states.
286
287---
288
289## 10. Thin walls
290
291`thin-stone-wall` uses the **same idea** on a **narrow frustum**, but a slightly different grey vocabulary:
292
293| Grey | Hex | Thin role |
294|------|-----|-----------|
295| 64 | `0x40` | Outline |
296| 182 | `0xB6` | West face |
297| 149 | `0x95` | North rim / ridge top |
298| 128 | `0x80` | East face (**not** top plateau — differs from thick) |
299| 115 | `0x73` | South / front body |
300
301Clone thin silhouettes; recolour via this table (or `texture-stone-wall-sprites.mjs`).
302
303---
304
305## 11. Baking cobble texture
306
307Gameplay sprites in `thick-stone-wall/` and `thin-stone-wall/` are **textured**. Greyscale face-id masks stay in `_examples/stone-wall/`.
308
309```bash
310node client/scripts/texture-stone-wall-sprites.mjs
311```
312
313Reads example masks → writes cobble-shaded PNGs using the old cool-grey stone palette (TOP / FACE / EDGE / MORTAR speckles), keyed by face role. Re-run after editing shapes in `_examples`.
314
315---
316
317## 12. Code touchpoints
318
319| Concern | Location |
320|---------|----------|
321| Cardinal suffix / mask (`& 15`) | `shared/world/neighborConnect.js` |
322| Block defs | `shared/definitions/tiles.js` |
323| Textured sprites (gameplay) | `client/assets/blocks/thick-stone-wall/`, `thin-stone-wall/` |
324| Greyscale shape masks + refs | `client/assets/blocks/_examples/stone-wall/` |
325| Shape generator from connecting examples | `client/scripts/generate-stone-wall-sprites.mjs` |
326| Cobble texture bake | `client/scripts/texture-stone-wall-sprites.mjs` |
327| Ref export | `client/scripts/export-thick-wall-refs.py` |
328
329Editor recomputes neighbour suffixes on paint and on chunk load so a 2×2 stays on corner suffixes, not `nesw`.
330
331---
332
333## 13. Regenerate reference maps
334
335Whenever the thick alone **shape** mask changes:
336
337```bash
338python3 client/scripts/export-thick-wall-refs.py
339node client/scripts/texture-stone-wall-sprites.mjs
340```
341
342Then update the grey table in §2 / §10 if the vocabulary shifted.
server/src/assets/spriteCatalog.js +1 −0
@@ -504,5 +504,6 @@ function listPngStems (folder)
504 504 return entries
505 505 .filter((entry) => entry.isFile() && extname(entry.name).toLowerCase() === ".png")
506 506 .map((entry) => entry.name.slice(0, -extname(entry.name).length))
507 .filter((stem) => !stem.startsWith("example") && !stem.startsWith("_"))
507 508 .sort((a, b) => a.localeCompare(b, "en", { numeric: true, sensitivity: "base" }));
508 509 }
@@ -504,5 +504,6 @@ function listPngStems (folder)
504 return entries
504 return entries
505 .filter((entry) => entry.isFile() && extname(entry.name).toLowerCase() === ".png")
505 .filter((entry) => entry.isFile() && extname(entry.name).toLowerCase() === ".png")
506 .map((entry) => entry.name.slice(0, -extname(entry.name).length))
506 .map((entry) => entry.name.slice(0, -extname(entry.name).length))
507 .filter((stem) => !stem.startsWith("example") && !stem.startsWith("_"))
507 .sort((a, b) => a.localeCompare(b, "en", { numeric: true, sensitivity: "base" }));
508 .sort((a, b) => a.localeCompare(b, "en", { numeric: true, sensitivity: "base" }));
508}
509}
server/tests/central-exchange.test.js +43 −2
@@ -1,6 +1,7 @@
1 1 import test from "node:test";
2 2 import assert from "node:assert/strict";
3 import {
3 import
4 {
4 5 NeighborBit,
5 6 computeNeighborConnectMask,
6 7 neighborConnectStateName,
@@ -9,7 +10,10 @@ import {
9 10 neighborConnectBlocksMatch,
10 11 parseMaterialNeighborConnectState,
11 12 worldTileToChunkLocal,
12 neighborConnectRefreshTiles
13 neighborConnectRefreshTiles,
14 cardinalConnectionSuffix,
15 composeNamedNeighborConnectState,
16 parseNamedNeighborConnectMask
13 17 } from "../../shared/world/neighborConnect.js";
14 18 import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";
15 19 import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";
@@ -30,6 +34,43 @@ test("neighbor connect masks cover all NESW combinations", () =>
30 34 assert.equal(mask, NeighborBit.n | NeighborBit.e);
31 35 });
32 36
37 test("named wall connection suffixes follow nesw / we / esw / wne", () =>
38 {
39 assert.equal(cardinalConnectionSuffix(0), "");
40 assert.equal(cardinalConnectionSuffix(NeighborBit.e | NeighborBit.w), "we");
41 assert.equal(cardinalConnectionSuffix(NeighborBit.n | NeighborBit.s), "ns");
42 assert.equal(
43 cardinalConnectionSuffix(NeighborBit.e | NeighborBit.s | NeighborBit.w),
44 "esw"
45 );
46 assert.equal(
47 cardinalConnectionSuffix(NeighborBit.w | NeighborBit.n | NeighborBit.e),
48 "wne"
49 );
50 assert.equal(
51 cardinalConnectionSuffix(NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w),
52 "nesw"
53 );
54 const def = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true };
55 assert.equal(composeNamedNeighborConnectState(def, 0), "thick-stone-wall");
56 assert.equal(
57 composeNamedNeighborConnectState(def, NeighborBit.e | NeighborBit.s | NeighborBit.w),
58 "thick-stone-wall-esw"
59 );
60 assert.equal(parseNamedNeighborConnectMask("thick-stone-wall-wne", def), NeighborBit.w | NeighborBit.n | NeighborBit.e);
61 assert.equal(parseNamedNeighborConnectMask("14", def), 14);
62 assert.deepEqual(neighborConnectRefreshTiles(15, 8).length, 5);
63 });
64
65 test("legacy diagonal wall masks keep cardinals only (19 → ne, not nesw)", () =>
66 {
67 const def = { key: "thin-stone-wall", neighborConnect: true, neighborConnectNamed: true };
68 assert.equal(parseNamedNeighborConnectMask("19", def), NeighborBit.n | NeighborBit.e);
69 assert.equal(composeNamedNeighborConnectState(def, parseNamedNeighborConnectMask("19", def)), "thin-stone-wall-ne");
70 assert.equal(parseNamedNeighborConnectMask("38", def), NeighborBit.e | NeighborBit.s);
71 assert.equal(parseNamedNeighborConnectMask("255", def), 15);
72 });
73
33 74 test("material neighbor-connect states keep wood id and only match same material", () =>
34 75 {
35 76 const def = BLOCK_DEFINITIONS[BlockType.table];
@@ -1,6 +1,7 @@
1import test from "node:test";
1import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import {
3import
4{
4 NeighborBit,
5 NeighborBit,
5 computeNeighborConnectMask,
6 computeNeighborConnectMask,
6 neighborConnectStateName,
7 neighborConnectStateName,
@@ -9,7 +10,10 @@ import {
9 neighborConnectBlocksMatch,
10 neighborConnectBlocksMatch,
10 parseMaterialNeighborConnectState,
11 parseMaterialNeighborConnectState,
11 worldTileToChunkLocal,
12 worldTileToChunkLocal,
12 neighborConnectRefreshTiles
13 neighborConnectRefreshTiles,
14 cardinalConnectionSuffix,
15 composeNamedNeighborConnectState,
16 parseNamedNeighborConnectMask
13} from "../../shared/world/neighborConnect.js";
17} from "../../shared/world/neighborConnect.js";
14import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";
18import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";
15import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";
19import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";
@@ -30,6 +34,43 @@ test("neighbor connect masks cover all NESW combinations", () =>
30 assert.equal(mask, NeighborBit.n | NeighborBit.e);
34 assert.equal(mask, NeighborBit.n | NeighborBit.e);
31});
35});
32
36
37test("named wall connection suffixes follow nesw / we / esw / wne", () =>
38{
39 assert.equal(cardinalConnectionSuffix(0), "");
40 assert.equal(cardinalConnectionSuffix(NeighborBit.e | NeighborBit.w), "we");
41 assert.equal(cardinalConnectionSuffix(NeighborBit.n | NeighborBit.s), "ns");
42 assert.equal(
43 cardinalConnectionSuffix(NeighborBit.e | NeighborBit.s | NeighborBit.w),
44 "esw"
45 );
46 assert.equal(
47 cardinalConnectionSuffix(NeighborBit.w | NeighborBit.n | NeighborBit.e),
48 "wne"
49 );
50 assert.equal(
51 cardinalConnectionSuffix(NeighborBit.n | NeighborBit.e | NeighborBit.s | NeighborBit.w),
52 "nesw"
53 );
54 const def = { key: "thick-stone-wall", neighborConnect: true, neighborConnectNamed: true };
55 assert.equal(composeNamedNeighborConnectState(def, 0), "thick-stone-wall");
56 assert.equal(
57 composeNamedNeighborConnectState(def, NeighborBit.e | NeighborBit.s | NeighborBit.w),
58 "thick-stone-wall-esw"
59 );
60 assert.equal(parseNamedNeighborConnectMask("thick-stone-wall-wne", def), NeighborBit.w | NeighborBit.n | NeighborBit.e);
61 assert.equal(parseNamedNeighborConnectMask("14", def), 14);
62 assert.deepEqual(neighborConnectRefreshTiles(15, 8).length, 5);
63});
64
65test("legacy diagonal wall masks keep cardinals only (19 → ne, not nesw)", () =>
66{
67 const def = { key: "thin-stone-wall", neighborConnect: true, neighborConnectNamed: true };
68 assert.equal(parseNamedNeighborConnectMask("19", def), NeighborBit.n | NeighborBit.e);
69 assert.equal(composeNamedNeighborConnectState(def, parseNamedNeighborConnectMask("19", def)), "thin-stone-wall-ne");
70 assert.equal(parseNamedNeighborConnectMask("38", def), NeighborBit.e | NeighborBit.s);
71 assert.equal(parseNamedNeighborConnectMask("255", def), 15);
72});
73
33test("material neighbor-connect states keep wood id and only match same material", () =>
74test("material neighbor-connect states keep wood id and only match same material", () =>
34{
75{
35 const def = BLOCK_DEFINITIONS[BlockType.table];
76 const def = BLOCK_DEFINITIONS[BlockType.table];
server/tests/season.test.js +16 −15
@@ -2,19 +2,20 @@ import test from "node:test";
2 2 import assert from "node:assert/strict";
3 3 import { fileURLToPath } from "node:url";
4 4 import { join } from "node:path";
5 import {
6 SeasonId,
7 GrowthSeasonId,
8 seasonIdAt,
9 growthSeasonIdAt,
10 regrowDurationMultiplier,
11 scaleRegrowDurationMs,
12 resolveSeasonalVisualState,
13 preferredSeasonalDefaultState,
14 typeHasSeasonalStates,
15 seasonalCycleStates,
16 seasonIdFromVisualState
17 } from "../../shared/world/season.js";
5 import
6 {
7 SeasonId,
8 GrowthSeasonId,
9 seasonIdAt,
10 growthSeasonIdAt,
11 regrowDurationMultiplier,
12 scaleRegrowDurationMs,
13 resolveSeasonalVisualState,
14 preferredSeasonalDefaultState,
15 typeHasSeasonalStates,
16 seasonalCycleStates,
17 seasonIdFromVisualState
18 } from "../../shared/world/season.js";
18 19 import { shopRestockDayKey } from "../../shared/shop/pricing.js";
19 20 import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
20 21
@@ -143,8 +144,8 @@ test("catalog exposes seasonal grass and pine-tree states", () =>
143 144 assert.equal(catalog.blocks["pine-tree"].defaultState, "summer");
144 145 assert.equal(catalog.blocks["pine-tree"].outdoor, true);
145 146 assert.equal(catalog.blocks["pine-tree"].seasonal, true);
146 assert.equal(catalog.blocks["stone-wall"].outdoor, false);
147 assert.equal(catalog.blocks["stone-wall"].seasonal, false);
147 assert.equal(catalog.blocks["thick-stone-wall"].outdoor, false);
148 assert.equal(catalog.blocks["thick-stone-wall"].seasonal, false);
148 149 assert.ok(catalog.images.some((image) => image.name === "block:boulder:boulder-winter"));
149 150 assert.ok(catalog.images.some((image) => image.name === "block:boulder:copper-ore-winter"));
150 151 assert.ok(catalog.images.some((image) => image.url.includes("boulder-ore-winter.png")));
@@ -2,19 +2,20 @@ import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { fileURLToPath } from "node:url";
3import { fileURLToPath } from "node:url";
4import { join } from "node:path";
4import { join } from "node:path";
5import {
5import
6 SeasonId,
6 {
7 GrowthSeasonId,
7 SeasonId,
8 seasonIdAt,
8 GrowthSeasonId,
9 growthSeasonIdAt,
9 seasonIdAt,
10 regrowDurationMultiplier,
10 growthSeasonIdAt,
11 scaleRegrowDurationMs,
11 regrowDurationMultiplier,
12 resolveSeasonalVisualState,
12 scaleRegrowDurationMs,
13 preferredSeasonalDefaultState,
13 resolveSeasonalVisualState,
14 typeHasSeasonalStates,
14 preferredSeasonalDefaultState,
15 seasonalCycleStates,
15 typeHasSeasonalStates,
16 seasonIdFromVisualState
16 seasonalCycleStates,
17} from "../../shared/world/season.js";
17 seasonIdFromVisualState
18 } from "../../shared/world/season.js";
18import { shopRestockDayKey } from "../../shared/shop/pricing.js";
19import { shopRestockDayKey } from "../../shared/shop/pricing.js";
19import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
20import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
20
21
@@ -143,8 +144,8 @@ test("catalog exposes seasonal grass and pine-tree states", () =>
143 assert.equal(catalog.blocks["pine-tree"].defaultState, "summer");
144 assert.equal(catalog.blocks["pine-tree"].defaultState, "summer");
144 assert.equal(catalog.blocks["pine-tree"].outdoor, true);
145 assert.equal(catalog.blocks["pine-tree"].outdoor, true);
145 assert.equal(catalog.blocks["pine-tree"].seasonal, true);
146 assert.equal(catalog.blocks["pine-tree"].seasonal, true);
146 assert.equal(catalog.blocks["stone-wall"].outdoor, false);
147 assert.equal(catalog.blocks["thick-stone-wall"].outdoor, false);
147 assert.equal(catalog.blocks["stone-wall"].seasonal, false);
148 assert.equal(catalog.blocks["thick-stone-wall"].seasonal, false);
148 assert.ok(catalog.images.some((image) => image.name === "block:boulder:boulder-winter"));
149 assert.ok(catalog.images.some((image) => image.name === "block:boulder:boulder-winter"));
149 assert.ok(catalog.images.some((image) => image.name === "block:boulder:copper-ore-winter"));
150 assert.ok(catalog.images.some((image) => image.name === "block:boulder:copper-ore-winter"));
150 assert.ok(catalog.images.some((image) => image.url.includes("boulder-ore-winter.png")));
151 assert.ok(catalog.images.some((image) => image.url.includes("boulder-ore-winter.png")));
server/tests/tile-states.test.js +39 −11
@@ -5,7 +5,8 @@ import { join } from "node:path";
5 5 import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
6 6 import { cycleState, isCompanionSpriteStem, parseSpriteStem, resolveState } from "../../shared/definitions/tileSprites.js";
7 7 import { decodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";
8 import { GroundType, BlockType, normalizeGround, setBlockVisualState } from "../../shared/definitions/tiles.js";
8 import { GroundType, BlockType, normalizeGround, normalizeBlock, setBlockVisualState } from "../../shared/definitions/tiles.js";
9 import { WOOD_TIER_ORDER } from "../../shared/definitions/materialTiers.js";
9 10 import { diffChunks } from "../src/editor/service.js";
10 11
11 12 const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta.url)));
@@ -13,11 +14,27 @@ const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta
13 14 test("sprite folders expose alphabetical states; first is default", () =>
14 15 {
15 16 const catalog = buildSpriteCatalog(ASSET_ROOT);
16 assert.deepEqual(catalog.blocks["stone-wall"].states, [
17 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"
18 ]);
19 assert.equal(catalog.blocks["stone-wall"].defaultState, "0");
20 assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:15"));
17 assert.equal(catalog.blocks["thick-stone-wall"].defaultState, "thick-stone-wall");
18 assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall"));
19 assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-esw"));
20 assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-nesw"));
21 assert.equal(catalog.blocks["thick-stone-wall"].states.length, 16);
22 assert.ok(catalog.images.some((image) => image.name === "block:thick-stone-wall:thick-stone-wall-nesw"));
23 assert.equal(catalog.blocks["thin-stone-wall"].defaultState, "thin-stone-wall");
24 assert.equal(catalog.blocks["thin-stone-wall"].states.length, 16);
25 assert.ok(catalog.images.some((image) => image.name === "block:thin-stone-wall:thin-stone-wall-wne"));
26 assert.equal(catalog.blocks["thick-smooth-stone-wall"].states.length, 16);
27 assert.equal(catalog.blocks["thin-smooth-stone-wall"].states.length, 16);
28 assert.ok(catalog.images.some((image) => image.name === "block:thick-smooth-stone-wall:thick-smooth-stone-wall"));
29 assert.equal(catalog.blocks["thick-brick-wall"].states.length, 16);
30 assert.equal(catalog.blocks["thin-brick-wall"].states.length, 16);
31 assert.ok(catalog.images.some((image) => image.name === "block:thick-brick-wall:thick-brick-wall-we"));
32 assert.ok(catalog.images.some((image) => image.name === "block:thick-wood-wall:pine-0"));
33 assert.ok(catalog.images.some((image) => image.name === "block:thin-wood-wall:oak-15"));
34 assert.equal(catalog.blocks["thick-wood-wall"].states.length, WOOD_TIER_ORDER.length * 16);
35 assert.equal(catalog.blocks["thick-cliff"].states.length, 16);
36 assert.equal(catalog.blocks["thin-cliff"].states.length, 16);
37 assert.ok(catalog.images.some((image) => image.name === "block:thick-cliff:thick-cliff-nesw"));
21 38 assert.equal(catalog.images[0].subImgTotal, 1);
22 39 assert.equal(catalog.images[0].perRow, 1);
23 40 });
@@ -117,17 +134,28 @@ test("gameplay can set a block visual state", () =>
117 134 {
118 135 const data = createEmptyChunkData();
119 136 data.blocks[0] = { typeId: BlockType.stoneWall, state: null, config: null };
120 setBlockVisualState(data.blocks[0], "2");
121 assert.equal(data.blocks[0].state, "2");
137 setBlockVisualState(data.blocks[0], "thick-stone-wall-e");
138 assert.equal(data.blocks[0].state, "thick-stone-wall-e");
122 139 });
123 140
124 141 test("chunk diffs mention visual state changes", () =>
125 142 {
126 143 const previous = createEmptyChunkData();
127 144 const next = createEmptyChunkData();
128 previous.blocks[0] = { typeId: BlockType.stoneWall, state: "1", config: null };
129 next.blocks[0] = { typeId: BlockType.stoneWall, state: "2", config: null };
145 previous.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-n", config: null };
146 next.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-e", config: null };
130 147 const bullets = diffChunks(0, 0, previous, next, true);
131 assert.ok(bullets.some((line) => line.includes("state changed from 1 to 2")));
148 assert.ok(bullets.some((line) =>
149 line.includes("state changed from thick-stone-wall-n to thick-stone-wall-e")));
132 150 assert.equal(normalizeGround(GroundType.grass).typeId, GroundType.grass);
133 151 });
152
153 test("normalizeBlock migrates legacy numeric wall states to named suffixes", () =>
154 {
155 const migrated = normalizeBlock({ typeId: BlockType.stoneWall, state: "14", config: null });
156 assert.equal(migrated.state, "thick-stone-wall-esw");
157 const alone = normalizeBlock({ typeId: BlockType.stoneWallThin, state: "0", config: null });
158 assert.equal(alone.state, "thin-stone-wall");
159 const corner = normalizeBlock({ typeId: BlockType.stoneWallThin, state: "19", config: null });
160 assert.equal(corner.state, "thin-stone-wall-ne");
161 });
@@ -5,7 +5,8 @@ import { join } from "node:path";
5import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
5import { buildSpriteCatalog } from "../src/assets/spriteCatalog.js";
6import { cycleState, isCompanionSpriteStem, parseSpriteStem, resolveState } from "../../shared/definitions/tileSprites.js";
6import { cycleState, isCompanionSpriteStem, parseSpriteStem, resolveState } from "../../shared/definitions/tileSprites.js";
7import { decodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";
7import { decodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";
8import { GroundType, BlockType, normalizeGround, setBlockVisualState } from "../../shared/definitions/tiles.js";
8import { GroundType, BlockType, normalizeGround, normalizeBlock, setBlockVisualState } from "../../shared/definitions/tiles.js";
9import { WOOD_TIER_ORDER } from "../../shared/definitions/materialTiers.js";
9import { diffChunks } from "../src/editor/service.js";
10import { diffChunks } from "../src/editor/service.js";
10
11
11const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta.url)));
12const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta.url)));
@@ -13,11 +14,27 @@ const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta
13test("sprite folders expose alphabetical states; first is default", () =>
14test("sprite folders expose alphabetical states; first is default", () =>
14{
15{
15 const catalog = buildSpriteCatalog(ASSET_ROOT);
16 const catalog = buildSpriteCatalog(ASSET_ROOT);
16 assert.deepEqual(catalog.blocks["stone-wall"].states, [
17 assert.equal(catalog.blocks["thick-stone-wall"].defaultState, "thick-stone-wall");
17 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"
18 assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall"));
18 ]);
19 assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-esw"));
19 assert.equal(catalog.blocks["stone-wall"].defaultState, "0");
20 assert.ok(catalog.blocks["thick-stone-wall"].states.includes("thick-stone-wall-nesw"));
20 assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:15"));
21 assert.equal(catalog.blocks["thick-stone-wall"].states.length, 16);
22 assert.ok(catalog.images.some((image) => image.name === "block:thick-stone-wall:thick-stone-wall-nesw"));
23 assert.equal(catalog.blocks["thin-stone-wall"].defaultState, "thin-stone-wall");
24 assert.equal(catalog.blocks["thin-stone-wall"].states.length, 16);
25 assert.ok(catalog.images.some((image) => image.name === "block:thin-stone-wall:thin-stone-wall-wne"));
26 assert.equal(catalog.blocks["thick-smooth-stone-wall"].states.length, 16);
27 assert.equal(catalog.blocks["thin-smooth-stone-wall"].states.length, 16);
28 assert.ok(catalog.images.some((image) => image.name === "block:thick-smooth-stone-wall:thick-smooth-stone-wall"));
29 assert.equal(catalog.blocks["thick-brick-wall"].states.length, 16);
30 assert.equal(catalog.blocks["thin-brick-wall"].states.length, 16);
31 assert.ok(catalog.images.some((image) => image.name === "block:thick-brick-wall:thick-brick-wall-we"));
32 assert.ok(catalog.images.some((image) => image.name === "block:thick-wood-wall:pine-0"));
33 assert.ok(catalog.images.some((image) => image.name === "block:thin-wood-wall:oak-15"));
34 assert.equal(catalog.blocks["thick-wood-wall"].states.length, WOOD_TIER_ORDER.length * 16);
35 assert.equal(catalog.blocks["thick-cliff"].states.length, 16);
36 assert.equal(catalog.blocks["thin-cliff"].states.length, 16);
37 assert.ok(catalog.images.some((image) => image.name === "block:thick-cliff:thick-cliff-nesw"));
21 assert.equal(catalog.images[0].subImgTotal, 1);
38 assert.equal(catalog.images[0].subImgTotal, 1);
22 assert.equal(catalog.images[0].perRow, 1);
39 assert.equal(catalog.images[0].perRow, 1);
23});
40});
@@ -117,17 +134,28 @@ test("gameplay can set a block visual state", () =>
117{
134{
118 const data = createEmptyChunkData();
135 const data = createEmptyChunkData();
119 data.blocks[0] = { typeId: BlockType.stoneWall, state: null, config: null };
136 data.blocks[0] = { typeId: BlockType.stoneWall, state: null, config: null };
120 setBlockVisualState(data.blocks[0], "2");
137 setBlockVisualState(data.blocks[0], "thick-stone-wall-e");
121 assert.equal(data.blocks[0].state, "2");
138 assert.equal(data.blocks[0].state, "thick-stone-wall-e");
122});
139});
123
140
124test("chunk diffs mention visual state changes", () =>
141test("chunk diffs mention visual state changes", () =>
125{
142{
126 const previous = createEmptyChunkData();
143 const previous = createEmptyChunkData();
127 const next = createEmptyChunkData();
144 const next = createEmptyChunkData();
128 previous.blocks[0] = { typeId: BlockType.stoneWall, state: "1", config: null };
145 previous.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-n", config: null };
129 next.blocks[0] = { typeId: BlockType.stoneWall, state: "2", config: null };
146 next.blocks[0] = { typeId: BlockType.stoneWall, state: "thick-stone-wall-e", config: null };
130 const bullets = diffChunks(0, 0, previous, next, true);
147 const bullets = diffChunks(0, 0, previous, next, true);
131 assert.ok(bullets.some((line) => line.includes("state changed from 1 to 2")));
148 assert.ok(bullets.some((line) =>
149 line.includes("state changed from thick-stone-wall-n to thick-stone-wall-e")));
132 assert.equal(normalizeGround(GroundType.grass).typeId, GroundType.grass);
150 assert.equal(normalizeGround(GroundType.grass).typeId, GroundType.grass);
133});
151});
152
153test("normalizeBlock migrates legacy numeric wall states to named suffixes", () =>
154{
155 const migrated = normalizeBlock({ typeId: BlockType.stoneWall, state: "14", config: null });
156 assert.equal(migrated.state, "thick-stone-wall-esw");
157 const alone = normalizeBlock({ typeId: BlockType.stoneWallThin, state: "0", config: null });
158 assert.equal(alone.state, "thin-stone-wall");
159 const corner = normalizeBlock({ typeId: BlockType.stoneWallThin, state: "19", config: null });
160 assert.equal(corner.state, "thin-stone-wall-ne");
161});
shared/definitions/tiles.js +158 −9
@@ -25,7 +25,9 @@ import { isSeasonalStumpState, SeasonId } from "../world/season.js";
25 25 import
26 26 {
27 27 composeNeighborConnectState,
28 definitionUsesMaterialNeighborConnect
28 definitionUsesMaterialNeighborConnect,
29 definitionUsesNamedNeighborConnect,
30 parseNeighborConnectMaskFromState
29 31 } from "../world/neighborConnect.js";
30 32
31 33 export const GroundType = Object.freeze({
@@ -75,7 +77,16 @@ export const BlockType = Object.freeze({
75 77 jeweleringStation: 34,
76 78 flaxPlant: 35,
77 79 silkCocoon: 36,
78 fence: 37
80 fence: 37,
81 stoneWallThin: 38,
82 smoothStoneWall: 39,
83 smoothStoneWallThin: 40,
84 brickWall: 41,
85 brickWallThin: 42,
86 woodWall: 43,
87 woodWallThin: 44,
88 cliff: 45,
89 cliffThin: 46
79 90 });
80 91
81 92 export const GROUND_DEFINITIONS = Object.freeze({
@@ -168,8 +179,8 @@ function treeBlockDef (id, woodTier)
168 179 export const BLOCK_DEFINITIONS = Object.freeze({
169 180 [BlockType.stoneWall]: Object.freeze({
170 181 id: BlockType.stoneWall,
171 key: "stone-wall",
172 displayName: "Stone wall",
182 key: "thick-stone-wall",
183 displayName: "Thick stone wall",
173 184 passable: false,
174 185 lightRangeTiles: 0,
175 186 frames: 1,
@@ -177,8 +188,135 @@ export const BLOCK_DEFINITIONS = Object.freeze({
177 188 animationSpeed: 0,
178 189 /** Building walls count as indoor (no seasonal art required). */
179 190 outdoor: false,
180 /** Autotile via N/E/S/W bitmask states `"0"`…`"15"` (frustum cobble sprites). */
181 neighborConnect: true
191 /** Autotile via named cardinal states (`thick-stone-wall`, `thick-stone-wall-esw`, …). */
192 neighborConnect: true,
193 neighborConnectNamed: true
194 }),
195 [BlockType.stoneWallThin]: Object.freeze({
196 id: BlockType.stoneWallThin,
197 key: "thin-stone-wall",
198 displayName: "Thin stone wall",
199 passable: false,
200 lightRangeTiles: 0,
201 frames: 1,
202 framesPerRow: 1,
203 animationSpeed: 0,
204 outdoor: false,
205 neighborConnect: true,
206 neighborConnectNamed: true
207 }),
208 [BlockType.smoothStoneWall]: Object.freeze({
209 id: BlockType.smoothStoneWall,
210 key: "thick-smooth-stone-wall",
211 displayName: "Thick smooth stone wall",
212 passable: false,
213 lightRangeTiles: 0,
214 frames: 1,
215 framesPerRow: 1,
216 animationSpeed: 0,
217 outdoor: false,
218 neighborConnect: true,
219 neighborConnectNamed: true
220 }),
221 [BlockType.smoothStoneWallThin]: Object.freeze({
222 id: BlockType.smoothStoneWallThin,
223 key: "thin-smooth-stone-wall",
224 displayName: "Thin smooth stone wall",
225 passable: false,
226 lightRangeTiles: 0,
227 frames: 1,
228 framesPerRow: 1,
229 animationSpeed: 0,
230 outdoor: false,
231 neighborConnect: true,
232 neighborConnectNamed: true
233 }),
234 [BlockType.brickWall]: Object.freeze({
235 id: BlockType.brickWall,
236 key: "thick-brick-wall",
237 displayName: "Thick brick wall",
238 passable: false,
239 lightRangeTiles: 0,
240 frames: 1,
241 framesPerRow: 1,
242 animationSpeed: 0,
243 outdoor: false,
244 neighborConnect: true,
245 neighborConnectNamed: true
246 }),
247 [BlockType.brickWallThin]: Object.freeze({
248 id: BlockType.brickWallThin,
249 key: "thin-brick-wall",
250 displayName: "Thin brick wall",
251 passable: false,
252 lightRangeTiles: 0,
253 frames: 1,
254 framesPerRow: 1,
255 animationSpeed: 0,
256 outdoor: false,
257 neighborConnect: true,
258 neighborConnectNamed: true
259 }),
260 [BlockType.woodWall]: Object.freeze({
261 id: BlockType.woodWall,
262 key: "thick-wood-wall",
263 displayName: "Thick wood wall",
264 passable: false,
265 lightRangeTiles: 0,
266 frames: 1,
267 framesPerRow: 1,
268 animationSpeed: 0,
269 outdoor: false,
270 /** Magenta face-lit masks `0`–`15`; catalog expands `${wood}-${mask}`. */
271 neighborConnect: true,
272 neighborConnectByMaterial: true,
273 defaultNeighborMaterial: WoodTier.pine
274 }),
275 [BlockType.woodWallThin]: Object.freeze({
276 id: BlockType.woodWallThin,
277 key: "thin-wood-wall",
278 displayName: "Thin wood wall",
279 passable: false,
280 lightRangeTiles: 0,
281 frames: 1,
282 framesPerRow: 1,
283 animationSpeed: 0,
284 outdoor: false,
285 neighborConnect: true,
286 neighborConnectByMaterial: true,
287 defaultNeighborMaterial: WoodTier.pine
288 }),
289 [BlockType.cliff]: Object.freeze({
290 id: BlockType.cliff,
291 key: "thick-cliff",
292 displayName: "Thick cliff",
293 passable: false,
294 lightRangeTiles: 0,
295 frames: 1,
296 framesPerRow: 1,
297 animationSpeed: 0,
298 outdoor: true,
299 neighborConnect: true,
300 neighborConnectNamed: true,
301 /**
302 * Magenta top faces are replaced at draw time by sampling the chunk
303 * ground atlas at the same tile-local UV (1:1; includes soft-terrain blend).
304 */
305 cliffGroundTop: true
306 }),
307 [BlockType.cliffThin]: Object.freeze({
308 id: BlockType.cliffThin,
309 key: "thin-cliff",
310 displayName: "Thin cliff",
311 passable: false,
312 lightRangeTiles: 0,
313 frames: 1,
314 framesPerRow: 1,
315 animationSpeed: 0,
316 outdoor: true,
317 neighborConnect: true,
318 neighborConnectNamed: true,
319 cliffGroundTop: true
182 320 }),
183 321 [BlockType.torch]: Object.freeze({
184 322 id: BlockType.torch,
@@ -796,10 +934,14 @@ export function listPlaceableBlockPaletteEntries (catalog = null)
796 934 }
797 935 entries.push({
798 936 typeId: def.id,
799 state: "0",
937 state: definitionUsesNamedNeighborConnect(def) ? def.key : "0",
800 938 key: def.key,
801 939 displayName: def.displayName,
802 spriteName: spriteImageName("block", def.key, "0")
940 spriteName: spriteImageName(
941 "block",
942 def.key,
943 definitionUsesNamedNeighborConnect(def) ? def.key : "0"
944 )
803 945 });
804 946 continue;
805 947 }
@@ -967,7 +1109,14 @@ export function normalizeBlock (value)
967 1109 {
968 1110 if (!value || !Number.isInteger(value.typeId))
969 1111 { return null; }
970 return { typeId: value.typeId, state: value.state ?? null, config: value.config ?? null };
1112 let state = value.state ?? null;
1113 const def = BLOCK_DEFINITIONS[value.typeId];
1114 if (def && definitionUsesNamedNeighborConnect(def) && state != null)
1115 {
1116 const mask = parseNeighborConnectMaskFromState(state, def);
1117 state = composeNeighborConnectState(def, state, mask);
1118 }
1119 return { typeId: value.typeId, state, config: value.config ?? null };
971 1120 }
972 1121
973 1122 export function setBlockVisualState (block, state)
@@ -25,7 +25,9 @@ import { isSeasonalStumpState, SeasonId } from "../world/season.js";
25import
25import
26{
26{
27 composeNeighborConnectState,
27 composeNeighborConnectState,
28 definitionUsesMaterialNeighborConnect
28 definitionUsesMaterialNeighborConnect,
29 definitionUsesNamedNeighborConnect,
30 parseNeighborConnectMaskFromState
29} from "../world/neighborConnect.js";
31} from "../world/neighborConnect.js";
30
32
31export const GroundType = Object.freeze({
33export const GroundType = Object.freeze({
@@ -75,7 +77,16 @@ export const BlockType = Object.freeze({
75 jeweleringStation: 34,
77 jeweleringStation: 34,
76 flaxPlant: 35,
78 flaxPlant: 35,
77 silkCocoon: 36,
79 silkCocoon: 36,
78 fence: 37
80 fence: 37,
81 stoneWallThin: 38,
82 smoothStoneWall: 39,
83 smoothStoneWallThin: 40,
84 brickWall: 41,
85 brickWallThin: 42,
86 woodWall: 43,
87 woodWallThin: 44,
88 cliff: 45,
89 cliffThin: 46
79});
90});
80
91
81export const GROUND_DEFINITIONS = Object.freeze({
92export const GROUND_DEFINITIONS = Object.freeze({
@@ -168,8 +179,8 @@ function treeBlockDef (id, woodTier)
168export const BLOCK_DEFINITIONS = Object.freeze({
179export const BLOCK_DEFINITIONS = Object.freeze({
169 [BlockType.stoneWall]: Object.freeze({
180 [BlockType.stoneWall]: Object.freeze({
170 id: BlockType.stoneWall,
181 id: BlockType.stoneWall,
171 key: "stone-wall",
182 key: "thick-stone-wall",
172 displayName: "Stone wall",
183 displayName: "Thick stone wall",
173 passable: false,
184 passable: false,
174 lightRangeTiles: 0,
185 lightRangeTiles: 0,
175 frames: 1,
186 frames: 1,
@@ -177,8 +188,135 @@ export const BLOCK_DEFINITIONS = Object.freeze({
177 animationSpeed: 0,
188 animationSpeed: 0,
178 /** Building walls count as indoor (no seasonal art required). */
189 /** Building walls count as indoor (no seasonal art required). */
179 outdoor: false,
190 outdoor: false,
180 /** Autotile via N/E/S/W bitmask states `"0"`…`"15"` (frustum cobble sprites). */
191 /** Autotile via named cardinal states (`thick-stone-wall`, `thick-stone-wall-esw`, …). */
181 neighborConnect: true
192 neighborConnect: true,
193 neighborConnectNamed: true
194 }),
195 [BlockType.stoneWallThin]: Object.freeze({
196 id: BlockType.stoneWallThin,
197 key: "thin-stone-wall",
198 displayName: "Thin stone wall",
199 passable: false,
200 lightRangeTiles: 0,
201 frames: 1,
202 framesPerRow: 1,
203 animationSpeed: 0,
204 outdoor: false,
205 neighborConnect: true,
206 neighborConnectNamed: true
207 }),
208 [BlockType.smoothStoneWall]: Object.freeze({
209 id: BlockType.smoothStoneWall,
210 key: "thick-smooth-stone-wall",
211 displayName: "Thick smooth stone wall",
212 passable: false,
213 lightRangeTiles: 0,
214 frames: 1,
215 framesPerRow: 1,
216 animationSpeed: 0,
217 outdoor: false,
218 neighborConnect: true,
219 neighborConnectNamed: true
220 }),
221 [BlockType.smoothStoneWallThin]: Object.freeze({
222 id: BlockType.smoothStoneWallThin,
223 key: "thin-smooth-stone-wall",
224 displayName: "Thin smooth stone wall",
225 passable: false,
226 lightRangeTiles: 0,
227 frames: 1,
228 framesPerRow: 1,
229 animationSpeed: 0,
230 outdoor: false,
231 neighborConnect: true,
232 neighborConnectNamed: true
233 }),
234 [BlockType.brickWall]: Object.freeze({
235 id: BlockType.brickWall,
236 key: "thick-brick-wall",
237 displayName: "Thick brick wall",
238 passable: false,
239 lightRangeTiles: 0,
240 frames: 1,
241 framesPerRow: 1,
242 animationSpeed: 0,
243 outdoor: false,
244 neighborConnect: true,
245 neighborConnectNamed: true
246 }),
247 [BlockType.brickWallThin]: Object.freeze({
248 id: BlockType.brickWallThin,
249 key: "thin-brick-wall",
250 displayName: "Thin brick wall",
251 passable: false,
252 lightRangeTiles: 0,
253 frames: 1,
254 framesPerRow: 1,
255 animationSpeed: 0,
256 outdoor: false,
257 neighborConnect: true,
258 neighborConnectNamed: true
259 }),
260 [BlockType.woodWall]: Object.freeze({
261 id: BlockType.woodWall,
262 key: "thick-wood-wall",
263 displayName: "Thick wood wall",
264 passable: false,
265 lightRangeTiles: 0,
266 frames: 1,
267 framesPerRow: 1,
268 animationSpeed: 0,
269 outdoor: false,
270 /** Magenta face-lit masks `0`–`15`; catalog expands `${wood}-${mask}`. */
271 neighborConnect: true,
272 neighborConnectByMaterial: true,
273 defaultNeighborMaterial: WoodTier.pine
274 }),
275 [BlockType.woodWallThin]: Object.freeze({
276 id: BlockType.woodWallThin,
277 key: "thin-wood-wall",
278 displayName: "Thin wood wall",
279 passable: false,
280 lightRangeTiles: 0,
281 frames: 1,
282 framesPerRow: 1,
283 animationSpeed: 0,
284 outdoor: false,
285 neighborConnect: true,
286 neighborConnectByMaterial: true,
287 defaultNeighborMaterial: WoodTier.pine
288 }),
289 [BlockType.cliff]: Object.freeze({
290 id: BlockType.cliff,
291 key: "thick-cliff",
292 displayName: "Thick cliff",
293 passable: false,
294 lightRangeTiles: 0,
295 frames: 1,
296 framesPerRow: 1,
297 animationSpeed: 0,
298 outdoor: true,
299 neighborConnect: true,
300 neighborConnectNamed: true,
301 /**
302 * Magenta top faces are replaced at draw time by sampling the chunk
303 * ground atlas at the same tile-local UV (1:1; includes soft-terrain blend).
304 */
305 cliffGroundTop: true
306 }),
307 [BlockType.cliffThin]: Object.freeze({
308 id: BlockType.cliffThin,
309 key: "thin-cliff",
310 displayName: "Thin cliff",
311 passable: false,
312 lightRangeTiles: 0,
313 frames: 1,
314 framesPerRow: 1,
315 animationSpeed: 0,
316 outdoor: true,
317 neighborConnect: true,
318 neighborConnectNamed: true,
319 cliffGroundTop: true
182 }),
320 }),
183 [BlockType.torch]: Object.freeze({
321 [BlockType.torch]: Object.freeze({
184 id: BlockType.torch,
322 id: BlockType.torch,
@@ -796,10 +934,14 @@ export function listPlaceableBlockPaletteEntries (catalog = null)
796 }
934 }
797 entries.push({
935 entries.push({
798 typeId: def.id,
936 typeId: def.id,
799 state: "0",
937 state: definitionUsesNamedNeighborConnect(def) ? def.key : "0",
800 key: def.key,
938 key: def.key,
801 displayName: def.displayName,
939 displayName: def.displayName,
802 spriteName: spriteImageName("block", def.key, "0")
940 spriteName: spriteImageName(
941 "block",
942 def.key,
943 definitionUsesNamedNeighborConnect(def) ? def.key : "0"
944 )
803 });
945 });
804 continue;
946 continue;
805 }
947 }
@@ -967,7 +1109,14 @@ export function normalizeBlock (value)
967{
1109{
968 if (!value || !Number.isInteger(value.typeId))
1110 if (!value || !Number.isInteger(value.typeId))
969 { return null; }
1111 { return null; }
970 return { typeId: value.typeId, state: value.state ?? null, config: value.config ?? null };
1112 let state = value.state ?? null;
1113 const def = BLOCK_DEFINITIONS[value.typeId];
1114 if (def && definitionUsesNamedNeighborConnect(def) && state != null)
1115 {
1116 const mask = parseNeighborConnectMaskFromState(state, def);
1117 state = composeNeighborConnectState(def, state, mask);
1118 }
1119 return { typeId: value.typeId, state, config: value.config ?? null };
971}
1120}
972
1121
973export function setBlockVisualState (block, state)
1122export function setBlockVisualState (block, state)
shared/world/neighborConnect.js +114 −14
@@ -1,7 +1,9 @@
1 1 /**
2 2 * Generic neighbor-connect autotile masks (N/E/S/W).
3 * Stored as block/ground `state` string `"0"`…`"15"` for bakeable sprite variants.
4 * Same pattern can later apply to walls and selected grounds.
3 * Stored as block/ground `state` for bakeable sprite variants.
4 *
5 * - Cardinal numeric (tables/fences/counters): `"0"`…`"15"` (or `pine-3` with material).
6 * - Named cardinal (stone walls): `"thick-stone-wall"`, `"thick-stone-wall-esw"`, …
5 7 */
6 8
7 9 export const NeighborBit = Object.freeze({
@@ -23,8 +25,101 @@ export function neighborConnectMask ({ n = false, e = false, s = false, w = fals
23 25
24 26 export function neighborConnectStateName (mask)
25 27 {
26 const m = Math.max(0, Math.min(15, mask | 0));
27 return String(m);
28 return String((mask | 0) & 15);
29 }
30
31 /**
32 * Cardinal connection suffix for named wall sprites.
33 * Opposite runs: `ns`, `we`. Three-ways clockwise from the side after the gap
34 * (`esw` = T open north, `wne` = T open south). Full: `nesw`. Alone: `""`.
35 */
36 export function cardinalConnectionSuffix (mask)
37 {
38 const m = (mask | 0) & 15;
39 if (m === 0)
40 { return ""; }
41 const n = (m & NeighborBit.n) !== 0;
42 const e = (m & NeighborBit.e) !== 0;
43 const s = (m & NeighborBit.s) !== 0;
44 const w = (m & NeighborBit.w) !== 0;
45 const count = (n ? 1 : 0) + (e ? 1 : 0) + (s ? 1 : 0) + (w ? 1 : 0);
46 if (count === 1)
47 {
48 if (n)
49 { return "n"; }
50 if (e)
51 { return "e"; }
52 if (s)
53 { return "s"; }
54 return "w";
55 }
56 if (count === 2)
57 {
58 if (n && s)
59 { return "ns"; }
60 if (e && w)
61 { return "we"; }
62 if (n && e)
63 { return "ne"; }
64 if (e && s)
65 { return "es"; }
66 if (s && w)
67 { return "sw"; }
68 return "wn";
69 }
70 if (count === 3)
71 {
72 const bits = [NeighborBit.n, NeighborBit.e, NeighborBit.s, NeighborBit.w];
73 const letters = ["n", "e", "s", "w"];
74 let miss = 0;
75 for (let i = 0; i < 4; i++)
76 {
77 if ((m & bits[i]) === 0)
78 { miss = i; }
79 }
80 return letters[(miss + 1) % 4] + letters[(miss + 2) % 4] + letters[(miss + 3) % 4];
81 }
82 return "nesw";
83 }
84
85 export function composeNamedNeighborConnectState (def, mask)
86 {
87 const key = def?.key ?? "block";
88 const suffix = cardinalConnectionSuffix(mask);
89 return suffix ? `${key}-${suffix}` : key;
90 }
91
92 /** Parse named (`thick-stone-wall-esw`) or bare (`esw`) or legacy numeric states. */
93 export function parseNamedNeighborConnectMask (state, def = null)
94 {
95 const s = String(state ?? "").trim().toLowerCase();
96 if (!s)
97 { return 0; }
98 if (/^\d+$/.test(s))
99 {
100 // Legacy numeric masks may include old diagonal bits (e.g. 19 = N|E|NE).
101 // Keep only cardinals — do not clamp with min(15,n) (that turns 19 into 15/nesw).
102 return (Number(s) | 0) & 15;
103 }
104 const key = String(def?.key ?? "").toLowerCase();
105 if (key && s === key)
106 { return 0; }
107 let suffix = s;
108 if (key && s.startsWith(`${key}-`))
109 { suffix = s.slice(key.length + 1); }
110 let mask = 0;
111 for (const ch of suffix)
112 {
113 if (ch === "n")
114 { mask |= NeighborBit.n; }
115 else if (ch === "e")
116 { mask |= NeighborBit.e; }
117 else if (ch === "s")
118 { mask |= NeighborBit.s; }
119 else if (ch === "w")
120 { mask |= NeighborBit.w; }
121 }
122 return mask;
28 123 }
29 124
30 125 export function parseNeighborConnectMask (state)
@@ -34,7 +129,7 @@ export function parseNeighborConnectMask (state)
34 129 const n = Number(state);
35 130 if (!Number.isFinite(n))
36 131 { return 0; }
37 return Math.max(0, Math.min(15, n | 0));
132 return (n | 0) & 15;
38 133 }
39 134
40 135 export function hasNeighborBit (mask, bit)
@@ -52,7 +147,6 @@ export const NEIGHBOR_CARDINALS = Object.freeze([
52 147
53 148 /**
54 149 * @param {(dx: number, dy: number) => boolean} isConnectedNeighbor
55 * true when the adjacent tile should join (same connectable type).
56 150 */
57 151 export function computeNeighborConnectMask (isConnectedNeighbor)
58 152 {
@@ -70,17 +164,22 @@ export function definitionUsesNeighborConnect (def)
70 164 return !!def?.neighborConnect;
71 165 }
72 166
167 export function definitionUsesNamedNeighborConnect (def)
168 {
169 return !!def?.neighborConnect && !!def?.neighborConnectNamed;
170 }
171
73 172 export function definitionUsesMaterialNeighborConnect (def)
74 173 {
75 174 return !!def?.neighborConnect && !!def?.neighborConnectByMaterial;
76 175 }
77 176
78 function clampMask (value)
177 function clampCardinalMask (value)
79 178 {
80 179 const n = Number(value);
81 180 if (!Number.isFinite(n))
82 181 { return 0; }
83 return Math.max(0, Math.min(15, n | 0));
182 return (n | 0) & 15;
84 183 }
85 184
86 185 /**
@@ -96,12 +195,12 @@ export function parseMaterialNeighborConnectState (state, def = null)
96 195 {
97 196 return {
98 197 material: paired[1].toLowerCase(),
99 mask: clampMask(paired[2])
198 mask: clampCardinalMask(paired[2])
100 199 };
101 200 }
102 201 if (/^\d+$/.test(s))
103 202 {
104 return { material: fallback, mask: clampMask(s) };
203 return { material: fallback, mask: clampCardinalMask(s) };
105 204 }
106 205 if (/^[a-z][a-z0-9]*$/i.test(s))
107 206 {
@@ -112,12 +211,14 @@ export function parseMaterialNeighborConnectState (state, def = null)
112 211
113 212 export function composeNeighborConnectState (def, currentState, mask)
114 213 {
115 const m = clampMask(mask);
214 const m = clampCardinalMask(mask);
116 215 if (definitionUsesMaterialNeighborConnect(def))
117 216 {
118 217 const { material } = parseMaterialNeighborConnectState(currentState, def);
119 218 return `${material}-${m}`;
120 219 }
220 if (definitionUsesNamedNeighborConnect(def))
221 { return composeNamedNeighborConnectState(def, m); }
121 222 return neighborConnectStateName(m);
122 223 }
123 224
@@ -138,14 +239,13 @@ export function parseNeighborConnectMaskFromState (state, def = null)
138 239 {
139 240 if (definitionUsesMaterialNeighborConnect(def))
140 241 { return parseMaterialNeighborConnectState(state, def).mask; }
242 if (definitionUsesNamedNeighborConnect(def))
243 { return parseNamedNeighborConnectMask(state, def); }
141 244 return parseNeighborConnectMask(state);
142 245 }
143 246
144 247 /**
145 248 * Map a world tile to chunk coords + local tile (handles negative world tiles).
146 * @param {number} tileX
147 * @param {number} tileY
148 * @param {number} [chunkSize=16]
149 249 */
150 250 export function worldTileToChunkLocal (tileX, tileY, chunkSize = 16)
151 251 {
@@ -1,7 +1,9 @@
1/**
1/**
2 * Generic neighbor-connect autotile masks (N/E/S/W).
2 * Generic neighbor-connect autotile masks (N/E/S/W).
3 * Stored as block/ground `state` string `"0"`…`"15"` for bakeable sprite variants.
3 * Stored as block/ground `state` for bakeable sprite variants.
4 * Same pattern can later apply to walls and selected grounds.
4 *
5 * - Cardinal numeric (tables/fences/counters): `"0"`…`"15"` (or `pine-3` with material).
6 * - Named cardinal (stone walls): `"thick-stone-wall"`, `"thick-stone-wall-esw"`, …
5 */
7 */
6
8
7export const NeighborBit = Object.freeze({
9export const NeighborBit = Object.freeze({
@@ -23,8 +25,101 @@ export function neighborConnectMask ({ n = false, e = false, s = false, w = fals
23
25
24export function neighborConnectStateName (mask)
26export function neighborConnectStateName (mask)
25{
27{
26 const m = Math.max(0, Math.min(15, mask | 0));
28 return String((mask | 0) & 15);
27 return String(m);
29}
30
31/**
32 * Cardinal connection suffix for named wall sprites.
33 * Opposite runs: `ns`, `we`. Three-ways clockwise from the side after the gap
34 * (`esw` = T open north, `wne` = T open south). Full: `nesw`. Alone: `""`.
35 */
36export function cardinalConnectionSuffix (mask)
37{
38 const m = (mask | 0) & 15;
39 if (m === 0)
40 { return ""; }
41 const n = (m & NeighborBit.n) !== 0;
42 const e = (m & NeighborBit.e) !== 0;
43 const s = (m & NeighborBit.s) !== 0;
44 const w = (m & NeighborBit.w) !== 0;
45 const count = (n ? 1 : 0) + (e ? 1 : 0) + (s ? 1 : 0) + (w ? 1 : 0);
46 if (count === 1)
47 {
48 if (n)
49 { return "n"; }
50 if (e)
51 { return "e"; }
52 if (s)
53 { return "s"; }
54 return "w";
55 }
56 if (count === 2)
57 {
58 if (n && s)
59 { return "ns"; }
60 if (e && w)
61 { return "we"; }
62 if (n && e)
63 { return "ne"; }
64 if (e && s)
65 { return "es"; }
66 if (s && w)
67 { return "sw"; }
68 return "wn";
69 }
70 if (count === 3)
71 {
72 const bits = [NeighborBit.n, NeighborBit.e, NeighborBit.s, NeighborBit.w];
73 const letters = ["n", "e", "s", "w"];
74 let miss = 0;
75 for (let i = 0; i < 4; i++)
76 {
77 if ((m & bits[i]) === 0)
78 { miss = i; }
79 }
80 return letters[(miss + 1) % 4] + letters[(miss + 2) % 4] + letters[(miss + 3) % 4];
81 }
82 return "nesw";
83}
84
85export function composeNamedNeighborConnectState (def, mask)
86{
87 const key = def?.key ?? "block";
88 const suffix = cardinalConnectionSuffix(mask);
89 return suffix ? `${key}-${suffix}` : key;
90}
91
92/** Parse named (`thick-stone-wall-esw`) or bare (`esw`) or legacy numeric states. */
93export function parseNamedNeighborConnectMask (state, def = null)
94{
95 const s = String(state ?? "").trim().toLowerCase();
96 if (!s)
97 { return 0; }
98 if (/^\d+$/.test(s))
99 {
100 // Legacy numeric masks may include old diagonal bits (e.g. 19 = N|E|NE).
101 // Keep only cardinals — do not clamp with min(15,n) (that turns 19 into 15/nesw).
102 return (Number(s) | 0) & 15;
103 }
104 const key = String(def?.key ?? "").toLowerCase();
105 if (key && s === key)
106 { return 0; }
107 let suffix = s;
108 if (key && s.startsWith(`${key}-`))
109 { suffix = s.slice(key.length + 1); }
110 let mask = 0;
111 for (const ch of suffix)
112 {
113 if (ch === "n")
114 { mask |= NeighborBit.n; }
115 else if (ch === "e")
116 { mask |= NeighborBit.e; }
117 else if (ch === "s")
118 { mask |= NeighborBit.s; }
119 else if (ch === "w")
120 { mask |= NeighborBit.w; }
121 }
122 return mask;
28}
123}
29
124
30export function parseNeighborConnectMask (state)
125export function parseNeighborConnectMask (state)
@@ -34,7 +129,7 @@ export function parseNeighborConnectMask (state)
34 const n = Number(state);
129 const n = Number(state);
35 if (!Number.isFinite(n))
130 if (!Number.isFinite(n))
36 { return 0; }
131 { return 0; }
37 return Math.max(0, Math.min(15, n | 0));
132 return (n | 0) & 15;
38}
133}
39
134
40export function hasNeighborBit (mask, bit)
135export function hasNeighborBit (mask, bit)
@@ -52,7 +147,6 @@ export const NEIGHBOR_CARDINALS = Object.freeze([
52
147
53/**
148/**
54 * @param {(dx: number, dy: number) => boolean} isConnectedNeighbor
149 * @param {(dx: number, dy: number) => boolean} isConnectedNeighbor
55 * true when the adjacent tile should join (same connectable type).
56 */
150 */
57export function computeNeighborConnectMask (isConnectedNeighbor)
151export function computeNeighborConnectMask (isConnectedNeighbor)
58{
152{
@@ -70,17 +164,22 @@ export function definitionUsesNeighborConnect (def)
70 return !!def?.neighborConnect;
164 return !!def?.neighborConnect;
71}
165}
72
166
167export function definitionUsesNamedNeighborConnect (def)
168{
169 return !!def?.neighborConnect && !!def?.neighborConnectNamed;
170}
171
73export function definitionUsesMaterialNeighborConnect (def)
172export function definitionUsesMaterialNeighborConnect (def)
74{
173{
75 return !!def?.neighborConnect && !!def?.neighborConnectByMaterial;
174 return !!def?.neighborConnect && !!def?.neighborConnectByMaterial;
76}
175}
77
176
78function clampMask (value)
177function clampCardinalMask (value)
79{
178{
80 const n = Number(value);
179 const n = Number(value);
81 if (!Number.isFinite(n))
180 if (!Number.isFinite(n))
82 { return 0; }
181 { return 0; }
83 return Math.max(0, Math.min(15, n | 0));
182 return (n | 0) & 15;
84}
183}
85
184
86/**
185/**
@@ -96,12 +195,12 @@ export function parseMaterialNeighborConnectState (state, def = null)
96 {
195 {
97 return {
196 return {
98 material: paired[1].toLowerCase(),
197 material: paired[1].toLowerCase(),
99 mask: clampMask(paired[2])
198 mask: clampCardinalMask(paired[2])
100 };
199 };
101 }
200 }
102 if (/^\d+$/.test(s))
201 if (/^\d+$/.test(s))
103 {
202 {
104 return { material: fallback, mask: clampMask(s) };
203 return { material: fallback, mask: clampCardinalMask(s) };
105 }
204 }
106 if (/^[a-z][a-z0-9]*$/i.test(s))
205 if (/^[a-z][a-z0-9]*$/i.test(s))
107 {
206 {
@@ -112,12 +211,14 @@ export function parseMaterialNeighborConnectState (state, def = null)
112
211
113export function composeNeighborConnectState (def, currentState, mask)
212export function composeNeighborConnectState (def, currentState, mask)
114{
213{
115 const m = clampMask(mask);
214 const m = clampCardinalMask(mask);
116 if (definitionUsesMaterialNeighborConnect(def))
215 if (definitionUsesMaterialNeighborConnect(def))
117 {
216 {
118 const { material } = parseMaterialNeighborConnectState(currentState, def);
217 const { material } = parseMaterialNeighborConnectState(currentState, def);
119 return `${material}-${m}`;
218 return `${material}-${m}`;
120 }
219 }
220 if (definitionUsesNamedNeighborConnect(def))
221 { return composeNamedNeighborConnectState(def, m); }
121 return neighborConnectStateName(m);
222 return neighborConnectStateName(m);
122}
223}
123
224
@@ -138,14 +239,13 @@ export function parseNeighborConnectMaskFromState (state, def = null)
138{
239{
139 if (definitionUsesMaterialNeighborConnect(def))
240 if (definitionUsesMaterialNeighborConnect(def))
140 { return parseMaterialNeighborConnectState(state, def).mask; }
241 { return parseMaterialNeighborConnectState(state, def).mask; }
242 if (definitionUsesNamedNeighborConnect(def))
243 { return parseNamedNeighborConnectMask(state, def); }
141 return parseNeighborConnectMask(state);
244 return parseNeighborConnectMask(state);
142}
245}
143
246
144/**
247/**
145 * Map a world tile to chunk coords + local tile (handles negative world tiles).
248 * Map a world tile to chunk coords + local tile (handles negative world tiles).
146 * @param {number} tileX
147 * @param {number} tileY
148 * @param {number} [chunkSize=16]
149 */
249 */
150export function worldTileToChunkLocal (tileX, tileY, chunkSize = 16)
250export function worldTileToChunkLocal (tileX, tileY, chunkSize = 16)
151{
251{