export const GroundType = Object.freeze({ grass: 1, wood: 2 }); export const BlockType = Object.freeze({ stoneWall: 1, torch: 2, spawner: 3, bank: 4 }); export const GROUND_DEFINITIONS = Object.freeze({ [GroundType.grass]: Object.freeze({ id: GroundType.grass, key: "grass", displayName: "Grass", frames: 1, framesPerRow: 1, animationSpeed: 0 }), [GroundType.wood]: Object.freeze({ id: GroundType.wood, key: "wood", displayName: "Wood", frames: 1, framesPerRow: 1, animationSpeed: 0 }) }); export const BLOCK_DEFINITIONS = Object.freeze({ [BlockType.stoneWall]: Object.freeze({ id: BlockType.stoneWall, key: "stone-wall", displayName: "Stone wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0 }), [BlockType.torch]: Object.freeze({ id: BlockType.torch, key: "torch", displayName: "Torch", passable: true, lightRangeTiles: 8, frames: 1, framesPerRow: 1, animationSpeed: 0 }), [BlockType.spawner]: Object.freeze({ id: BlockType.spawner, key: "spawner", displayName: "Spawner", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0 }), [BlockType.bank]: Object.freeze({ id: BlockType.bank, key: "bank", displayName: "Bank", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0 }) }); export function groundDefinition (typeId) { return GROUND_DEFINITIONS[typeId] ?? null; } export function blockDefinition (typeId) { return BLOCK_DEFINITIONS[typeId] ?? null; } export function isBlockPassable (typeId) { if (typeId == null) { return true; } const def = blockDefinition(typeId); return def ? def.passable : false; } export function blockLightRange (typeId) { const def = blockDefinition(typeId); return def ? def.lightRangeTiles : 0; } export function normalizeGround (value, fallbackTypeId = GroundType.grass) { if (typeof value === "number") { return { typeId: value, state: null }; } if (value && Number.isInteger(value.typeId)) { return { typeId: value.typeId, state: value.state ?? null }; } return { typeId: fallbackTypeId, state: null }; } export function normalizeBlock (value) { if (!value || !Number.isInteger(value.typeId)) { return null; } return { typeId: value.typeId, state: value.state ?? null, config: value.config ?? null }; } export function setBlockVisualState (block, state) { if (!block) { return null; } block.state = state ?? null; return block; }