BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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