Files
dusk/types/asset/assetentry.d.ts
T
2026-06-02 09:32:07 -05:00

55 lines
1.6 KiB
TypeScript

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/**
* A live reference to an entry in the asset cache.
* Holds a lock that keeps the entry alive; the lock is released automatically
* when the object is garbage collected, or immediately via `unlock()`.
*/
interface AssetEntry {
/** Archive-relative path used as the cache key. */
readonly name: string;
/** Current loading state — compare against `AssetEntry.*` state constants. */
readonly state: number;
/** Loader type — one of the `AssetEntry.TYPE_*` constants. */
readonly type: number;
/** `true` when the entry has fully loaded (`state === AssetEntry.LOADED`). */
readonly isLoaded: boolean;
/**
* Returns a `Texture` for this entry when it is a loaded texture asset.
* The `Texture` holds its own asset lock — independent of this `AssetEntry`.
* Returns `undefined` if the entry is not of type `Asset.TYPE_TEXTURE` or
* is not yet loaded.
*/
readonly texture: Texture | undefined;
/**
* Blocks until the entry reaches `LOADED` (or `ERROR`).
* Returns `this` for chaining.
* @throws If the load fails.
*/
requireLoaded(): this;
/**
* Releases the lock immediately.
* After this call the object is invalid — do not use it again.
*/
unlock(): void;
toString(): string;
}
interface AssetEntryConstructor {
// Loading state constants
readonly NOT_STARTED: number;
readonly PENDING: number;
readonly LOADING: number;
readonly LOADED: number;
readonly ERROR: number;
new(): never;
}
declare var AssetEntry: AssetEntryConstructor;