BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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