diff options
author | Nao Pross <naopross@thearcway.org> | 2018-12-22 04:00:45 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-12-22 04:01:22 +0100 |
commit | da3f74c914afd6529f8b89d2c90b96056c1b5394 (patch) | |
tree | 7af4e9b58a7a1f6289b5059ddff70e4fbccd8408 /src | |
parent | Skip rendering for blank tiles (value = 0) (diff) | |
download | Subconscious-rs-da3f74c914afd6529f8b89d2c90b96056c1b5394.tar.gz Subconscious-rs-da3f74c914afd6529f8b89d2c90b96056c1b5394.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/graphics.rs | 24 |
1 files changed, 20 insertions, 4 deletions
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 { |