BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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