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:
parent
7bd416a416
commit
00197982b7
1 changed files with 55 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue