BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

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