update asset loaders to throw AssetLoadingExceptions on error
This commit is contained in:
parent
1e6c502641
commit
ac66820997
|
@ -1,6 +1,7 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.prefabs;
|
||||
|
||||
import ca.blarg.gdx.Strings;
|
||||
import ca.blarg.gdx.assets.AssetLoadingException;
|
||||
import ca.blarg.gdx.tilemap3d.assets.tilemap.TileDataSerializer;
|
||||
import ca.blarg.gdx.tilemap3d.prefabs.TilePrefab;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
|
@ -16,9 +17,9 @@ class TilePrefabJsonLoader {
|
|||
return json.fromJson(JsonTilePrefab.class, file);
|
||||
}
|
||||
|
||||
public static TilePrefab create(JsonTilePrefab definition, AssetManager assetManager) {
|
||||
public static TilePrefab create(FileHandle file, JsonTilePrefab definition, AssetManager assetManager) {
|
||||
if (Strings.isNullOrEmpty(definition.data))
|
||||
throw new RuntimeException("Invalid prefab: no tile data.");
|
||||
throw new AssetLoadingException(file.path(), "No tile data.");
|
||||
|
||||
TilePrefab prefab = new TilePrefab(definition.width, definition.height, definition.depth);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public class TilePrefabLoader extends AsynchronousAssetLoader<TilePrefab, TilePr
|
|||
|
||||
@Override
|
||||
public void loadAsync(AssetManager manager, String fileName, FileHandle file, TilePrefabParameters parameter) {
|
||||
prefab = TilePrefabJsonLoader.create(definition, manager);
|
||||
prefab = TilePrefabJsonLoader.create(file, definition, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemap;
|
||||
|
||||
import ca.blarg.gdx.Strings;
|
||||
import ca.blarg.gdx.assets.AssetLoadingException;
|
||||
import ca.blarg.gdx.tilemap3d.ChunkVertexGenerator;
|
||||
import ca.blarg.gdx.tilemap3d.TileChunk;
|
||||
import ca.blarg.gdx.tilemap3d.TileMap;
|
||||
|
@ -22,14 +23,14 @@ class TileMapJsonLoader {
|
|||
return json.fromJson(JsonTileMap.class, file);
|
||||
}
|
||||
|
||||
public static TileMap create(JsonTileMap definition, AssetManager assetManager) {
|
||||
public static TileMap create(FileHandle file, JsonTileMap definition, AssetManager assetManager) {
|
||||
if (definition.chunks == null || definition.chunks.size() == 0)
|
||||
throw new RuntimeException("Invalid map: no chunks.");
|
||||
throw new AssetLoadingException(file.path(), "No chunks.");
|
||||
int numChunks = (definition.widthInChunks * definition.heightInChunks * definition.depthInChunks);
|
||||
if (definition.chunks.size() != numChunks)
|
||||
throw new RuntimeException("Inconsistent map dimensions and number of chunks.");
|
||||
throw new AssetLoadingException(file.path(), "Inconsistent map dimensions and number of chunks.");
|
||||
if (definition.tileMeshes == null)
|
||||
throw new RuntimeException("No tile mesh collection specified.");
|
||||
throw new AssetLoadingException(file.path(), "No tile mesh collection specified.");
|
||||
|
||||
TileMeshCollection tileMeshes = assetManager.get(definition.tileMeshes, TileMeshCollection.class);
|
||||
|
||||
|
@ -46,7 +47,7 @@ class TileMapJsonLoader {
|
|||
chunkVertexGenerator = new LitChunkVertexGenerator();
|
||||
lighter = new LightSpreadingTileMapLighter(true, true);
|
||||
} else
|
||||
throw new RuntimeException("Invalid lighting mode.");
|
||||
throw new AssetLoadingException(file.path(), "Invalid lighting mode.");
|
||||
|
||||
TileMap tileMap = new TileMap(
|
||||
definition.chunkWidth, definition.chunkHeight, definition.chunkDepth,
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TileMapLoader extends AsynchronousAssetLoader<TileMap, TileMapLoade
|
|||
|
||||
@Override
|
||||
public void loadAsync(AssetManager manager, String fileName, FileHandle file, TileMapParameters parameter) {
|
||||
map = TileMapJsonLoader.create(definition, manager);
|
||||
map = TileMapJsonLoader.create(file, definition, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.assets.AssetLoadingException;
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.MaterialTileMapping;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
|
@ -12,9 +13,11 @@ class MaterialTileMappingJsonLoader {
|
|||
return json.fromJson(JsonMaterialMapping.class, file);
|
||||
}
|
||||
|
||||
public static MaterialTileMapping create(JsonMaterialMapping definition, AssetManager assetManager) {
|
||||
public static MaterialTileMapping create(FileHandle file, JsonMaterialMapping definition, AssetManager assetManager) {
|
||||
if (definition.materials == null || definition.materials.size() == 0)
|
||||
throw new RuntimeException("No material mappings defined.");
|
||||
throw new AssetLoadingException(file.path(), "No material mappings defined.");
|
||||
if (definition.textureAtlas == null)
|
||||
throw new AssetLoadingException(file.path(), "No texture atlas specified.");
|
||||
|
||||
TextureAtlas atlas = assetManager.get(definition.textureAtlas, TextureAtlas.class);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public class MaterialTileMappingLoader extends AsynchronousAssetLoader<MaterialT
|
|||
|
||||
@Override
|
||||
public void loadAsync(AssetManager manager, String fileName, FileHandle file, MaterialTileMappingParameters parameter) {
|
||||
mapping = MaterialTileMappingJsonLoader.create(definition, manager);
|
||||
mapping = MaterialTileMappingJsonLoader.create(file, definition, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ca.blarg.gdx.tilemap3d.assets.tilemesh;
|
||||
|
||||
import ca.blarg.gdx.assets.AssetLoadingException;
|
||||
import ca.blarg.gdx.graphics.atlas.TextureAtlas;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.TileMesh;
|
||||
import ca.blarg.gdx.tilemap3d.tilemesh.TileMeshCollection;
|
||||
|
@ -13,11 +14,11 @@ class TileMeshCollectionJsonLoader {
|
|||
return json.fromJson(JsonTileMeshCollection.class, file);
|
||||
}
|
||||
|
||||
public static TileMeshCollection create(JsonTileMeshCollection definition, AssetManager assetManager) {
|
||||
public static TileMeshCollection create(FileHandle file, JsonTileMeshCollection definition, AssetManager assetManager) {
|
||||
if (definition.tiles == null || definition.tiles.size() == 0)
|
||||
throw new RuntimeException("No tiles defined.");
|
||||
throw new AssetLoadingException(file.path(), "No tiles defined.");
|
||||
if (definition.textureAtlas == null)
|
||||
throw new RuntimeException("No texture atlas defined.");
|
||||
throw new AssetLoadingException(file.path(), "No texture atlas defined.");
|
||||
|
||||
TextureAtlas atlas = assetManager.get(definition.textureAtlas, TextureAtlas.class);
|
||||
TileMeshCollection collection = new TileMeshCollection(atlas);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TileMeshCollectionLoader extends AsynchronousAssetLoader<TileMeshCo
|
|||
|
||||
@Override
|
||||
public void loadAsync(AssetManager manager, String fileName, FileHandle file, TileMeshCollectionParameters parameter) {
|
||||
collection = TileMeshCollectionJsonLoader.create(definition, manager);
|
||||
collection = TileMeshCollectionJsonLoader.create(file, definition, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue