AssetPacks

class AssetPacks(source: PackSource, dispatcher: CoroutineDispatcher = Dispatchers.Default, markers: VerifiedMarkers = InMemoryVerifiedMarkers(), stallTimeoutMillis: Long = 0)(source)

The app's entry point: one shared fetch per pack, an integrity check against the pack's assetdropkit.json, and reads on dispatcher, never the caller's thread.

stallTimeoutMillis (0 = off) bounds a download whose state stops changing, as an offline download parked in Pending does: it is cancelled and the fetch returns Failed(NoNetwork).

Constructors

Link copied to clipboard
constructor(source: PackSource, dispatcher: CoroutineDispatcher = Dispatchers.Default, markers: VerifiedMarkers = InMemoryVerifiedMarkers(), stallTimeoutMillis: Long = 0)

Functions

Link copied to clipboard
suspend fun fetch(packId: String): PackState

Downloads the pack if needed and verifies it. Suspends until Ready, Failed, WaitingForWifi or NeedsPlayConfirmation, and returns a state rather than throwing. Callers fetching the same pack at once share one store request; the download is cancelled when every caller has been cancelled.

Link copied to clipboard
suspend fun readBytes(packId: String, path: String): ByteArray?

A file of a ready pack (path is inside the pack, as town/sedan.glb), or null.

Link copied to clipboard

Registers Play's dialogs; call from the activity's onCreate, before it starts.

Link copied to clipboard
suspend fun remove(packId: String)

Frees the pack's space and forgets its verification; the next fetch downloads and checks it again.

Link copied to clipboard
fun state(packId: String): Flow<PackState>

The pack's state; the first value is read from the store, never assumed. A store's Ready becomes Ready here only once the pack matches its manifest (otherwise Failed(Corrupt)), so a UI keyed on Ready never reads an unverified pack. The store is asked and the pack checked on dispatcher, so a collector on the main thread never waits on Play or the disk.