Module technology.sola.engine
Package technology.sola.engine.assets
Class AssetHandle<T extends Asset>
java.lang.Object
technology.sola.engine.assets.AssetHandle<T>
- Type Parameters:
T
- the type of the asset
AssetHandle is a handle to an
Asset
that may or may not be loaded yet.-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty AssetHandle with an empty list of onLoadSubscribers.AssetHandle
(@Nullable T asset) Creates an AssetHandle instance with a preloadedAsset
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
executeIfLoaded
(Consumer<T> consumer) Executes the provided consumer synchronously if theAsset
for this handle has been loaded.void
executeWhenLoaded
(Consumer<T> consumer) Executes the provided consumer asynchronously once theAsset
for this handle has been loaded.@Nullable T
getAsset()
Gets the loadedAsset
immediately, but throws a runtime exception if it is not yet loaded.boolean
void
Sets the loadedAsset
for thisAssetHandle
.
-
Constructor Details
-
AssetHandle
public AssetHandle()Creates an empty AssetHandle with an empty list of onLoadSubscribers. Listeners will be notified whensetAsset(Asset)
is called with the loaded asset. -
AssetHandle
Creates an AssetHandle instance with a preloadedAsset
.- Parameters:
asset
- the preloaded asset
-
-
Method Details
-
isLoading
public boolean isLoading()- Returns:
- true if the
Asset
for this handle has not yet been loaded
-
getAsset
Gets the loadedAsset
immediately, but throws a runtime exception if it is not yet loaded.- Returns:
- the loaded asset
-
setAsset
Sets the loadedAsset
for thisAssetHandle
.- Parameters:
asset
- the loaded asset
-
executeWhenLoaded
Executes the provided consumer asynchronously once theAsset
for this handle has been loaded. This will execute immediately if the asset is already loaded.- Parameters:
consumer
- the function to execute if the asset is loaded
-
executeIfLoaded
Executes the provided consumer synchronously if theAsset
for this handle has been loaded. Otherwise, it does nothing.- Parameters:
consumer
- the function to execute if the asset is loaded
-