aboutsummaryrefslogtreecommitdiff
path: root/content-system/registry/registry.ts
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-04-22 14:32:03 +0530
committerBobby <[email protected]>2026-04-22 14:32:03 +0530
commitbbe9d34700995ba1644d726743dbb61144052bd1 (patch)
treebee0455edb7023d08b348022672ec2c294f2579c /content-system/registry/registry.ts
parent87f4e51a2804d0788c8cd1fcde56923d19d0e06c (diff)
downloadhollowdark-main.tar.xz
hollowdark-main.zip
Load the content manifest and cache every chunk to IndexedDB on initial loadHEADmain
Diffstat (limited to 'content-system/registry/registry.ts')
-rw-r--r--content-system/registry/registry.ts14
1 files changed, 12 insertions, 2 deletions
diff --git a/content-system/registry/registry.ts b/content-system/registry/registry.ts
index 38f0a91..6910cab 100644
--- a/content-system/registry/registry.ts
+++ b/content-system/registry/registry.ts
@@ -62,18 +62,26 @@ export class ContentRegistry {
}
}
+/** Per-chunk callback used to advance a progress bar as loading proceeds. */
+export type ChunkProgressCallback = (loaded: number, total: number) => void
+
/**
* Populate a fresh registry from the supplied manifest. Fetches every
* chunk whose id begins with a world-content prefix; ignores unknown
* prefixes so the registry can grow without breaking older clients.
+ * Chunks load in parallel; the callback reports completion order, not
+ * start order.
*/
export async function populateFromManifest(
manifest: ContentManifest,
- baseUrl: string
+ baseUrl: string,
+ onProgress?: ChunkProgressCallback
): Promise<ContentRegistry> {
const registry = new ContentRegistry()
-
const entries = Object.entries(manifest.chunks)
+ const total = entries.length
+ let loaded = 0
+
await Promise.all(
entries.map(async ([chunkId]) => {
const { data } = await loadChunk(chunkId, manifest, baseUrl)
@@ -84,6 +92,8 @@ export async function populateFromManifest(
} else if (chunkId.startsWith('world/institutions/')) {
registry.addInstitution(data as unknown as InstitutionContent)
}
+ loaded += 1
+ onProgress?.(loaded, total)
})
)