Class AssetHandle<T extends Asset>

java.lang.Object
technology.sola.engine.assets.AssetHandle<T>
Type Parameters:
T - the type of the asset

@NullMarked public class AssetHandle<T extends Asset> extends Object
AssetHandle is a handle to an Asset that may or may not be loaded yet.
  • Constructor Details

    • AssetHandle

      public AssetHandle()
      Creates an empty AssetHandle with an empty list of onLoadSubscribers. Listeners will be notified when setAsset(Asset) is called with the loaded asset.
    • AssetHandle

      public AssetHandle(@Nullable T asset)
      Creates an AssetHandle instance with a preloaded Asset.
      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

      public @Nullable T getAsset()
      Gets the loaded Asset immediately, but throws a runtime exception if it is not yet loaded.
      Returns:
      the loaded asset
    • setAsset

      public void setAsset(T asset)
      Sets the loaded Asset for this AssetHandle.
      Parameters:
      asset - the loaded asset
    • executeWhenLoaded

      public void executeWhenLoaded(Consumer<T> consumer)
      Executes the provided consumer asynchronously once the Asset 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

      public void executeIfLoaded(Consumer<T> consumer)
      Executes the provided consumer synchronously if the Asset for this handle has been loaded. Otherwise, it does nothing.
      Parameters:
      consumer - the function to execute if the asset is loaded