From eb360e5b2ccc79914cf607ba19adef618b7f2aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 24 Jan 2022 18:01:32 +0100 Subject: [PATCH] Changes required to compile against rs-tiled git --- Cargo.lock | 3 +-- Cargo.toml | 4 ++-- examples/tiled/tiled.rs | 25 ++++++++++++------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1698c2f7..d85ccc11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2973,8 +2973,7 @@ dependencies = [ [[package]] name = "tiled" version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9b76189425fed476c9cb0e2a97adb0c6c9d370bf69a57cb951814e77a5fe63" +source = "git+https://github.com/mapeditor/rs-tiled.git#28ba42c0f9def4dc716bfe34b1a65c9e2fb9843d" dependencies = [ "base64 0.10.1", "libflate", diff --git a/Cargo.toml b/Cargo.toml index ade90dba..70377b0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ ldtk_rust = { version = "0.5" } rand = "0.8" env_logger = "0.9" serde_json = { version = "1.0" } -tiled = { version = "0.9", default-features = false } +tiled = { version = "0.9", git = "https://github.com/mapeditor/rs-tiled.git", default-features = false } [[example]] name = "ldtk" @@ -42,4 +42,4 @@ name = "tiled_rotate" path = "examples/tiled/tiled_rotate.rs" [target.wasm32-unknown-unknown] -runner = "wasm-server-runner" \ No newline at end of file +runner = "wasm-server-runner" diff --git a/examples/tiled/tiled.rs b/examples/tiled/tiled.rs index c51be354..c623aef3 100644 --- a/examples/tiled/tiled.rs +++ b/examples/tiled/tiled.rs @@ -20,7 +20,7 @@ impl Plugin for TiledMapPlugin { #[derive(TypeUuid)] #[uuid = "e51081d0-6168-4881-a1c6-4249b2000d7f"] pub struct TiledMap { - pub map: tiled::Map, + pub map: tiled::map::Map, pub tilesets: HashMap>, } @@ -41,14 +41,13 @@ impl AssetLoader for TiledLoader { load_context: &'a mut LoadContext, ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { Box::pin(async move { - let root_dir = load_context.path().parent().unwrap(); - let map = tiled::parse(BufReader::new(bytes))?; + let map = tiled::map::Map::parse_reader(BufReader::new(bytes), Some(load_context.path()))?; let mut dependencies = Vec::new(); let mut handles = HashMap::default(); for tileset in &map.tilesets { - let tile_path = root_dir.join(tileset.images.first().unwrap().source.as_str()); + let tile_path = tileset.image.as_ref().unwrap().source.clone(); let asset_path = AssetPath::new(tile_path, None); let texture: Handle = load_context.get_handle(asset_path.clone()); @@ -164,9 +163,9 @@ pub fn process_loaded_tile_maps( ChunkSize(64, 64), TileSize(tile_width, tile_height), TextureSize( - tileset.images[0].width as f32, - tileset.images[0].height as f32, - ), // TODO: support multiple tileset images? + tileset.image.as_ref().unwrap().width as f32, + tileset.image.as_ref().unwrap().height as f32, + ), ); map_settings.grid_size = Vec2::new( tiled_map.map.tile_width as f32, @@ -174,16 +173,16 @@ pub fn process_loaded_tile_maps( ); map_settings.mesh_type = match tiled_map.map.orientation { - tiled::Orientation::Hexagonal => { + tiled::map::Orientation::Hexagonal => { TilemapMeshType::Hexagon(HexType::Row) // TODO: Support hex for real. } - tiled::Orientation::Isometric => { + tiled::map::Orientation::Isometric => { TilemapMeshType::Isometric(IsoType::Diamond) } - tiled::Orientation::Staggered => { + tiled::map::Orientation::Staggered => { TilemapMeshType::Isometric(IsoType::Staggered) } - tiled::Orientation::Orthogonal => TilemapMeshType::Square, + tiled::map::Orientation::Orthogonal => TilemapMeshType::Square, }; let layer_entity = LayerBuilder::::new_batch( @@ -200,7 +199,7 @@ pub fn process_loaded_tile_maps( return None; } - if tiled_map.map.orientation == tiled::Orientation::Orthogonal { + if tiled_map.map.orientation == tiled::map::Orientation::Orthogonal { tile_pos.1 = (tiled_map.map.height - 1) as u32 - tile_pos.1; } @@ -208,7 +207,7 @@ pub fn process_loaded_tile_maps( let y = tile_pos.1 as usize; let map_tile = match &layer.tiles { - tiled::LayerData::Finite(tiles) => &tiles[y][x], + tiled::layers::LayerData::Finite(tiles) => &tiles[y * layer.width as usize + x], _ => panic!("Infinite maps not supported"), };