The Assets services is how you access loaded assets, and query if an asset is loaded.
The primary use for this at the moment is the accessors like Assets.image, and finding out
if an asset is loaded via Assets.has_image.
Note that the asset system is a work in progress and is not final.
There are several accessors missing, for example, fonts are often referenced
as a string, not via Assets.font("fonts/name"). Later, all assets will be unified into this form as intended.
Also, they’re supposed to be able to reload dynamically, many can’t currently. And remember the input
to the asset system is compiled assets, not the assets themselves.
Finally, there are functions in the API that shouldn’t be used directly (they aren’t listed here.)
Create a new asset DB.
This is usually internal stuff.
Also used internally in "luxe: project" for ProjectAssets which has additional functions for making the DB useful for common usecases.
Add a root path for files that the asset database considers.
In a normal project this is the project folder and all module folders.
note: this usually happens internally without you needing to worry about it.
Get the db asset info for an asset by its asset id.
!in this context the “asset ID” is the local path from the project or module root (with the module prefix if in a module), including extensions!
Assets.modified(db : AssetDB, query_id : String) : List
Get all modified asset files in the db.
The query id is used for having different systems be able to have different modified states.
The query id can also be changed to make sure assets are seen as not handled yet when an asset handler has a new version.
This function returns a list of DB entries as maps. the AssetID helper class can hold these infos in a wren type.
Get the modified asset files in the DB with a specific extension/subtype (like .subtype.ext). Asset flow uses this internally to get which assets to recompile.
Mark an asset as not modified/dirty anymore (in the context of one query), this usually happens when an asset was handled/compiled successfully and doesn’t need to be touched again until the file changes.
Mark an asset file as modified. This can be useful if one asset is dependent on a bunch of other assets in a folder (like entities in scenes, the entities mark the scene as modified when the entity changes.).
Returns the data stored as bytes.
A Wren String is also a byte sequence, used via string.bytes.
Note That unlike other assets, bytes are stored by name with extension.
For example if you put a file called data/hello.txt in your project,
you would access it via var data = Assets.bytes("data/hello.txt").
This is because the extension might be meaningful to the user of the bytes,
for example loading an image based on png vs jpg extension would be impossible
if we don’t know the extension of the data. Because bytes are “opaque”, as in,
we don’t care what they store, we just store them for you to access, we keep the extension.
var text = Assets.bytes("data/hello.txt")
Log.print(text) //prints the contents of the file (the contents at compile time).
Returns the LX parsed representation of a bytes asset.
This is convenience for Assets.bytes followed by LX.parse.
Returns null if the asset isn’t found, or if parsing failed.
See Assets.bytes, as bytes require an extension.
//assuming our data contains { speaker="sara" message="follow me." }
When dealing with data like assets, storing a string directly can take up a lot of space.
Instead, what we can do is store the strings once, in a shared place, and then reference that string later.
At runtime, strings can also be more expensive than is ideal (like needing to iterate the characters individually, or taking up more memory).
In both cases, what we store instead of a string is a string id, which is just a number.
Comparing two numbers, looking up numbers in an array or map and so on, it’s much faster with a number than using
the string itself. Operating on numbers is both faster and simpler, and has a fixed size in memory.
This is commonly called “string interning”.
In luxe, the Strings class is how you interact with the strings available to your game.
For example, var name_id = Entity.get_name(entity) will return a string id, not a string.
To get the string, you can use var name = Strings.get(name_id).
Note that if the name is unknown to Strings, it will return null, so handle that appropriately.
To add a string, use Strings.add("string").
For debugging strings, if you look inside .luxe/luxe.strings.lx,
this lists all the strings your assets reference, and what their key is.