AssetPlugin

View source

ExtendsPlugin

Adds typed asset storage and optional lifecycle events to an App.

Register one instance for each asset constructor the app should manage. The plugin provides a typed Assets pool for that asset family and connects the pool to the app’s AssetServer resource.

The optional events option accepts the three constructors in AssetEvents and provides typed Events resources for asset-added, asset-modified, and asset-dropped values. Without events, no lifecycle event resources are provided.

AssetPlugin does not create the AssetServer; register AssetServerPlugin, or provide a compatible server resource yourself.

Examples

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

class Texture {}

new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new AssetServerPlugin())
  .registerPlugin(new AssetPlugin({ asset: Texture }))
  .setRunner(() => {})
  .run()

Constructor


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

View source

Creates runtime support for one asset constructor.

The options are stored until the app invokes register. Supply the complete events object to expose typed added, modified, and dropped lifecycle events for this asset family.

Type Parameters

T

Parameters

NameDescriptionDefault
options

Asset constructor and optional lifecycle event constructors.

—

Properties


readonlyasset: Constructor<T>

View source

Asset constructor identifying the family managed by this plugin.

It specializes the plugin’s typed Assets pool and identifies the asset constructor used by the plugin’s generic identity. Registering another AssetPlugin for the same constructor produces the same plugin ID and is rejected by the app.

readonlyevents: AssetEvents<T>

View source

Optional constructors for the asset family’s lifecycle event resources.

When present, register exposes typed Events resources for asset-added, asset-modified, and asset-dropped values. All three constructors are required together; when omitted, the plugin does not create lifecycle event resources.

Methods


register(app: App): void

View source

Adds the configured typed asset pool and optional lifecycle event resources to an app.

The plugin creates an Assets pool for the configured asset constructor and makes it available through the app’s typed resource store. The pool connects to the app’s AssetServer so server-managed assets can use the typed pool.

If events is configured, the plugin creates typed Events resources for added, modified, and dropped values. Lifecycle events from the pool are exposed through those resources, and dropped asset metadata is removed from the server.

An AssetServer resource must be available to the app. Register AssetServerPlugin, or provide that resource yourself, in addition to this plugin. This plugin does not install an asset importer or exporter.

Examples

import { App } from '@wimaengine/app'
import { AssetAdded, AssetDropped, AssetModified, AssetPlugin, AssetServerPlugin } from '@wimaengine/asset'
import { CorePlugin } from '@wimaengine/core'
import { ReflectPlugin } from '@wimaengine/reflect'

class Texture {}

new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new AssetServerPlugin())
  .registerPlugin(new AssetPlugin({
    asset: Texture,
    events: { added: AssetAdded, modified: AssetModified, dropped: AssetDropped }
  }))
  .setRunner(() => {})
  .run()
// The plugin stages Assets<Texture> and the three typed event resources.

Parameters

NameDescriptionDefault
app

App receiving the asset pool and lifecycle integration.

—

requires(): TypeId[]

View source

Returns the plugin type IDs required by this asset support.

The IDs identify CorePlugin and ReflectPlugin as direct dependencies. The app validates these dependencies but does not install them automatically. AssetServerPlugin is not included because the required AssetServer resource may be supplied by another plugin or directly by the app.

Returns

Required plugin TypeId values.

name(): TypeId

View source

Returns the generic plugin identity for this asset constructor.

The returned TypeId is derived from AssetPlugin and the configured asset constructor. The app can therefore register one plugin for each asset constructor while rejecting duplicate registration for the same constructor.

Returns

Generic plugin TypeId.