BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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