pixi.js
    Preparing search index...

    Interface LoaderParser<ASSET, META_DATA, CONFIG>Advanced

    The interface to define a loader parser (all functions are optional).

    When you create a parser object, the flow for every asset loaded is:

    1. parser.test() - Each URL to load will be tested here, if the test is passed the assets are loaded using the load function below. Good place to test for things like file extensions!
    2. parser.load() - This is the promise that loads the URL provided resolves with a loaded asset if returned by the parser.
    3. parser.testParse() - This function is used to test if the parse function should be run on the asset If this returns true then parse is called with the asset
    4. parse.parse() - Gets called on the asset it testParse passes. Useful to convert a raw asset into something more useful

    Some loaders may only be used for parsing, some only for loading, and some for both!
    interface LoaderParser<
        ASSET = any,
        META_DATA = any,
        CONFIG = Record<string, any>,
    > {
        config?: CONFIG;
        extension?: ExtensionMetadata;
        load?: <T>(
            url: string,
            resolvedAsset?: ResolvedAsset<META_DATA>,
            loader?: Loader,
        ) => Promise<ASSET | T>;
        name: string;
        parse?: <T>(
            asset: ASSET,
            resolvedAsset?: ResolvedAsset<META_DATA>,
            loader?: Loader,
        ) => Promise<ASSET | T>;
        test?: (
            url: string,
            resolvedAsset?: ResolvedAsset<META_DATA>,
            loader?: Loader,
        ) => boolean;
        testParse?: (
            asset: ASSET,
            resolvedAsset?: ResolvedAsset<META_DATA>,
            loader?: Loader,
        ) => Promise<boolean>;
        unload?: (
            asset: ASSET,
            resolvedAsset?: ResolvedAsset<META_DATA>,
            loader?: Loader,
        ) => void | Promise<void>;
    }

    Type Parameters

    • ASSET = any
    • META_DATA = any
    • CONFIG = Record<string, any>

    Hierarchy (View Summary)

    Index

    Properties

    config?: CONFIG

    A config to adjust the parser

    extension?: ExtensionMetadata

    Should be ExtensionType.LoaderParser

    load?: <T>(
        url: string,
        resolvedAsset?: ResolvedAsset<META_DATA>,
        loader?: Loader,
    ) => Promise<ASSET | T>

    This is the promise that loads the URL provided resolves with a loaded asset if returned by the parser.

    Type declaration

    name: string

    The name of the parser (this can be used when specifying loadParser in a ResolvedAsset)

    parse?: <T>(
        asset: ASSET,
        resolvedAsset?: ResolvedAsset<META_DATA>,
        loader?: Loader,
    ) => Promise<ASSET | T>

    Gets called on the asset it testParse passes. Useful to convert a raw asset into something more useful

    Type declaration

    test?: (
        url: string,
        resolvedAsset?: ResolvedAsset<META_DATA>,
        loader?: Loader,
    ) => boolean

    Each URL to load will be tested here, if the test is passed the assets are loaded using the load function below. Good place to test for things like file extensions!

    Type declaration

      • (
            url: string,
            resolvedAsset?: ResolvedAsset<META_DATA>,
            loader?: Loader,
        ): boolean
      • Parameters

        • url: string

          The URL to test

        • OptionalresolvedAsset: ResolvedAsset<META_DATA>

          Any custom additional information relevant to the asset being loaded

        • Optionalloader: Loader

          The loader instance

        Returns boolean

    testParse?: (
        asset: ASSET,
        resolvedAsset?: ResolvedAsset<META_DATA>,
        loader?: Loader,
    ) => Promise<boolean>

    This function is used to test if the parse function should be run on the asset If this returns true then parse is called with the asset

    Type declaration

    unload?: (
        asset: ASSET,
        resolvedAsset?: ResolvedAsset<META_DATA>,
        loader?: Loader,
    ) => void | Promise<void>

    If an asset is parsed using this parser, the unload function will be called when the user requests an asset to be unloaded. This is useful for things like sounds or textures that can be unloaded from memory

    Type declaration