feat(@projects/@magic-civilization): add sprite detection utilities for new asset types

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-04-18 02:22:23 -07:00
parent 7bd416a416
commit 00197982b7

View file

@ -24,6 +24,26 @@ interface BuildingEntry {
sprite?: string
}
interface ItemEntry {
id?: string
sprite?: string
}
interface DepositEntry {
id?: string
sprite?: string
}
interface FaunaEntry {
id?: string
sprite?: string
}
interface WonderEntry {
id?: string
sprite?: string
}
/** Strip a leading `audio/` or `sprites/` segment so expected paths align with
* the layout under `public/games/age-of-dwarves/assets/`. */
function normaliseAssetPath(raw: string): string {
@ -73,6 +93,41 @@ export function collectExpectedBuildingSpritePaths(buildingFiles: BuildingEntry[
return Array.from(paths).sort()
}
/** Single-entry-per-file shape (items, deposits, fauna species). Each JSON
* is one object with an optional `sprite` path. */
function collectSinglePerFile(files: ReadonlyArray<{ sprite?: string }>): string[] {
const paths = new Set<string>()
for (const entry of files) {
if (entry?.sprite) paths.add(normaliseAssetPath(entry.sprite))
}
return Array.from(paths).sort()
}
export function collectExpectedItemSpritePaths(itemFiles: ItemEntry[]): string[] {
return collectSinglePerFile(itemFiles)
}
export function collectExpectedResourceSpritePaths(depositFiles: DepositEntry[]): string[] {
return collectSinglePerFile(depositFiles)
}
export function collectExpectedFaunaSpritePaths(faunaFiles: FaunaEntry[]): string[] {
return collectSinglePerFile(faunaFiles)
}
/** Mundane wonders live as a single JSON array of building-shaped entries
* (`data/buildings/mundane_wonders.json`). Same shape as unit/building
* arrays-of-arrays passed elsewhere, but with exactly one outer file. */
export function collectExpectedWonderSpritePaths(wonderFiles: WonderEntry[][]): string[] {
const paths = new Set<string>()
for (const arr of wonderFiles) {
for (const w of arr) {
if (w.sprite) paths.add(normaliseAssetPath(w.sprite))
}
}
return Array.from(paths).sort()
}
/** Given a set of expected asset paths and a set of present asset paths
* (as returned by `import.meta.glob` keys, already normalised), compute a
* per-item presence record. `presentPaths` should contain the same relative