AssetExporterPlugin

View source

ExtendsPlugin

Registers one typed Exporter with an app’s AssetServer.

Supply the same asset constructor in both plugin options and Exporter#asset. The AssetServer uses that constructor and the labels from Exporter#getExtensions to select an exporter for matching save requests. Include AssetServerPlugin and CorePlugin in the app when using this plugin.

Examples

import { App } from '@wimaengine/app'
import { AssetExporterPlugin, AssetServerPlugin, Exporter } from '@wimaengine/asset'
import { CorePlugin } from '@wimaengine/core'
import { ReflectPlugin } from '@wimaengine/reflect'

class TextAsset {
  constructor(value) {
    this.value = value
  }
}

class TextExporter extends Exporter {
  constructor() {
    super(TextAsset)
  }

  async serialize(asset, _typeRegistry) {
    return JSON.stringify(asset)
  }

  getExtensions() {
    return ['json']
  }
}

new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new AssetServerPlugin())
  .registerPlugin(new AssetExporterPlugin({
    asset: TextAsset,
    exporter: new TextExporter()
  }))
  .setRunner(() => {})
  .run()
// The asset server can use TextExporter for TextAsset values and `json` paths.

Constructor


constructor<T>(options: AssetExporterPluginOptions<T>)

View source

Creates a plugin that registers one exporter for one asset type.

The typed asset and exporter values are stored unchanged. Pass matching values so the plugin identity and Exporter#asset describe the same asset type.

Type Parameters

T

Parameters

NameDescriptionDefault
options

Asset constructor and matching exporter.

—

Properties


readonlyasset: Constructor<T>

View source

Asset constructor paired with this plugin’s exporter.

Pass the same constructor stored in Exporter#asset. The AssetServer uses the exporter’s constructor and extensions when selecting a save handler.

Methods


requires(): TypeId[]

View source

Returns the plugins required by this exporter plugin.

This plugin requires CorePlugin and AssetServerPlugin. The app validates these dependencies; it does not install them automatically.

Returns

Required plugin TypeId values.

name(): TypeId

View source

Returns this plugin’s identity for its asset constructor.

Different asset constructors receive different identities, so an app can register one exporter plugin per asset type. A second plugin for the same constructor has the same identity and is rejected by the app.

Returns

Plugin TypeId.