Skip to main content
Defined in: asset/src/asset-library.ts:24 Built-in asset library.

Remarks

Auto-registered by @nanoforge-dev/core — app code never calls app.use(new AssetLibrary()) directly. Stores the virtual file map injected by the NanoForge loader and exposes it via getAsset, always available on Context.assets. File paths are normalised on lookup: leading/duplicate slashes collapse to a single /, and a trailing slash is stripped.

Extends

  • Library

Constructors

Constructor

new AssetLibrary(relationships?): AssetLibrary
Defined in: common/dist/index.d.ts:510

Parameters

relationships?
Partial<LibraryRelationships> Optional ordering overrides, keyed by other libraries’ key.

Returns

AssetLibrary

Inherited from

Library.constructor

Properties

key

readonly key: "assets"
Defined in: asset/src/asset-library.ts:25 This library’s identity: its slot on Context, its registry key, and the identifier used to reference it in ordering relationships.

Overrides

Library.key

Accessors

relationships

Get Signature

get relationships(): LibraryRelationships
Defined in: common/dist/index.d.ts:512 Internal
Returns
LibraryRelationships

Inherited from

Library.relationships

Methods

__clear()

__clear(_ctx): Promise<void>
Defined in: common/dist/index.d.ts:525 Called once after the tick loop stops.

Parameters

_ctx
Context

Returns

Promise<void>

Inherited from

Library.__clear

__events()

__events(_ctx): Promise<void>
Defined in: common/dist/index.d.ts:521 Called every tick, in run order, whether or not the tick loop is paused — unlike __run. Use this for event/message draining that must not be affected by pause (e.g. listening for the command that resumes the loop), not for gameplay simulation.

Parameters

_ctx
Context

Returns

Promise<void>

Inherited from

Library.__events

__init()

__init(ctx): Promise<void>
Defined in: asset/src/asset-library.ts:29 Called once, in dependency order, before the tick loop starts.

Parameters

ctx
InitContext

Returns

Promise<void>

Overrides

Library.__init

__run()

__run(_ctx): Promise<void>
Defined in: common/dist/index.d.ts:523 Called every tick, in run order, while the tick loop is active and not paused.

Parameters

_ctx
Context

Returns

Promise<void>

Inherited from

Library.__run

expose()

expose(): AssetContext
Defined in: asset/src/asset-library.ts:52 Returns this library’s public contribution to Context[this.key].

Returns

AssetContext

Remarks

Return a plain object exposing only what game code should be able to reach — never this — so internal state and lifecycle hooks never leak onto Context. Libraries with nothing to expose (headless libraries) can leave this unimplemented; they simply won’t appear on Context.

Overrides

Library.expose

getAsset()

Call Signature

getAsset(path): NfFile
Defined in: asset/src/asset-library.ts:41 Retrieve a registered file asset by its virtual path.
Parameters
path
string Virtual path of the asset (e.g. “/textures/hero.png”).
Returns
NfFile An NfFile handle, or undefined if no path is given.
Throws
NfNotFound When no asset is registered at the given path.
Throws
NfNotInitializedException When called before __init resolves.

Call Signature

getAsset(path): undefined
Defined in: asset/src/asset-library.ts:42 Retrieve a registered file asset by its virtual path.
Parameters
path
"" | undefined Virtual path of the asset (e.g. “/textures/hero.png”).
Returns
undefined An NfFile handle, or undefined if no path is given.
Throws
NfNotFound When no asset is registered at the given path.
Throws
NfNotInitializedException When called before __init resolves.

throwNotInitializedError()

protected throwNotInitializedError(): never
Defined in: common/dist/index.d.ts:536

Returns

never

Inherited from

Library.throwNotInitializedError