updateAssetEvents

View sourceupdateAssetEvents<T>(assetType: Constructor<T>, eventType: AssetEvents<T>): SystemFunc

Creates a system that forwards one typed asset pool’s queued lifecycle events to typed Events resources.

The factory captures assetType and the three constructors in eventType and uses them to compute these resource IDs: typeidGeneric(Assets, [assetType]), typeidGeneric(Events, [eventType.added]), typeidGeneric(Events, [eventType.modified]), and typeidGeneric(Events, [eventType.dropped]). The factory does not look up resources or run a system until the returned function receives a World. The event constructors identify the typed Events resources; routing uses the AssetAdded, AssetModified, and AssetDropped lifecycle base classes produced by Assets.

Each invocation gets all four resources with World#getResourceByTypeId, so a missing typed resource throws. It then calls Assets#flushEvents, which returns the queued batch in mutation order and starts a fresh queue when that batch is non-empty. Added, modified, and dropped values are written to their matching Events resource. Writing makes them pending; they become readable when the event resource is cleared. Any other event value is discarded after warnOnce logs that its constructor is not handled.

When AssetPlugin receives an events option, it creates the typed event resources and registers this system in the repeating AppSchedule.Update schedule’s CoreSystems.End group. Releases processed during the same update can produce an AssetDropped value for this flush. The nested EventPlugin instances provide the event resources and automatic buffer clearing. For manual setup, stage those same resources under the IDs above and register the returned system in the corresponding Update/End phase.

Examples

import { App } from '@wimaengine/app'
import { AssetAdded, AssetDropped, AssetModified, AssetPlugin, updateAssetEvents } from '@wimaengine/asset'

class Texture {}
const events = {
  added: AssetAdded,
  modified: AssetModified,
  dropped: AssetDropped
}

const system = updateAssetEvents(Texture, events)
const app = new App()
app.registerPlugin(new AssetPlugin({ asset: Texture, events }))
// AssetPlugin creates an equivalent system and places it in
// AppSchedule.Update/CoreSystems.End.

Type Parameters

T

Parameters

NameDescriptionDefault
assetType

Constructor identifying the typed asset pool and its Assets<T> resource ID.

—
eventType

Constructors identifying the typed Events resources for added, modified, and dropped lifecycle values.

—

Throws

If the returned system cannot find the typed asset or event resource in its world.

Returns

System that accepts a World, flushes the asset pool, and writes recognized lifecycle values to typed event resources.