Class AssetCatalog
java.lang.Object
com.codename1.gaming.level.AssetCatalog
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe definition for an asset id, or null if no pack defines it.booleanResolves 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.static AssetCatalogload(InputStream in) Parses packs from a UTF-8 JSON stream and closes it.static AssetCatalogParses one or moreAssetPacks 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.byte[]The glTF/glb bytes for a 3D asset (load withcom.codename1.gpu.GltfLoader), or null if it has none.packs()Loads each asset's art from itsAssetDef#getSource()resource: a static image, a sprite sheet (AssetDef.Type#SHEET), or glTF/glb mesh bytes (AssetDef.Type#MESH).Supplies real artwork for an asset id, overriding the placeholder.setMeshData(String assetId, byte[] data) Supplies the glTF/glb bytes for a 3D (AssetDef.Type#MESH) asset.setSheet(String assetId, SpriteSheet sheet) Supplies the sprite sheet for an animated (AssetDef.Type#SHEET) asset.The sprite sheet for an animated asset, or null if it has none.
-
Constructor Details
-
AssetCatalog
public AssetCatalog()
-
-
Method Details
-
load
Parses one or moreAssetPacks 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
Parses packs from a UTF-8 JSON stream and closes it.- Throws:
IOException
-
addPack
-
getPack
-
packs
-
def
-
setImage
Supplies real artwork for an asset id, overriding the placeholder. -
hasImage
-
setSheet
Supplies the sprite sheet for an animated (AssetDef.Type#SHEET) asset. -
sheet
The sprite sheet for an animated asset, or null if it has none. -
setMeshData
Supplies the glTF/glb bytes for a 3D (AssetDef.Type#MESH) asset. -
meshData
The glTF/glb bytes for a 3D asset (load withcom.codename1.gpu.GltfLoader), or null if it has none. -
image
-
resolveArt
Loads each asset's art from itsAssetDef#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. Returnsthis.
-