assets
Asset definitions by reference: a project path, file#entry for one entry, #id for a scene block, or id://<id> from assets/index.toml. A script gets the…
On this page
Asset definitions by reference: a project path, file#entry for one entry, #id for a scene block, or id://<id> from assets/index.toml. A script gets the definition table.
9 functions, 0 constants. Scripts reach it as assets::.
Functions
Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.
| function | acts on | what it does |
|---|---|---|
directory(string) -> string |
— | The project-relative directory files of an asset type belong in; empty when the type is unknown or declared none. |
exists(string) -> bool |
— | Whether a reference resolves to a definition that is really there; false rather than an error when it does not. |
invalidate() |
— | Declare everything derived from project files stale (a shader a material links, say) so it is rebuilt from disk; for a file the watcher does not cover. A script hears this and every reload with events::listen(this.node, "assets_reloaded"), as on_assets_reloaded(generation). |
kind_of(string) -> string |
— | Which importer kind a file is by its extension — texture, audio, font or model — or empty for one none claims. A .ttf, .otf, .ttc or .fnt is a font. |
load(string) -> any |
— | The definition table behind a reference, from the cache: the script's own copy, so editing it disturbs no other holder. An error when the reference resolves to nothing; reload first for a fresh read of the file. |
reload(string) |
— | Forget a reference so the next load re-reads its file, along with every entry cut from that same file. |
rename(string, string) -> [str] |
— | Move a file or directory and rewrite every reference to it in the project's .toml files, comments kept; answers the files rewritten. Paths as fs.* takes them, so an editor refactors the game it has open by absolute path. Script sources are not rewritten: a path in a .bs is the script's own value, and id:// is the reference that survives a move. |
save(string, any) |
— | Write a definition table to the project-relative file a reference names; an error unless it names a whole file. |
schema(string) -> any |
— | The properties a record asset type holds, in the order it writes them; nil for a type that is not a record. |