From f61346d4060a6f0b04571abbbdbae69d6998a593 Mon Sep 17 00:00:00 2001 From: Kautism Date: Tue, 22 Oct 2024 11:16:15 +0800 Subject: [PATCH] Add hexside_length for newer tmx. --- src/map.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/map.rs b/src/map.rs index 37b2503..7dd3dda 100644 --- a/src/map.rs +++ b/src/map.rs @@ -48,6 +48,8 @@ pub struct Map { /// individual tiles may have different sizes. As such, there is no guarantee that this value /// will be the same as the one from the tilesets the map is using. pub tile_height: u32, + /// The Length of the side of a hexagonal tile (used by tile layers on hexagonal maps). + pub hexside_length: Option, /// The stagger axis of Hexagonal/Staggered map. pub stagger_axis: StaggerAxis, /// The stagger index of Hexagonal/Staggered map. @@ -157,7 +159,7 @@ impl Map { cache: &mut impl ResourceCache, ) -> Result { let ( - (c, infinite, user_type, user_class, stagger_axis, stagger_index), + (c, infinite, user_type, user_class, stagger_axis, stagger_index, hexside_length), (v, o, w, h, tw, th), ) = get_attrs!( for v in attrs { @@ -167,6 +169,7 @@ impl Map { Some("class") => user_class ?= v.parse(), Some("staggeraxis") => stagger_axis ?= v.parse::(), Some("staggerindex") => stagger_index ?= v.parse::(), + Some("hexsidelength") => hexside_length ?= v.parse(), "version" => version = v, "orientation" => orientation ?= v.parse::(), "width" => width ?= v.parse::(), @@ -174,13 +177,14 @@ impl Map { "tilewidth" => tile_width ?= v.parse::(), "tileheight" => tile_height ?= v.parse::(), } - ((colour, infinite, user_type, user_class, stagger_axis, stagger_index), (version, orientation, width, height, tile_width, tile_height)) + ((colour, infinite, user_type, user_class, stagger_axis, stagger_index, hexside_length), (version, orientation, width, height, tile_width, tile_height)) ); let infinite = infinite.unwrap_or(false); let user_type = user_type.or(user_class); let stagger_axis = stagger_axis.unwrap_or_default(); let stagger_index = stagger_index.unwrap_or_default(); + // We can only parse sequentally, but tilesets are guaranteed to appear before layers. // So we can pass in tileset data to layer construction without worrying about unfinished @@ -282,6 +286,7 @@ impl Map { height: h, tile_width: tw, tile_height: th, + hexside_length, stagger_axis, stagger_index, tilesets,