BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

tiles.js 29.0 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 blocksLight: false,
740 lightRangeTiles: 0,
741 frames: 1,
742 framesPerRow: 1,
743 animationSpeed: 0,
744 outdoor: false,
745 /** Wooden door — not a dimension portal (`doorway`). */
746 door: true,
747 tintFromTier: true,
748 perTileBlock: true,
749 defaultState: "pine-s-closed"
750 }),
751 [BlockType.herbPlant]: Object.freeze({
752 id: BlockType.herbPlant,
753 key: "herb",
754 displayName: "Herb",
755 passable: true,
756 blocksLight: false,
757 lightRangeTiles: 0,
758 frames: 1,
759 framesPerRow: 1,
760 animationSpeed: 0,
761 outdoor: true,
762 gatherable: true,
763 /** Sprites live under `assets/herbs/` (shared with items), not `blocks/herb/`. */
764 assetFolder: "herbs",
765 plantGather: Object.freeze({
766 kind: "herb",
767 requiresClippers: true,
768 skillId: "herbalism"
769 })
770 })
771});
772
773/** Grounds and real blocks the editor may place (excludes legacy/hidden entries). */
774export function listPlaceableGrounds ()
775{
776 return Object.values(GROUND_DEFINITIONS);
777}
778
779export function listPlaceableBlocks ()
780{
781 return Object.values(BLOCK_DEFINITIONS).filter((def) => !def.editorHidden);
782}
783
784/** Display name for an ore boulder state (`copper-ore` → "Copper ore boulder"). */
785export function oreBoulderDisplayName (state)
786{
787 const material = materialFromOreBoulderState(state);
788 if (!material)
789 { return null; }
790 const label = MATERIAL_DISPLAY_NAME[material] ?? material;
791 if (material === "coal")
792 { return "Coal boulder"; }
793 if (isGemstoneMaterial(material))
794 { return `${label} boulder`; }
795 return `${label} ore boulder`;
796}
797
798/**
799 * Hover / UI label for a gatherable resource node.
800 * Ore boulders and chopable trees; fishing / herbs can extend this later.
801 * Returns null when the block is not an active resource node.
802 */
803export function resourceNodeDisplayName (block)
804{
805 if (!block)
806 { return null; }
807 if (block.typeId === BlockType.fishingSpot && block.state !== "exhausted")
808 { return "Fishing spot"; }
809 if (block.typeId === BlockType.boulder)
810 { return oreBoulderDisplayName(block.state); }
811 if (isChopableTreeBlock(block))
812 {
813 const def = BLOCK_DEFINITIONS[block.typeId];
814 return def?.displayName ?? "Tree";
815 }
816 if (block.typeId === BlockType.flower)
817 {
818 const color = FLOWER_COLOR_DISPLAY[block.state];
819 return color ? `${color} flower` : "Flower";
820 }
821 if (block.typeId === BlockType.cottonPlant)
822 { return "Cotton plant"; }
823 if (block.typeId === BlockType.flaxPlant)
824 { return "Flax plant"; }
825 if (block.typeId === BlockType.silkCocoon)
826 { return "Silk cocoon"; }
827 if (block.typeId === BlockType.herbPlant)
828 {
829 const herb = herbDefinition(block.state);
830 return herb ? herb.displayName : "Herb";
831 }
832 return null;
833}
834
835/** Wood tier for a tree block type, or null. */
836export function woodTierForTreeBlock (typeId)
837{
838 const def = BLOCK_DEFINITIONS[typeId];
839 return def?.woodTier ?? null;
840}
841
842/** True when this block is a standing (non-stump) gatherable tree. */
843export function isChopableTreeBlock (block)
844{
845 if (!block || woodTierForTreeBlock(block.typeId) == null)
846 { return false; }
847 return !isSeasonalStumpState(block.state);
848}
849
850/** Plant gather config from block def, or null. */
851export function plantGatherForBlock (block)
852{
853 if (!block)
854 { return null; }
855 const def = BLOCK_DEFINITIONS[block.typeId];
856 return def?.plantGather ?? null;
857}
858
859export function isPickablePlantBlock (block)
860{
861 return !!plantGatherForBlock(block);
862}
863
864/**
865 * Blocks baked into chunk atlas rows. Gather nodes and pickables stay as per-tile
866 * sprites so chunkDelta can hide or restyle them without rebaking the row.
867 */
868export function isChunkAtlasBakedBlock (block)
869{
870 if (!block)
871 { return false; }
872 const entry = normalizeBlock(block);
873 if (!entry)
874 { return false; }
875 const def = BLOCK_DEFINITIONS[entry.typeId];
876 if (!def || def.editorHidden)
877 { return false; }
878 if (def.perTileBlock)
879 { return false; }
880 /** Cliff tops need a dedicated per-tile ground-sample shader, not the row atlas. */
881 if (def.cliffGroundTop)
882 { return false; }
883 if (resourceNodeDisplayName(entry))
884 { return false; }
885 if (isPickablePlantBlock(entry))
886 { return false; }
887 return true;
888}
889
890/**
891 * Editor palette cards: one entry per placeable, with boulder expanded into
892 * plain rock + each ore/coal variant (shared BlockType, distinct state).
893 * Flowers are a single card; colour is rolled when painting (and on respawn).
894 */
895export function listPlaceableBlockPaletteEntries (catalog = null)
896{
897 const entries = [];
898 for (const def of listPlaceableBlocks())
899 {
900 if (def.id === BlockType.boulder)
901 {
902 entries.push({
903 typeId: def.id,
904 state: "boulder",
905 key: def.key,
906 displayName: "Boulder",
907 spriteName: spriteImageName("block", def.key, "boulder")
908 });
909 for (const material of ORE_BEARING_MATERIALS)
910 {
911 const state = oreBoulderState(material);
912 entries.push({
913 typeId: def.id,
914 state,
915 key: def.key,
916 displayName: oreBoulderDisplayName(state) ?? state,
917 spriteName: spriteImageName("block", def.key, state)
918 });
919 }
920 continue;
921 }
922 if (def.id === BlockType.flower)
923 {
924 const state = flowerBlockState(FLOWER_COLOR_ORDER[0]);
925 entries.push({
926 typeId: def.id,
927 state,
928 key: def.key,
929 displayName: "Flower",
930 spriteName: spriteImageName("block", def.key, state)
931 });
932 continue;
933 }
934 if (def.id === BlockType.herbPlant)
935 {
936 for (const herbId of HERB_ORDER)
937 {
938 const herb = HERB_DEFINITIONS[herbId];
939 entries.push({
940 typeId: def.id,
941 state: herbId,
942 key: def.key,
943 displayName: herb?.displayName ?? herbId,
944 spriteName: spriteImageName("block", def.key, herbId)
945 });
946 }
947 continue;
948 }
949 if (def.door)
950 {
951 for (const material of WOOD_TIER_ORDER)
952 {
953 const state = composeDoorState(material, "s", false);
954 entries.push({
955 typeId: def.id,
956 state,
957 key: def.key,
958 displayName: doorPaletteDisplayName(state).replace(/ \(S closed\)$/u, ""),
959 spriteName: spriteImageName("block", def.key, state)
960 });
961 }
962 continue;
963 }
964 if (def.neighborConnect)
965 {
966 if (definitionUsesMaterialNeighborConnect(def))
967 {
968 for (const material of WOOD_TIER_ORDER)
969 {
970 const state = composeNeighborConnectState(def, material, 0);
971 const label = MATERIAL_DISPLAY_NAME[material] ?? material;
972 const noun = String(def.displayName ?? def.key).toLowerCase();
973 entries.push({
974 typeId: def.id,
975 state,
976 key: def.key,
977 displayName: `${label} ${noun}`,
978 spriteName: spriteImageName("block", def.key, state)
979 });
980 }
981 continue;
982 }
983 entries.push({
984 typeId: def.id,
985 state: definitionUsesNamedNeighborConnect(def) ? def.key : "0",
986 key: def.key,
987 displayName: def.displayName,
988 spriteName: spriteImageName(
989 "block",
990 def.key,
991 definitionUsesNamedNeighborConnect(def) ? def.key : "0"
992 )
993 });
994 continue;
995 }
996 const state = defaultStateForType(catalog, "block", def.key);
997 entries.push({
998 typeId: def.id,
999 state,
1000 key: def.key,
1001 displayName: def.displayName,
1002 spriteName: state
1003 ? spriteImageName("block", def.key, state)
1004 : spriteImageName("block", def.key, def.key)
1005 });
1006 }
1007 return entries;
1008}
1009
1010export function groundDefinition (typeId)
1011{
1012 return GROUND_DEFINITIONS[typeId] ?? null;
1013}
1014
1015export function blockDefinition (typeId)
1016{
1017 return BLOCK_DEFINITIONS[typeId] ?? null;
1018}
1019
1020export function isGroundPassable (typeId)
1021{
1022 const def = groundDefinition(typeId);
1023 if (!def)
1024 { return true; }
1025 return def.passable !== false;
1026}
1027
1028export function isWaterGround (typeId)
1029{
1030 return !!groundDefinition(typeId)?.water;
1031}
1032
1033export function isWadeGround (typeId)
1034{
1035 return !!groundDefinition(typeId)?.wades;
1036}
1037
1038/**
1039 * Liquid water for foam / wade (shallow water freezes in winter and is solid ice).
1040 * Deep water stays liquid year-round.
1041 */
1042export function isLiquidWaterGround (typeId, seasonId = null)
1043{
1044 if (!isWaterGround(typeId))
1045 { return false; }
1046 if (typeId === GroundType.water && seasonId === SeasonId.winter)
1047 { return false; }
1048 return true;
1049}
1050
1051/** Wade clip/foam only on liquid shallow water (not winter ice). */
1052export function isWadeGroundInSeason (typeId, seasonId = null)
1053{
1054 return isWadeGround(typeId) && isLiquidWaterGround(typeId, seasonId);
1055}
1056
1057export function isBlockPassable (typeId, state = null)
1058{
1059 if (typeId == null)
1060 { return true; }
1061
1062 const def = blockDefinition(typeId);
1063 if (!def)
1064 { return false; }
1065 if (def.door)
1066 { return isDoorOpenState(state); }
1067 return def.passable;
1068}
1069
1070/**
1071 * Whether a block stops ranged attack / spell line of sight.
1072 * `blocksRangedAttacks`: explicit override; `craftingStationId` defaults to clear;
1073 * otherwise impassable blocks block and passable blocks do not.
1074 */
1075export function blockBlocksRangedAttacks (typeId, state = null)
1076{
1077 if (typeId == null)
1078 { return false; }
1079 const def = blockDefinition(typeId);
1080 if (!def)
1081 { return true; }
1082 if (def.door)
1083 { return !isDoorOpenState(state); }
1084 if (def.blocksRangedAttacks === false)
1085 { return false; }
1086 if (def.blocksRangedAttacks === true)
1087 { return true; }
1088 if (def.craftingStationId)
1089 { return false; }
1090 return def.passable === false;
1091}
1092
1093/**
1094 * Light ray occlusion for a block tile.
1095 * - `clear` (0): no effect (default for passable; set `blocksLight: false` for furniture)
1096 * - `partial` (1): ray continues; each such tile adds +1 to falloff distance (2× cost)
1097 * - `solid` (2): ray stops (default for impassable; set `blocksLight: true` explicitly)
1098 */
1099export const LightOcclusion = Object.freeze({
1100 clear: 0,
1101 partial: 1,
1102 solid: 2
1103});
1104
1105/**
1106 * Resolve light occlusion for a block tile (type + visual state).
1107 * Stumps are a runtime/editor state override: no occlusion even on tree types.
1108 */
1109export function blockLightOcclusionForBlock (block)
1110{
1111 if (!block)
1112 { return LightOcclusion.clear; }
1113 if (isSeasonalStumpState(block.state))
1114 { return LightOcclusion.clear; }
1115 return blockLightOcclusion(block.typeId ?? null);
1116}
1117
1118/**
1119 * Resolve light occlusion for a block type id.
1120 * `blocksLight`: `true` | `false` | `"partial"`; omitted → solid iff `!passable`.
1121 * `blocksRangedAttacks`: `true` | `false`; omitted → false when `craftingStationId` is set,
1122 * otherwise blocks iff `!passable` (furniture/stations may block movement but not magic/ranged).
1123 * Prefer {@link blockLightOcclusionForBlock} when block state is known.
1124 */
1125export function blockLightOcclusion (typeId)
1126{
1127 if (typeId == null)
1128 { return LightOcclusion.clear; }
1129 const def = blockDefinition(typeId);
1130 if (!def)
1131 { return LightOcclusion.solid; }
1132 if (def.blocksLight === "partial")
1133 { return LightOcclusion.partial; }
1134 if (def.blocksLight === false)
1135 { return LightOcclusion.clear; }
1136 if (def.blocksLight === true)
1137 { return LightOcclusion.solid; }
1138 return def.passable === false ? LightOcclusion.solid : LightOcclusion.clear;
1139}
1140
1141/** True when a block fully stops light rays (not partial canopy). */
1142export function isBlockOccludingLight (typeId)
1143{
1144 return blockLightOcclusion(typeId) === LightOcclusion.solid;
1145}
1146
1147export function blockLightRange (typeId)
1148{
1149 const def = blockDefinition(typeId);
1150 return def ? def.lightRangeTiles : 0;
1151}
1152
1153export function normalizeGround (value, fallbackTypeId = GroundType.grass)
1154{
1155 if (typeof value === "number")
1156 { return { typeId: value, state: null }; }
1157 if (value && Number.isInteger(value.typeId))
1158 { return { typeId: value.typeId, state: value.state ?? null }; }
1159 return { typeId: fallbackTypeId, state: null };
1160}
1161
1162export function normalizeBlock (value)
1163{
1164 if (!value || !Number.isInteger(value.typeId))
1165 { return null; }
1166 let state = value.state ?? null;
1167 const def = BLOCK_DEFINITIONS[value.typeId];
1168 if (def && definitionUsesNamedNeighborConnect(def) && state != null)
1169 {
1170 const mask = parseNeighborConnectMaskFromState(state, def);
1171 state = composeNeighborConnectState(def, state, mask);
1172 }
1173 return { typeId: value.typeId, state, config: value.config ?? null };
1174}
1175
1176export function setBlockVisualState (block, state)
1177{
1178 if (!block)
1179 { return null; }
1180 block.state = state ?? null;
1181 return block;
1182}