BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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