summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-12-22 04:00:45 +0100
committerNao Pross <naopross@thearcway.org>2018-12-22 04:01:22 +0100
commitda3f74c914afd6529f8b89d2c90b96056c1b5394 (patch)
tree7af4e9b58a7a1f6289b5059ddff70e4fbccd8408
parentSkip rendering for blank tiles (value = 0) (diff)
downloadSubconscious-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 '')
-rw-r--r--res/maps/demo.tmx8
-rw-r--r--res/maps/tilesets/cliff.png (renamed from res/tilesets/cliff.png)bin96155 -> 96155 bytes
-rw-r--r--res/maps/tilesets/ground.png (renamed from res/tilesets/ground.png)bin227339 -> 227339 bytes
-rw-r--r--res/maps/tilesets/objects.png (renamed from res/tilesets/objects.png)bin32479 -> 32479 bytes
-rw-r--r--res/maps/tilesets/water.png (renamed from res/tilesets/water.png)bin71295 -> 71295 bytes
-rw-r--r--src/graphics.rs24
6 files changed, 24 insertions, 8 deletions
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 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" tiledversion="1.0.3" orientation="orthogonal" renderorder="right-down" width="12" height="12" tilewidth="32" tileheight="32" nextobjectid="1">
<tileset firstgid="1" name="ground" tilewidth="32" tileheight="32" tilecount="441" columns="21">
- <image source="../tilesets/ground.png" width="672" height="701"/>
+ <image source="tilesets/ground.png" width="672" height="701"/>
</tileset>
<tileset firstgid="442" name="cliff" tilewidth="32" tileheight="32" tilecount="240" columns="15">
- <image source="../tilesets/cliff.png" width="503" height="518"/>
+ <image source="tilesets/cliff.png" width="503" height="518"/>
</tileset>
<tileset firstgid="682" name="objects" tilewidth="32" tileheight="32" tilecount="84" columns="14">
- <image source="../tilesets/objects.png" width="477" height="219"/>
+ <image source="tilesets/objects.png" width="477" height="219"/>
</tileset>
<tileset firstgid="766" name="water" tilewidth="32" tileheight="32" tilecount="81" columns="9">
- <image source="../tilesets/water.png" width="319" height="293"/>
+ <image source="tilesets/water.png" width="319" height="293"/>
</tileset>
<layer name="ground" width="12" height="12">
<data encoding="base64" compression="zlib">
diff --git a/res/tilesets/cliff.png b/res/maps/tilesets/cliff.png
index 6ab54c2..6ab54c2 100644
--- a/res/tilesets/cliff.png
+++ b/res/maps/tilesets/cliff.png
Binary files differ
diff --git a/res/tilesets/ground.png b/res/maps/tilesets/ground.png
index 80ccd33..80ccd33 100644
--- a/res/tilesets/ground.png
+++ b/res/maps/tilesets/ground.png
Binary files differ
diff --git a/res/tilesets/objects.png b/res/maps/tilesets/objects.png
index 599c476..599c476 100644
--- a/res/tilesets/objects.png
+++ b/res/maps/tilesets/objects.png
Binary files differ
diff --git a/res/tilesets/water.png b/res/maps/tilesets/water.png
index e5c5c73..e5c5c73 100644
--- a/res/tilesets/water.png
+++ b/res/maps/tilesets/water.png
Binary files 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 {