import { GROUND_DEFINITIONS, BLOCK_DEFINITIONS, GroundType, normalizeGround, normalizeBlock } from "/shared/definitions/tiles.js"; import { bloomImageName, resolveState, spriteImageName } from "/shared/definitions/tileSprites.js"; /** Resolve ground/block/bloom image names for one tile. */ export function resolveTileSprites ({ catalog, ground, block }) { return { ground: groundSpriteName(catalog, ground), groundBloom: groundBloomName(catalog, ground), block: blockSpriteName(catalog, block), blockBloom: blockBloomName(catalog, block) }; } function groundSpriteName (catalog, ground) { const entry = normalizeGround(ground); const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass]; const states = catalog.grounds?.[def.key]?.states ?? []; const state = resolveState(states, entry.state); return spriteImageName("ground", def.key, state); } function blockSpriteName (catalog, block) { const entry = normalizeBlock(block); if (!entry) { return null; } const def = BLOCK_DEFINITIONS[entry.typeId]; if (!def) { return null; } const states = catalog.blocks?.[def.key]?.states ?? []; const state = resolveState(states, entry.state); return spriteImageName("block", def.key, state); } function groundBloomName (catalog, ground) { const entry = normalizeGround(ground); const def = GROUND_DEFINITIONS[entry.typeId] ?? GROUND_DEFINITIONS[GroundType.grass]; const type = catalog.grounds?.[def.key]; const state = resolveState(type?.states ?? [], entry.state); if (!state || !type?.blooms?.[state]) { return null; } return bloomImageName("ground", def.key, state); } function blockBloomName (catalog, block) { const entry = normalizeBlock(block); if (!entry) { return null; } const def = BLOCK_DEFINITIONS[entry.typeId]; if (!def) { return null; } const type = catalog.blocks?.[def.key]; const state = resolveState(type?.states ?? [], entry.state); if (!state || !type?.blooms?.[state]) { return null; } return bloomImageName("block", def.key, state); }