Module asset
+Asset manager.
+Loads asset and cache them.
+ +This only provides a streamlined way to handle asset, and doesn’t handle the actual file loading/object creation itself; you are expected to provide your own asset loaders.
+ +See the Asset:__call method for more details on how assets are loaded. Hopefully this will allow you to use asset which are more game-specific than “image” or “audio”.
+ +No dependencies.
+ + +Functions
+| new (directory, loaders[, mode="auto"]) | +Create a new asset manager. | +
Asset objects
+| Asset.prefix | +A prefix for asset names. | +
| Asset.cache | +The asset cache. | +
| Asset.loaders | +The loaders table. | +
| Asset:__call (assetName, ...) | +Load (and cache) an asset. | +
| Asset:load (list) | +Preload a list of assets. | +
| Asset:clear () | +Allow loaded assets to be garbage collected. | +
+
+ + +
Functions
+ +-
+
- + + new (directory, loaders[, mode="auto"]) + +
-
+ Create a new asset manager.
+
+
If the caching “mode” is set to auto (default), the asset manager will allow assets to be automaticaly garbage collected by Lua.
+ +If set to “manual”, the assets will not be garbage collected unless the clear method is called. + “manual” mode is useful if you have assets that are particularly slow to load and you want full control on when they are loaded and unloaded (typically a loading screen). + + + + + + +
Parameters:
+-
+
- directory + string + the directory in which the assets will be loaded + +
- loaders + table + loaders table: {prefix = function, …} + +
- mode + string + caching mode + (default "auto") + +
Returns:
+-
+
+ Asset
+ the new asset manager
+
+
Asset objects
+ +-
+
- + + Asset.prefix + +
-
+ A prefix for asset names.
+
+
+
Type:
+-
+
string+
+ - + + Asset.cache + +
-
+ The asset cache. Each cached asset is indexed with a string key “type.assetName”.
+
+
+
Type:
+-
+
table{["assetName"]=asset} +
+ - + + Asset.loaders + +
-
+ The loaders table.
+
+
+
Type:
+-
+
table{["prefix"]=function, ...} +
+ - + + Asset:__call (assetName, ...) + +
-
+
Load (and cache) an asset.
+ +Asset name are similar to Lua module names (directory separator is the dot . and no extention should be specified). + To load an asset, ubiquitousse will try every loaders in the loader list with a name that prefix the asset name. + The first value returned will be used as the asset value.
+ +Loaders are called with the arguments:
+ +-
+
- path: the asset full path, except extension +
- …: other arguments given after the asset name. Can only be number and strings. +
Parameters:
+-
+
- assetName + string + string the asset’s full name + +
- ... + number/string + other arguments for the asset loader + +
Returns:
+-
+
+ the asset
+
Usage:
+-
+
local image = asset("image.example")
+ + +
+ - + + Asset:load (list) + +
-
+ Preload a list of assets.
+
+
+
+
+
+
+
Parameters:
+-
+
- list + {"asset1",...} + list of assets to load + +
+ - + + Asset:clear () + +
- + Allow loaded assets to be garbage collected. + Only useful if the caching mode is set to “manual” duritng creation. + + + + + + + + + + + + +