BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

tiles.js 27.5 KiB Download Raw
1import
2{
3 ORE_BEARING_MATERIALS,
4 oreBoulderState,
5 materialFromOreBoulderState,
6 MATERIAL_DISPLAY_NAME,
7 isGemstoneMaterial,
8 WoodTier,
9 WOOD_TIER_ORDER
10} from "./materialTiers.js";
11import
12{
13 FLOWER_COLOR_ORDER,
14 FLOWER_COLOR_DISPLAY,
15 flowerBlockState
16} from "./dyes.js";
17import
18{
19 HERB_ORDER,
20 HERB_DEFINITIONS,
21 herbDefinition
22} from "./herbs.js";
23import { spriteImageName, defaultStateForType } from "./tileSprites.js";
24import { isSeasonalStumpState, SeasonId } from "../world/season.js";
25import
26{
27 composeNeighborConnectState,
28 definitionUsesMaterialNeighborConnect,
29 definitionUsesNamedNeighborConnect,
30 parseNeighborConnectMaskFromState
31} from "../world/neighborConnect.js";
32
33export const GroundType = Object.freeze({
34 grass: 1,
35 wood: 2,
36 water: 3,
37 deepWater: 4,
38 dirt: 5
39});
40
41export const BlockType = Object.freeze({
42 stoneWall: 1,
43 torch: 2,
44 /** @deprecated Legacy authored block; migrated into chunk `spawners[]` on load. */
45 spawner: 3,
46 bank: 4,
47 churchAltar: 5,
48 cauldron: 6,
49 boulder: 7,
50 furnace: 8,
51 anvil: 9,
52 woodworkingBench: 10,
53 craftingBench: 11,
54 pineTree: 12,
55 marketplace: 13,
56 table: 14,
57 flower: 15,
58 cottonPlant: 16,
59 spinningWheel: 17,
60 loom: 18,
61 tailorBench: 19,
62 bountyOffice: 20,
63 barber: 23,
64 /** Folklore herbs — state is herbId (`sage`, `mint`, …); sprites in `assets/herbs/`. */
65 herbPlant: 24,
66 birchTree: 21,
67 oakTree: 22,
68 ebonyTree: 25,
69 lignumTree: 26,
70 heartwoodTree: 27,
71 elderTree: 28,
72 leatherworkingTable: 29,
73 doorway: 30,
74 campfire: 31,
75 oven: 32,
76 fishingSpot: 33,
77 jeweleringStation: 34,
78 flaxPlant: 35,
79 silkCocoon: 36,
80 fence: 37,
81 stoneWallThin: 38,
82 /** Former thick smooth stone wall (39) removed — id left unused. */
83 smoothStoneWallThin: 40,
84 brickWall: 41,
85 brickWallThin: 42,
86 woodWall: 43,
87 woodWallThin: 44,
88 cliff: 45,
89 cliffThin: 46
90});
91
92export const GROUND_DEFINITIONS = Object.freeze({
93 [GroundType.grass]: Object.freeze({
94 id: GroundType.grass,
95 key: "grass",
96 displayName: "Grass",
97 passable: true,
98 wades: false,
99 water: false,
100 frames: 1,
101 framesPerRow: 1,
102 animationSpeed: 0,
103 /** Outdoor grounds should expose summer/fall/winter (legacy `grass` ok for summer). */
104 outdoor: true,
105 /** Soft-terrain edge blend when the player enables Soft terrain. */
106 blendable: true
107 }),
108 [GroundType.wood]: Object.freeze({
109 id: GroundType.wood,
110 key: "wood",
111 displayName: "Wood",
112 passable: true,
113 wades: false,
114 water: false,
115 frames: 1,
116 framesPerRow: 1,
117 animationSpeed: 0,
118 outdoor: false
119 }),
120 [GroundType.water]: Object.freeze({
121 id: GroundType.water,
122 key: "water",
123 displayName: "Water",
124 passable: true,
125 wades: true,
126 water: true,
127 frames: 4,
128 framesPerRow: 4,
129 animationSpeed: 0.12,
130 outdoor: true
131 }),
132 [GroundType.deepWater]: Object.freeze({
133 id: GroundType.deepWater,
134 key: "deep-water",
135 displayName: "Deep water",
136 passable: false,
137 wades: false,
138 water: true,
139 frames: 4,
140 framesPerRow: 4,
141 animationSpeed: 0.12,
142 outdoor: true
143 }),
144 [GroundType.dirt]: Object.freeze({
145 id: GroundType.dirt,
146 key: "dirt",
147 displayName: "Dirt",
148 passable: true,
149 wades: false,
150 water: false,
151 frames: 1,
152 framesPerRow: 1,
153 animationSpeed: 0,
154 outdoor: true,
155 blendable: true
156 })
157});
158
159function treeBlockDef (id, woodTier)
160{
161 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
162 return Object.freeze({
163 id,
164 key: `${woodTier}-tree`,
165 displayName: `${name} tree`,
166 passable: false,
167 /** Canopy: light passes but each tree tile adds +1 falloff distance. */
168 blocksLight: "partial",
169 lightRangeTiles: 0,
170 frames: 1,
171 framesPerRow: 1,
172 animationSpeed: 0,
173 outdoor: true,
174 gatherable: true,
175 woodTier
176 });
177}
178
179export const BLOCK_DEFINITIONS = Object.freeze({
180 [BlockType.stoneWall]: Object.freeze({
181 id: BlockType.stoneWall,
182 key: "thick-stone-wall",
183 displayName: "Thick stone wall",
184 passable: false,
185 lightRangeTiles: 0,
186 frames: 1,
187 framesPerRow: 1,
188 animationSpeed: 0,
189 /** Building walls count as indoor (no seasonal art required). */
190 outdoor: false,
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.smoothStoneWallThin]: Object.freeze({
209 id: BlockType.smoothStoneWallThin,
210 key: "thin-smooth-stone-wall",
211 displayName: "Thin 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.brickWall]: Object.freeze({
222 id: BlockType.brickWall,
223 key: "thick-brick-wall",
224 displayName: "Thick brick 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.brickWallThin]: Object.freeze({
235 id: BlockType.brickWallThin,
236 key: "thin-brick-wall",
237 displayName: "Thin 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.woodWall]: Object.freeze({
248 id: BlockType.woodWall,
249 key: "thick-wood-wall",
250 displayName: "Thick wood wall",
251 passable: false,
252 lightRangeTiles: 0,
253 frames: 1,
254 framesPerRow: 1,
255 animationSpeed: 0,
256 outdoor: false,
257 /** Magenta face-lit masks `0`–`15`; catalog expands `${wood}-${mask}`. */
258 neighborConnect: true,
259 neighborConnectByMaterial: true,
260 defaultNeighborMaterial: WoodTier.pine
261 }),
262 [BlockType.woodWallThin]: Object.freeze({
263 id: BlockType.woodWallThin,
264 key: "thin-wood-wall",
265 displayName: "Thin wood wall",
266 passable: false,
267 lightRangeTiles: 0,
268 frames: 1,
269 framesPerRow: 1,
270 animationSpeed: 0,
271 outdoor: false,
272 neighborConnect: true,
273 neighborConnectByMaterial: true,
274 defaultNeighborMaterial: WoodTier.pine
275 }),
276 [BlockType.cliff]: Object.freeze({
277 id: BlockType.cliff,
278 key: "thick-cliff",
279 displayName: "Thick cliff",
280 passable: false,
281 lightRangeTiles: 0,
282 frames: 1,
283 framesPerRow: 1,
284 animationSpeed: 0,
285 outdoor: true,
286 neighborConnect: true,
287 neighborConnectNamed: true,
288 /**
289 * Magenta top faces are replaced at draw time by a dedicated per-tile
290 * cliff shader that samples the chunk ground atlas (1:1 UV, soft-terrain
291 * blend included). These blocks are not baked into chunk atlas rows.
292 */
293 cliffGroundTop: true
294 }),
295 [BlockType.cliffThin]: Object.freeze({
296 id: BlockType.cliffThin,
297 key: "thin-cliff",
298 displayName: "Thin cliff",
299 passable: false,
300 lightRangeTiles: 0,
301 frames: 1,
302 framesPerRow: 1,
303 animationSpeed: 0,
304 outdoor: true,
305 neighborConnect: true,
306 neighborConnectNamed: true,
307 /** @see {@link BlockType.cliff} `cliffGroundTop` */
308 cliffGroundTop: true
309 }),
310 [BlockType.torch]: Object.freeze({
311 id: BlockType.torch,
312 key: "torch",
313 displayName: "Torch",
314 passable: true,
315 lightRangeTiles: 8,
316 frames: 1,
317 framesPerRow: 1,
318 animationSpeed: 0,
319 outdoor: false
320 }),
321 [BlockType.spawner]: Object.freeze({
322 id: BlockType.spawner,
323 key: "spawner",
324 displayName: "Spawner",
325 passable: true,
326 lightRangeTiles: 0,
327 frames: 1,
328 framesPerRow: 1,
329 animationSpeed: 0,
330 /** Not shown in the placeable block palette; use the Spawners tab. */
331 editorHidden: true,
332 outdoor: false
333 }),
334 [BlockType.bank]: Object.freeze({
335 id: BlockType.bank,
336 key: "bank",
337 displayName: "Bank",
338 passable: false,
339 lightRangeTiles: 0,
340 frames: 1,
341 framesPerRow: 1,
342 animationSpeed: 0,
343 outdoor: false
344 }),
345 [BlockType.churchAltar]: Object.freeze({
346 id: BlockType.churchAltar,
347 key: "church-altar",
348 displayName: "Church altar",
349 passable: false,
350 lightRangeTiles: 0,
351 frames: 1,
352 framesPerRow: 1,
353 animationSpeed: 0,
354 outdoor: false
355 }),
356 [BlockType.cauldron]: Object.freeze({
357 id: BlockType.cauldron,
358 key: "cauldron",
359 displayName: "Cauldron",
360 passable: false,
361 blocksLight: false,
362 lightRangeTiles: 0,
363 frames: 1,
364 framesPerRow: 1,
365 animationSpeed: 0,
366 outdoor: false
367 }),
368 [BlockType.boulder]: Object.freeze({
369 id: BlockType.boulder,
370 key: "boulder",
371 displayName: "Boulder",
372 passable: false,
373 blocksLight: false,
374 lightRangeTiles: 0,
375 frames: 1,
376 framesPerRow: 1,
377 animationSpeed: 0,
378 /** Ore states are synthesized in the sprite catalog (tinted boulder-ore). */
379 gatherable: true,
380 outdoor: true
381 }),
382 [BlockType.furnace]: Object.freeze({
383 id: BlockType.furnace,
384 key: "furnace",
385 displayName: "Furnace",
386 passable: false,
387 blocksLight: false,
388 lightRangeTiles: 4,
389 frames: 1,
390 framesPerRow: 1,
391 animationSpeed: 0,
392 craftingStationId: "furnace",
393 outdoor: false
394 }),
395 [BlockType.campfire]: Object.freeze({
396 id: BlockType.campfire,
397 key: "campfire",
398 displayName: "Campfire",
399 passable: true,
400 blocksLight: false,
401 blocksRangedAttacks: false,
402 lightRangeTiles: 4,
403 frames: 1,
404 framesPerRow: 1,
405 animationSpeed: 0,
406 craftingStationId: "fireplace",
407 /** State is wood tier id; tinted like logs. Bloom companion is fire only. */
408 tintFromTier: true,
409 /** Lit/expires at runtime — per-tile draw, not chunk atlas (see chunk-delta). */
410 perTileBlock: true,
411 outdoor: true
412 }),
413 [BlockType.oven]: Object.freeze({
414 id: BlockType.oven,
415 key: "oven",
416 displayName: "Oven",
417 passable: false,
418 blocksLight: false,
419 lightRangeTiles: 2,
420 frames: 1,
421 framesPerRow: 1,
422 animationSpeed: 0,
423 craftingStationId: "oven",
424 outdoor: false
425 }),
426 [BlockType.fishingSpot]: Object.freeze({
427 id: BlockType.fishingSpot,
428 key: "fishing-spot",
429 displayName: "Fishing spot",
430 passable: true,
431 blocksLight: false,
432 blocksRangedAttacks: false,
433 lightRangeTiles: 0,
434 /** Ripple / splash strip (temp art; 3 frames). */
435 frames: 3,
436 framesPerRow: 3,
437 animationSpeed: 0.18,
438 outdoor: true,
439 /** Requires water / deepWater under the tile (editor + server). */
440 requiresWater: true
441 }),
442 [BlockType.anvil]: Object.freeze({
443 id: BlockType.anvil,
444 key: "anvil",
445 displayName: "Anvil",
446 passable: false,
447 blocksLight: false,
448 lightRangeTiles: 0,
449 frames: 1,
450 framesPerRow: 1,
451 animationSpeed: 0,
452 craftingStationId: "anvil",
453 outdoor: false
454 }),
455 [BlockType.jeweleringStation]: Object.freeze({
456 id: BlockType.jeweleringStation,
457 key: "jewelering-station",
458 displayName: "Jewelering station",
459 passable: false,
460 blocksLight: false,
461 lightRangeTiles: 0,
462 frames: 1,
463 framesPerRow: 1,
464 animationSpeed: 0,
465 craftingStationId: "jewelering-station",
466 outdoor: false
467 }),
468 [BlockType.woodworkingBench]: Object.freeze({
469 id: BlockType.woodworkingBench,
470 key: "woodworking-bench",
471 displayName: "Woodworking bench",
472 passable: false,
473 blocksLight: false,
474 lightRangeTiles: 0,
475 frames: 1,
476 framesPerRow: 1,
477 animationSpeed: 0,
478 craftingStationId: "woodworking-bench",
479 outdoor: false
480 }),
481 [BlockType.craftingBench]: Object.freeze({
482 id: BlockType.craftingBench,
483 key: "crafting-bench",
484 displayName: "Crafting bench",
485 passable: false,
486 blocksLight: false,
487 lightRangeTiles: 0,
488 frames: 1,
489 framesPerRow: 1,
490 animationSpeed: 0,
491 craftingStationId: "crafting-bench",
492 outdoor: false
493 }),
494 [BlockType.pineTree]: treeBlockDef(BlockType.pineTree, WoodTier.pine),
495 [BlockType.birchTree]: treeBlockDef(BlockType.birchTree, WoodTier.birch),
496 [BlockType.oakTree]: treeBlockDef(BlockType.oakTree, WoodTier.oak),
497 [BlockType.ebonyTree]: treeBlockDef(BlockType.ebonyTree, WoodTier.ebony),
498 [BlockType.lignumTree]: treeBlockDef(BlockType.lignumTree, WoodTier.lignum),
499 [BlockType.heartwoodTree]: treeBlockDef(BlockType.heartwoodTree, WoodTier.heartwood),
500 [BlockType.elderTree]: treeBlockDef(BlockType.elderTree, WoodTier.elder),
501 [BlockType.marketplace]: Object.freeze({
502 id: BlockType.marketplace,
503 key: "marketplace",
504 displayName: "Central Exchange counter",
505 passable: false,
506 /** Furniture: blocks movement but not baked/dynamic light rays. */
507 blocksLight: false,
508 lightRangeTiles: 0,
509 frames: 1,
510 framesPerRow: 1,
511 animationSpeed: 0,
512 outdoor: false,
513 /** Autotile via N/E/S/W bitmask states `"0"`…`"15"`. */
514 neighborConnect: true
515 }),
516 [BlockType.table]: Object.freeze({
517 id: BlockType.table,
518 key: "table",
519 displayName: "Table",
520 passable: false,
521 blocksLight: false,
522 blocksRangedAttacks: false,
523 lightRangeTiles: 0,
524 frames: 1,
525 framesPerRow: 1,
526 animationSpeed: 0,
527 outdoor: false,
528 /** Magenta base `0`–`15` (strip-union line tables); catalog expands `${wood}-${mask}`.
529 * Filled-rectangle corners can later add diagonal-aware sprites without replacing these. */
530 neighborConnect: true,
531 neighborConnectByMaterial: true,
532 defaultNeighborMaterial: WoodTier.pine
533 }),
534 [BlockType.fence]: Object.freeze({
535 id: BlockType.fence,
536 key: "fence",
537 displayName: "Fence",
538 passable: false,
539 blocksLight: false,
540 blocksRangedAttacks: false,
541 lightRangeTiles: 0,
542 frames: 1,
543 framesPerRow: 1,
544 animationSpeed: 0,
545 outdoor: true,
546 /** Magenta base `0`–`15`; catalog expands `${wood}-${mask}` like tables. */
547 neighborConnect: true,
548 neighborConnectByMaterial: true,
549 defaultNeighborMaterial: WoodTier.pine
550 }),
551 [BlockType.flower]: Object.freeze({
552 id: BlockType.flower,
553 key: "flower",
554 displayName: "Flower",
555 passable: true,
556 blocksLight: false,
557 lightRangeTiles: 0,
558 frames: 1,
559 framesPerRow: 1,
560 animationSpeed: 0,
561 outdoor: true,
562 gatherable: true,
563 plantGather: Object.freeze({ kind: "flower", requiresClippers: false, skillId: "herbalism" })
564 }),
565 [BlockType.cottonPlant]: Object.freeze({
566 id: BlockType.cottonPlant,
567 key: "cotton-plant",
568 displayName: "Cotton plant",
569 passable: true,
570 blocksLight: false,
571 lightRangeTiles: 0,
572 frames: 1,
573 framesPerRow: 1,
574 animationSpeed: 0,
575 outdoor: true,
576 gatherable: true,
577 plantGather: Object.freeze({ kind: "cotton", requiresClippers: false, skillId: "herbalism" })
578 }),
579 [BlockType.flaxPlant]: Object.freeze({
580 id: BlockType.flaxPlant,
581 key: "flax-plant",
582 displayName: "Flax plant",
583 passable: true,
584 blocksLight: false,
585 lightRangeTiles: 0,
586 frames: 1,
587 framesPerRow: 1,
588 animationSpeed: 0,
589 outdoor: true,
590 gatherable: true,
591 plantGather: Object.freeze({
592 kind: "flax",
593 requiresClippers: true,
594 /** Linen-rank clippers or better (steel↔linen). */
595 minClothTier: "linen",
596 skillId: "herbalism"
597 })
598 }),
599 [BlockType.silkCocoon]: Object.freeze({
600 id: BlockType.silkCocoon,
601 key: "silk-cocoon",
602 displayName: "Silk cocoon",
603 passable: true,
604 blocksLight: false,
605 lightRangeTiles: 0,
606 frames: 1,
607 framesPerRow: 1,
608 animationSpeed: 0,
609 outdoor: true,
610 gatherable: true,
611 plantGather: Object.freeze({
612 kind: "silk",
613 requiresClippers: true,
614 /** Silk-rank clippers or better (adamantium↔silk). */
615 minClothTier: "silk",
616 skillId: "herbalism"
617 })
618 }),
619 [BlockType.spinningWheel]: Object.freeze({
620 id: BlockType.spinningWheel,
621 key: "spinning-wheel",
622 displayName: "Spinning wheel",
623 passable: false,
624 blocksLight: false,
625 lightRangeTiles: 0,
626 frames: 1,
627 framesPerRow: 1,
628 animationSpeed: 0,
629 craftingStationId: "spinning-wheel",
630 outdoor: false
631 }),
632 [BlockType.loom]: Object.freeze({
633 id: BlockType.loom,
634 key: "loom",
635 displayName: "Loom",
636 passable: false,
637 blocksLight: false,
638 lightRangeTiles: 0,
639 frames: 1,
640 framesPerRow: 1,
641 animationSpeed: 0,
642 craftingStationId: "loom",
643 outdoor: false
644 }),
645 [BlockType.tailorBench]: Object.freeze({
646 id: BlockType.tailorBench,
647 key: "tailor-bench",
648 displayName: "Tailor's bench",
649 passable: false,
650 blocksLight: false,
651 lightRangeTiles: 0,
652 frames: 1,
653 framesPerRow: 1,
654 animationSpeed: 0,
655 craftingStationId: "tailor-bench",
656 outdoor: false
657 }),
658 [BlockType.leatherworkingTable]: Object.freeze({
659 id: BlockType.leatherworkingTable,
660 key: "leatherworking-table",
661 displayName: "Leatherworking table",
662 passable: false,
663 blocksLight: false,
664 lightRangeTiles: 0,
665 frames: 1,
666 framesPerRow: 1,
667 animationSpeed: 0,
668 craftingStationId: "leatherworking-station",
669 outdoor: false
670 }),
671 [BlockType.bountyOffice]: Object.freeze({
672 id: BlockType.bountyOffice,
673 key: "bounty-office",
674 displayName: "Bounty office",
675 passable: false,
676 blocksLight: false,
677 lightRangeTiles: 0,
678 frames: 1,
679 framesPerRow: 1,
680 animationSpeed: 0,
681 outdoor: false
682 }),
683 [BlockType.barber]: Object.freeze({
684 id: BlockType.barber,
685 key: "barber",
686 displayName: "Barber",
687 passable: false,
688 blocksLight: false,
689 lightRangeTiles: 0,
690 frames: 1,
691 framesPerRow: 1,
692 animationSpeed: 0,
693 outdoor: false
694 }),
695 [BlockType.doorway]: Object.freeze({
696 id: BlockType.doorway,
697 key: "doorway",
698 displayName: "Doorway",
699 passable: true,
700 blocksLight: false,
701 lightRangeTiles: 0,
702 frames: 1,
703 framesPerRow: 1,
704 animationSpeed: 0,
705 outdoor: false,
706 /** Visual variants under `blocks/doorway/`. */
707 doorway: true,
708 defaultState: "door"
709 }),
710 [BlockType.herbPlant]: Object.freeze({
711 id: BlockType.herbPlant,
712 key: "herb",
713 displayName: "Herb",
714 passable: true,
715 blocksLight: false,
716 lightRangeTiles: 0,
717 frames: 1,
718 framesPerRow: 1,
719 animationSpeed: 0,
720 outdoor: true,
721 gatherable: true,
722 /** Sprites live under `assets/herbs/` (shared with items), not `blocks/herb/`. */
723 assetFolder: "herbs",
724 plantGather: Object.freeze({
725 kind: "herb",
726 requiresClippers: true,
727 skillId: "herbalism"
728 })
729 })
730});
731
732/** Grounds and real blocks the editor may place (excludes legacy/hidden entries). */
733export function listPlaceableGrounds ()
734{
735 return Object.values(GROUND_DEFINITIONS);
736}
737
738export function listPlaceableBlocks ()
739{
740 return Object.values(BLOCK_DEFINITIONS).filter((def) => !def.editorHidden);
741}
742
743/** Display name for an ore boulder state (`copper-ore` → "Copper ore boulder"). */
744export function oreBoulderDisplayName (state)
745{
746 const material = materialFromOreBoulderState(state);
747 if (!material)
748 { return null; }
749 const label = MATERIAL_DISPLAY_NAME[material] ?? material;
750 if (material === "coal")
751 { return "Coal boulder"; }
752 if (isGemstoneMaterial(material))
753 { return `${label} boulder`; }
754 return `${label} ore boulder`;
755}
756
757/**
758 * Hover / UI label for a gatherable resource node.
759 * Ore boulders and chopable trees; fishing / herbs can extend this later.
760 * Returns null when the block is not an active resource node.
761 */
762export function resourceNodeDisplayName (block)
763{
764 if (!block)
765 { return null; }
766 if (block.typeId === BlockType.fishingSpot && block.state !== "exhausted")
767 { return "Fishing spot"; }
768 if (block.typeId === BlockType.boulder)
769 { return oreBoulderDisplayName(block.state); }
770 if (isChopableTreeBlock(block))
771 {
772 const def = BLOCK_DEFINITIONS[block.typeId];
773 return def?.displayName ?? "Tree";
774 }
775 if (block.typeId === BlockType.flower)
776 {
777 const color = FLOWER_COLOR_DISPLAY[block.state];
778 return color ? `${color} flower` : "Flower";
779 }
780 if (block.typeId === BlockType.cottonPlant)
781 { return "Cotton plant"; }
782 if (block.typeId === BlockType.flaxPlant)
783 { return "Flax plant"; }
784 if (block.typeId === BlockType.silkCocoon)
785 { return "Silk cocoon"; }
786 if (block.typeId === BlockType.herbPlant)
787 {
788 const herb = herbDefinition(block.state);
789 return herb ? herb.displayName : "Herb";
790 }
791 return null;
792}
793
794/** Wood tier for a tree block type, or null. */
795export function woodTierForTreeBlock (typeId)
796{
797 const def = BLOCK_DEFINITIONS[typeId];
798 return def?.woodTier ?? null;
799}
800
801/** True when this block is a standing (non-stump) gatherable tree. */
802export function isChopableTreeBlock (block)
803{
804 if (!block || woodTierForTreeBlock(block.typeId) == null)
805 { return false; }
806 return !isSeasonalStumpState(block.state);
807}
808
809/** Plant gather config from block def, or null. */
810export function plantGatherForBlock (block)
811{
812 if (!block)
813 { return null; }
814 const def = BLOCK_DEFINITIONS[block.typeId];
815 return def?.plantGather ?? null;
816}
817
818export function isPickablePlantBlock (block)
819{
820 return !!plantGatherForBlock(block);
821}
822
823/**
824 * Blocks baked into chunk atlas rows. Gather nodes and pickables stay as per-tile
825 * sprites so chunkDelta can hide or restyle them without rebaking the row.
826 */
827export function isChunkAtlasBakedBlock (block)
828{
829 if (!block)
830 { return false; }
831 const entry = normalizeBlock(block);
832 if (!entry)
833 { return false; }
834 const def = BLOCK_DEFINITIONS[entry.typeId];
835 if (!def || def.editorHidden)
836 { return false; }
837 if (def.perTileBlock)
838 { return false; }
839 /** Cliff tops need a dedicated per-tile ground-sample shader, not the row atlas. */
840 if (def.cliffGroundTop)
841 { return false; }
842 if (resourceNodeDisplayName(entry))
843 { return false; }
844 if (isPickablePlantBlock(entry))
845 { return false; }
846 return true;
847}
848
849/**
850 * Editor palette cards: one entry per placeable, with boulder expanded into
851 * plain rock + each ore/coal variant (shared BlockType, distinct state).
852 * Flowers are a single card; colour is rolled when painting (and on respawn).
853 */
854export function listPlaceableBlockPaletteEntries (catalog = null)
855{
856 const entries = [];
857 for (const def of listPlaceableBlocks())
858 {
859 if (def.id === BlockType.boulder)
860 {
861 entries.push({
862 typeId: def.id,
863 state: "boulder",
864 key: def.key,
865 displayName: "Boulder",
866 spriteName: spriteImageName("block", def.key, "boulder")
867 });
868 for (const material of ORE_BEARING_MATERIALS)
869 {
870 const state = oreBoulderState(material);
871 entries.push({
872 typeId: def.id,
873 state,
874 key: def.key,
875 displayName: oreBoulderDisplayName(state) ?? state,
876 spriteName: spriteImageName("block", def.key, state)
877 });
878 }
879 continue;
880 }
881 if (def.id === BlockType.flower)
882 {
883 const state = flowerBlockState(FLOWER_COLOR_ORDER[0]);
884 entries.push({
885 typeId: def.id,
886 state,
887 key: def.key,
888 displayName: "Flower",
889 spriteName: spriteImageName("block", def.key, state)
890 });
891 continue;
892 }
893 if (def.id === BlockType.herbPlant)
894 {
895 for (const herbId of HERB_ORDER)
896 {
897 const herb = HERB_DEFINITIONS[herbId];
898 entries.push({
899 typeId: def.id,
900 state: herbId,
901 key: def.key,
902 displayName: herb?.displayName ?? herbId,
903 spriteName: spriteImageName("block", def.key, herbId)
904 });
905 }
906 continue;
907 }
908 if (def.neighborConnect)
909 {
910 if (definitionUsesMaterialNeighborConnect(def))
911 {
912 for (const material of WOOD_TIER_ORDER)
913 {
914 const state = composeNeighborConnectState(def, material, 0);
915 const label = MATERIAL_DISPLAY_NAME[material] ?? material;
916 const noun = String(def.displayName ?? def.key).toLowerCase();
917 entries.push({
918 typeId: def.id,
919 state,
920 key: def.key,
921 displayName: `${label} ${noun}`,
922 spriteName: spriteImageName("block", def.key, state)
923 });
924 }
925 continue;
926 }
927 entries.push({
928 typeId: def.id,
929 state: definitionUsesNamedNeighborConnect(def) ? def.key : "0",
930 key: def.key,
931 displayName: def.displayName,
932 spriteName: spriteImageName(
933 "block",
934 def.key,
935 definitionUsesNamedNeighborConnect(def) ? def.key : "0"
936 )
937 });
938 continue;
939 }
940 const state = defaultStateForType(catalog, "block", def.key);
941 entries.push({
942 typeId: def.id,
943 state,
944 key: def.key,
945 displayName: def.displayName,
946 spriteName: state
947 ? spriteImageName("block", def.key, state)
948 : spriteImageName("block", def.key, def.key)
949 });
950 }
951 return entries;
952}
953
954export function groundDefinition (typeId)
955{
956 return GROUND_DEFINITIONS[typeId] ?? null;
957}
958
959export function blockDefinition (typeId)
960{
961 return BLOCK_DEFINITIONS[typeId] ?? null;
962}
963
964export function isGroundPassable (typeId)
965{
966 const def = groundDefinition(typeId);
967 if (!def)
968 { return true; }
969 return def.passable !== false;
970}
971
972export function isWaterGround (typeId)
973{
974 return !!groundDefinition(typeId)?.water;
975}
976
977export function isWadeGround (typeId)
978{
979 return !!groundDefinition(typeId)?.wades;
980}
981
982/**
983 * Liquid water for foam / wade (shallow water freezes in winter and is solid ice).
984 * Deep water stays liquid year-round.
985 */
986export function isLiquidWaterGround (typeId, seasonId = null)
987{
988 if (!isWaterGround(typeId))
989 { return false; }
990 if (typeId === GroundType.water && seasonId === SeasonId.winter)
991 { return false; }
992 return true;
993}
994
995/** Wade clip/foam only on liquid shallow water (not winter ice). */
996export function isWadeGroundInSeason (typeId, seasonId = null)
997{
998 return isWadeGround(typeId) && isLiquidWaterGround(typeId, seasonId);
999}
1000
1001export function isBlockPassable (typeId)
1002{
1003 if (typeId == null)
1004 { return true; }
1005
1006 const def = blockDefinition(typeId);
1007 return def ? def.passable : false;
1008}
1009
1010/**
1011 * Whether a block stops ranged attack / spell line of sight.
1012 * `blocksRangedAttacks`: explicit override; `craftingStationId` defaults to clear;
1013 * otherwise impassable blocks block and passable blocks do not.
1014 */
1015export function blockBlocksRangedAttacks (typeId)
1016{
1017 if (typeId == null)
1018 { return false; }
1019 const def = blockDefinition(typeId);
1020 if (!def)
1021 { return true; }
1022 if (def.blocksRangedAttacks === false)
1023 { return false; }
1024 if (def.blocksRangedAttacks === true)
1025 { return true; }
1026 if (def.craftingStationId)
1027 { return false; }
1028 return def.passable === false;
1029}
1030
1031/**
1032 * Light ray occlusion for a block tile.
1033 * - `clear` (0): no effect (default for passable; set `blocksLight: false` for furniture)
1034 * - `partial` (1): ray continues; each such tile adds +1 to falloff distance (2× cost)
1035 * - `solid` (2): ray stops (default for impassable; set `blocksLight: true` explicitly)
1036 */
1037export const LightOcclusion = Object.freeze({
1038 clear: 0,
1039 partial: 1,
1040 solid: 2
1041});
1042
1043/**
1044 * Resolve light occlusion for a block tile (type + visual state).
1045 * Stumps are a runtime/editor state override: no occlusion even on tree types.
1046 */
1047export function blockLightOcclusionForBlock (block)
1048{
1049 if (!block)
1050 { return LightOcclusion.clear; }
1051 if (isSeasonalStumpState(block.state))
1052 { return LightOcclusion.clear; }
1053 return blockLightOcclusion(block.typeId ?? null);
1054}
1055
1056/**
1057 * Resolve light occlusion for a block type id.
1058 * `blocksLight`: `true` | `false` | `"partial"`; omitted → solid iff `!passable`.
1059 * `blocksRangedAttacks`: `true` | `false`; omitted → false when `craftingStationId` is set,
1060 * otherwise blocks iff `!passable` (furniture/stations may block movement but not magic/ranged).
1061 * Prefer {@link blockLightOcclusionForBlock} when block state is known.
1062 */
1063export function blockLightOcclusion (typeId)
1064{
1065 if (typeId == null)
1066 { return LightOcclusion.clear; }
1067 const def = blockDefinition(typeId);
1068 if (!def)
1069 { return LightOcclusion.solid; }
1070 if (def.blocksLight === "partial")
1071 { return LightOcclusion.partial; }
1072 if (def.blocksLight === false)
1073 { return LightOcclusion.clear; }
1074 if (def.blocksLight === true)
1075 { return LightOcclusion.solid; }
1076 return def.passable === false ? LightOcclusion.solid : LightOcclusion.clear;
1077}
1078
1079/** True when a block fully stops light rays (not partial canopy). */
1080export function isBlockOccludingLight (typeId)
1081{
1082 return blockLightOcclusion(typeId) === LightOcclusion.solid;
1083}
1084
1085export function blockLightRange (typeId)
1086{
1087 const def = blockDefinition(typeId);
1088 return def ? def.lightRangeTiles : 0;
1089}
1090
1091export function normalizeGround (value, fallbackTypeId = GroundType.grass)
1092{
1093 if (typeof value === "number")
1094 { return { typeId: value, state: null }; }
1095 if (value && Number.isInteger(value.typeId))
1096 { return { typeId: value.typeId, state: value.state ?? null }; }
1097 return { typeId: fallbackTypeId, state: null };
1098}
1099
1100export function normalizeBlock (value)
1101{
1102 if (!value || !Number.isInteger(value.typeId))
1103 { return null; }
1104 let state = value.state ?? null;
1105 const def = BLOCK_DEFINITIONS[value.typeId];
1106 if (def && definitionUsesNamedNeighborConnect(def) && state != null)
1107 {
1108 const mask = parseNeighborConnectMaskFromState(state, def);
1109 state = composeNeighborConnectState(def, state, mask);
1110 }
1111 return { typeId: value.typeId, state, config: value.config ?? null };
1112}
1113
1114export function setBlockVisualState (block, state)
1115{
1116 if (!block)
1117 { return null; }
1118 block.state = state ?? null;
1119 return block;
1120}