Skip to content

Commit

Permalink
Add hexside_length for newer tmx. (#313)
Browse files Browse the repository at this point in the history
* Add hexside_length for newer tmx.

* Fix fmt check

* Add CHANGELOG.md

* Update changelog

* [ci skip] Small typo fix

* Retrigger CI

* Change hexside_length to hex_side_length.

---------

Co-authored-by: aleokdev <[email protected]>
  • Loading branch information
darkautism and aleokdev authored Oct 22, 2024
1 parent 78eaf51 commit 31783f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased (0.13.0)]
### Added
- Added a `source` member to `Tileset`, `Map` and `Template`, which stores the resource path they have been loaded from.
- Add `hex_side_length` member to `Map`. (#313)

## [Unreleased (0.12.2)]
### Fixed
Expand Down
8 changes: 6 additions & 2 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 in pixels (used by tile layers on hexagonal maps).
pub hex_side_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 @@ -165,7 +167,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, hex_side_length),
(v, o, w, h, tw, th),
) = get_attrs!(
for v in attrs {
Expand All @@ -175,14 +177,15 @@ impl Map {
Some("class") => user_class ?= v.parse(),
Some("staggeraxis") => stagger_axis ?= v.parse::<StaggerAxis>(),
Some("staggerindex") => stagger_index ?= v.parse::<StaggerIndex>(),
Some("hexsidelength") => hex_side_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, hex_side_length), (version, orientation, width, height, tile_width, tile_height))
);

let infinite = infinite.unwrap_or(false);
Expand Down Expand Up @@ -291,6 +294,7 @@ impl Map {
height: h,
tile_width: tw,
tile_height: th,
hex_side_length,
stagger_axis,
stagger_index,
tilesets,
Expand Down

0 comments on commit 31783f0

Please sign in to comment.