Skip to content

Commit

Permalink
Add hexside_length for newer tmx.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkautism committed Oct 22, 2024
1 parent 1ffab03 commit f61346d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
/// The stagger axis of Hexagonal/Staggered map.
pub stagger_axis: StaggerAxis,
/// The stagger index of Hexagonal/Staggered map.
Expand Down Expand Up @@ -157,7 +159,7 @@ impl Map {
cache: &mut impl ResourceCache,
) -> Result<Map> {
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 {
Expand All @@ -167,20 +169,22 @@ impl Map {
Some("class") => user_class ?= v.parse(),
Some("staggeraxis") => stagger_axis ?= v.parse::<StaggerAxis>(),
Some("staggerindex") => stagger_index ?= v.parse::<StaggerIndex>(),
Some("hexsidelength") => hexside_length ?= v.parse(),
"version" => version = v,
"orientation" => orientation ?= v.parse::<Orientation>(),
"width" => width ?= v.parse::<u32>(),
"height" => height ?= v.parse::<u32>(),
"tilewidth" => tile_width ?= v.parse::<u32>(),
"tileheight" => tile_height ?= v.parse::<u32>(),
}
((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
Expand Down Expand Up @@ -282,6 +286,7 @@ impl Map {
height: h,
tile_width: tw,
tile_height: th,
hexside_length,
stagger_axis,
stagger_index,
tilesets,
Expand Down

0 comments on commit f61346d

Please sign in to comment.