Importers

View source

Registry that selects Importer instances by asset type ID and exact extension label.

Each importer is indexed under its Importer#asset constructor and every exact label returned by Importer#getExtensions. Registering another importer for the same type-and-extension pair warns and selects the newer importer for later lookups by AssetServer.

Examples

import { Importer, Importers } from '@wimaengine/asset'
import { typeid } from '@wimaengine/type'

class Texture {}
class PngImporter extends Importer {
  constructor() { super(Texture) }
  getExtensions() { return ['png'] }
}

const registry = new Importers()
const importer = new PngImporter()
registry.add(importer)
registry.get(typeid(Texture), 'png') // importer

Constructor


constructor()

Methods


add<T>(importer: Importer<T>): void

View source

Registers an importer for its asset type and each extension label it declares.

If the same type-and-extension pair is already registered, this warns and makes the new importer the result of subsequent lookups.

Type Parameters

T

Parameters

NameDescriptionDefault
importer

Importer to register for its asset type and supported extensions.

—

get<T>(type: TypeId, extension: string): Importer<T>

View source

Returns an importer selected by an exact asset type ID and extension label.

The extension must match a label supplied to Importers#add, including its spelling and case. A leading dot is not removed and the label is not otherwise normalized. Path-based lookups use AssetServer#getImporter.

Type Parameters

T

Parameters

NameDescriptionDefault
type

Runtime ID of the importer’s asset type.

—
extension

Exact indexed extension label.

—

Throws

The given extension does not have an importer registered when the extension is unknown.

The given asset type does not support the given extension when the type is not indexed for the extension.

If the selected importer cannot be returned.

Returns

The importer selected for the pair.