类 AssetsService

java.lang.Object
pkg.exoad.poprock.core.AssetsService

@ServiceClass(requiresArming=false) public final class AssetsService extends Object
AssetsService - Naive class for loading things from a baked-in assets folder that is bundled with the Poprock library and program. It can be used to fetch outside of this baked-in folder, but highly unstable and untested.

All of the methods that try to fetch an object are given 2 tries to find the required asset where it will first try to search in the pre-baked folder, then outside the pre-baked folder. If both of those fail for some reason, a final null is returned which is highly unlikely if the asset is actually present.

There are plans to migrate to using Optional's to allow for better catching of nonexistent assets, but that just introduces overhead as 99.9% of the time, the asset should be there.

作者:
Jack Meng
  • 字段详细资料

    • ASSETS_OFFSET

      public static String ASSETS_OFFSET
      Set to where this service should search in and append paths after. Rarely should this be touched.
    • cache

      private static final WeakHashMap<String,Object> cache
  • 构造器详细资料

    • AssetsService

      private AssetsService()
  • 方法详细资料

    • fetchImageIcon

      public static ImageIcon fetchImageIcon(String path)
      Fetches an ImageIcon object from the baked in folder. This is usually used directly with an UI object directly and requires no additional processing by the program. Such as scaling, filtering, etc..

      Example Usage

       UIButtonDelegate
                      .make()
                      .withIcon(AssetsService.fetchImageIcon("assets/icons/home_64x64.png"));
       
      参数:
      path - The internal baked-in path to search from
      返回:
      The loaded ImageIcon.
    • fetchBufferedImage

      public static BufferedImage fetchBufferedImage(String path)
      Fetchs an Image object. Similar to fetchImageIcon(String), but instead this function is called when we want to modify the image after, such as scaling, filtering, etc..

      Example Usage

       BufferedImage img=AssetsService.fetchBufferedImage("assets/icons/home_64x64.png");
       
      参数:
      path - The internal baked-in path to search from
      返回:
      The loaded BufferedImage
    • fetchFile

      public static File fetchFile(String path)