Class ResourceService

java.lang.Object
com.deco2800.game.services.ResourceService
All Implemented Interfaces:
Disposable

public class ResourceService
extends java.lang.Object
implements Disposable
Service for loading resources, e.g. textures, texture atlases, sounds, music, etc. Add new load methods when new types of resources are added to the game.
  • Constructor Summary

    Constructors 
    Constructor Description
    ResourceService()  
    ResourceService​(AssetManager assetManager)  
  • Method Summary

    Modifier and Type Method Description
    <T> boolean containsAsset​(java.lang.String resourceName, java.lang.Class<T> type)
    Check if an asset has been loaded already
    void dispose()  
    <T> T getAsset​(java.lang.String filename, java.lang.Class<T> type)
    Load an asset from a file
    int getProgress()
    Returns the loading completion progress as a percentage.
    void loadAll()
    Blocking call to load all assets.
    boolean loadForMillis​(int duration)
    Loads assets for the specified duration in milliseconds.
    void loadMusic​(java.lang.String[] musicNames)
    Loads a list of music assets into the asset manager.
    void loadSounds​(java.lang.String[] soundNames)
    Loads a list of sounds into the asset manager.
    void loadTextureAtlases​(java.lang.String[] textureAtlasNames)
    Loads a list of texture atlas assets into the asset manager.
    void loadTextures​(java.lang.String[] textureNames)
    Loads a list of texture assets into the asset manager.
    void unloadAssets​(java.lang.String[] assetNames)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getAsset

      public <T> T getAsset​(java.lang.String filename, java.lang.Class<T> type)
      Load an asset from a file
      Type Parameters:
      T - Type of class to load into
      Parameters:
      filename - Asset path
      type - Class to load into
      Returns:
      Instance of class loaded from path
      See Also:
      AssetManager.get(String, Class)
    • containsAsset

      public <T> boolean containsAsset​(java.lang.String resourceName, java.lang.Class<T> type)
      Check if an asset has been loaded already
      Type Parameters:
      T - Type of the asset
      Parameters:
      resourceName - path of the asset
      type - Class type of the asset
      Returns:
      true if asset has been loaded, false otherwise
      See Also:
      AssetManager.contains(String)
    • getProgress

      public int getProgress()
      Returns the loading completion progress as a percentage.
      Returns:
      progress
    • loadAll

      public void loadAll()
      Blocking call to load all assets.
      See Also:
      AssetManager.finishLoading()
    • loadForMillis

      public boolean loadForMillis​(int duration)
      Loads assets for the specified duration in milliseconds.
      Parameters:
      duration - duration to load for
      Returns:
      finished loading
      See Also:
      AssetManager.update(int)
    • loadTextures

      public void loadTextures​(java.lang.String[] textureNames)
      Loads a list of texture assets into the asset manager.
      Parameters:
      textureNames - texture filenames
    • loadTextureAtlases

      public void loadTextureAtlases​(java.lang.String[] textureAtlasNames)
      Loads a list of texture atlas assets into the asset manager.
      Parameters:
      textureAtlasNames - texture atlas filenames
    • loadSounds

      public void loadSounds​(java.lang.String[] soundNames)
      Loads a list of sounds into the asset manager.
      Parameters:
      soundNames - sound filenames
    • loadMusic

      public void loadMusic​(java.lang.String[] musicNames)
      Loads a list of music assets into the asset manager.
      Parameters:
      musicNames - music filenames
    • unloadAssets

      public void unloadAssets​(java.lang.String[] assetNames)
    • dispose

      public void dispose()
      Specified by:
      dispose in interface Disposable