BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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