BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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