From da3f74c914afd6529f8b89d2c90b96056c1b5394 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 22 Dec 2018 04:00:45 +0100 Subject: Move tilesets inside res/maps, add error messages for map assets loading The resources have been moved as a subdirectory of maps because Rust-Embed cannot resolve relative path when resources are embedded in the binary. --- res/maps/demo.tmx | 8 ++++---- res/maps/tilesets/cliff.png | Bin 0 -> 96155 bytes res/maps/tilesets/ground.png | Bin 0 -> 227339 bytes res/maps/tilesets/objects.png | Bin 0 -> 32479 bytes res/maps/tilesets/water.png | Bin 0 -> 71295 bytes res/tilesets/cliff.png | Bin 96155 -> 0 bytes res/tilesets/ground.png | Bin 227339 -> 0 bytes res/tilesets/objects.png | Bin 32479 -> 0 bytes res/tilesets/water.png | Bin 71295 -> 0 bytes src/graphics.rs | 24 ++++++++++++++++++++---- 10 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 res/maps/tilesets/cliff.png create mode 100644 res/maps/tilesets/ground.png create mode 100644 res/maps/tilesets/objects.png create mode 100644 res/maps/tilesets/water.png delete mode 100644 res/tilesets/cliff.png delete mode 100644 res/tilesets/ground.png delete mode 100644 res/tilesets/objects.png delete mode 100644 res/tilesets/water.png diff --git a/res/maps/demo.tmx b/res/maps/demo.tmx index 0b8a539..cf10ad2 100644 --- a/res/maps/demo.tmx +++ b/res/maps/demo.tmx @@ -1,16 +1,16 @@ - + - + - + - + diff --git a/res/maps/tilesets/cliff.png b/res/maps/tilesets/cliff.png new file mode 100644 index 0000000..6ab54c2 Binary files /dev/null and b/res/maps/tilesets/cliff.png differ diff --git a/res/maps/tilesets/ground.png b/res/maps/tilesets/ground.png new file mode 100644 index 0000000..80ccd33 Binary files /dev/null and b/res/maps/tilesets/ground.png differ diff --git a/res/maps/tilesets/objects.png b/res/maps/tilesets/objects.png new file mode 100644 index 0000000..599c476 Binary files /dev/null and b/res/maps/tilesets/objects.png differ diff --git a/res/maps/tilesets/water.png b/res/maps/tilesets/water.png new file mode 100644 index 0000000..e5c5c73 Binary files /dev/null and b/res/maps/tilesets/water.png differ diff --git a/res/tilesets/cliff.png b/res/tilesets/cliff.png deleted file mode 100644 index 6ab54c2..0000000 Binary files a/res/tilesets/cliff.png and /dev/null differ diff --git a/res/tilesets/ground.png b/res/tilesets/ground.png deleted file mode 100644 index 80ccd33..0000000 Binary files a/res/tilesets/ground.png and /dev/null differ diff --git a/res/tilesets/objects.png b/res/tilesets/objects.png deleted file mode 100644 index 599c476..0000000 Binary files a/res/tilesets/objects.png and /dev/null differ diff --git a/res/tilesets/water.png b/res/tilesets/water.png deleted file mode 100644 index e5c5c73..0000000 Binary files a/res/tilesets/water.png and /dev/null differ diff --git a/src/graphics.rs b/src/graphics.rs index 9af03f4..68dfa65 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -93,7 +93,12 @@ impl Graphics { continue; } - let tmx_tileset = state.map.get_tileset_by_gid(tmx_tile).unwrap(); + let tmx_tileset = match state.map.get_tileset_by_gid(tmx_tile) { + Some(tileset) => tileset, + None => { + panic!("Failed to get tileset with get_tileset_by_gid"); + } + }; // load tileset if not loaded yet // TODO: load in a separate thread? @@ -103,8 +108,19 @@ impl Graphics { // load tileset image let tmx_image = &tmx_tileset.images[0]; - let asset = MapAssets::get(&tmx_image.source).unwrap(); - let image = Image::from_memory(asset.as_ref()).unwrap(); + let asset = match MapAssets::get(&tmx_image.source) { + Some(asset) => asset, + None => { + panic!("Failed to get asset: {}", &tmx_image.source); + } + }; + + let image = match Image::from_memory(asset.as_ref()) { + Some(image) => image, + None => { + panic!("Failed load image from asset"); + } + }; // load tiles (textures) let tileset_width = tmx_image.width as u32 / tmx_tileset.tile_width; @@ -135,7 +151,7 @@ impl Graphics { // draw! // TODO: check map render order - let texture = self.textures.get(&tmx_tile).unwrap(); + let texture = &self.textures.get(&tmx_tile).unwrap(); let mut tile_rect = RectangleShape::with_texture(texture); tile_rect.set_size(Vector2f { -- cgit v1.2.1