summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/graphics.rs24
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 {