BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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