BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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