BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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