Class AssetCatalog

java.lang.Object
com.codename1.gaming.level.AssetCatalog

public class AssetCatalog extends Object

The registry that turns an GameElement#getAssetId() into something a LevelRealizer can draw.

It indexes one or more AssetPacks and resolves each asset's art by its AssetDef#getType(): #image(String) for a static image or a sprite-sheet still, #sheet(String) for the com.codename1.gaming.SpriteSheet of an animated asset, and #meshData(String) for the glTF/glb bytes of a 3D asset. #resolveArt() loads those from each def's AssetDef#getSource() resource; until art is supplied #image(String) returns a cached solid-color placeholder sized from the def, so a level always realizes to something visible.

  • Constructor Details

    • AssetCatalog

      public AssetCatalog()
  • Method Details

    • load

      public static AssetCatalog load(String json) throws IOException
      Parses one or more AssetPacks from a JSON document of the form {"packs":[{"id":..,"name":..,"assets":[{"id":..,"kind":"tile|actor","w":.., "h":..,"color":"#rrggbb","unique":false,"source":..,"defaults":{..}}]}]} and adds them to a new catalog. The same format the editor ships its starter packs in.
      Throws:
      IOException
    • load

      public static AssetCatalog load(InputStream in) throws IOException
      Parses packs from a UTF-8 JSON stream and closes it.
      Throws:
      IOException
    • addPack

      public AssetCatalog addPack(AssetPack pack)
    • getPack

      public AssetPack getPack(String id)
    • packs

      public List<AssetPack> packs()
    • def

      public AssetDef def(String assetId)
      The definition for an asset id, or null if no pack defines it.
    • setImage

      public AssetCatalog setImage(String assetId, Image image)
      Supplies real artwork for an asset id, overriding the placeholder.
    • hasImage

      public boolean hasImage(String assetId)
    • setSheet

      public AssetCatalog setSheet(String assetId, SpriteSheet sheet)
      Supplies the sprite sheet for an animated (AssetDef.Type#SHEET) asset.
    • sheet

      public SpriteSheet sheet(String assetId)
      The sprite sheet for an animated asset, or null if it has none.
    • setMeshData

      public AssetCatalog setMeshData(String assetId, byte[] data)
      Supplies the glTF/glb bytes for a 3D (AssetDef.Type#MESH) asset.
    • meshData

      public byte[] meshData(String assetId)
      The glTF/glb bytes for a 3D asset (load with com.codename1.gpu.GltfLoader), or null if it has none.
    • image

      public Image image(String assetId)
      Resolves the image for an asset id: the explicit art if one was supplied, else the first frame of a sprite sheet, else a cached solid-color placeholder sized from the def. Returns null only when the id is unknown to every pack and no art was set.
    • resolveArt

      public AssetCatalog resolveArt()
      Loads each asset's art from its AssetDef#getSource() resource: a static image, a sprite sheet (AssetDef.Type#SHEET), or glTF/glb mesh bytes (AssetDef.Type#MESH). Best-effort -- an asset whose source is missing keeps its placeholder. Tries the source path as-is and, for the flat device bundle, by file name. Returns this.