BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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