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 TypeMethodDescriptionvoidexecuteIfLoaded(Consumer<T> consumer) Executes the provided consumer synchronously if theAssetfor this handle has been loaded.voidexecuteWhenLoaded(Consumer<T> consumer) Executes the provided consumer asynchronously once theAssetfor this handle has been loaded.@Nullable TgetAsset()Gets the loadedAssetimmediately, but throws a runtime exception if it is not yet loaded.booleanvoidSets the loadedAssetfor 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
Assetfor this handle has not yet been loaded
-
getAsset
Gets the loadedAssetimmediately, but throws a runtime exception if it is not yet loaded.- Returns:
- the loaded asset
-
setAsset
Sets the loadedAssetfor thisAssetHandle.- Parameters:
asset- the loaded asset
-
executeWhenLoaded
Executes the provided consumer asynchronously once theAssetfor 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 theAssetfor this handle has been loaded. Otherwise, it does nothing.- Parameters:
consumer- the function to execute if the asset is loaded
-