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. --- src/graphics.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src') 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