Exporters

View source

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

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

Examples

import { Exporter, Exporters } from '@wimaengine/asset'
import { typeid } from '@wimaengine/type'

class Texture {}
class PngExporter extends Exporter {
  constructor() { super(Texture) }
  getExtensions() { return ['png'] }
}

const registry = new Exporters()
const exporter = new PngExporter()
registry.add(exporter)
registry.get(typeid(Texture), 'png') // exporter

Constructor


constructor()

Methods


add<T>(exporter: Exporter<T>): void

View source

Registers an exporter 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 exporter the result of subsequent lookups.

Type Parameters

T

Parameters

NameDescriptionDefault
exporter

Exporter to register for its asset type and supported extensions.

—

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

View source

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

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

Type Parameters

T

Parameters

NameDescriptionDefault
type

Runtime ID of the exporter’s asset type.

—
extension

Exact indexed extension label.

—

Throws

The given extension does not have an exporter 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 exporter cannot be returned.

Returns

The exporter selected for the pair.