diff --git a/CHANGELOG.md b/CHANGELOG.md index 70d2c15ac01b2c5d6a9dad55713644577daef822..8ae8f0d215f61d0d3fe0bbd5ecc76e2eebf6f201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), @@ -6,13 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.9.0] - 2019-25-11 +## [0.9.2] - 2020-Apr-25 ### Added -- + +- Properties to Tilesets. +- Test verifying `tileset.properties` ### Changed -- Migration to `rust 2018` and `?` + +- ### Removed + - diff --git a/README.md b/README.md index d5cb706e4b36986f32386b9db2e499dbc021d940..352fe3b3583bc108484f8e68c92122faf67aa582 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Code contributions are welcome as are bug reports, documentation, suggestions an [There is a package on crates.io](https://crates.io/crates/tiled), to use simply add: ``` -tiled = "0.9.1" +tiled = "0.9.2" ``` to the dependencies section of your Cargo.toml. @@ -38,14 +38,16 @@ fn main() { ``` ### Things missing + There are a few things missing at the moment: - * Terrain - * Tile flipping - * Image layers - * A nice API. At the moment you can access attributes and properties, find tilesets by GID and loop through the tiles. This leaves a user of the library with a bit to do. +- Terrain +- Tile flipping +- Image layers +- A nice API. At the moment you can access attributes and properties, find tilesets by GID and loop through the tiles. This leaves a user of the library with a bit to do. ### Licences + assets/tilesheet.png by Buch (http://blog-buch.rhcloud.com/) Licenced under MIT diff --git a/assets/tiled_base64.tmx b/assets/tiled_base64.tmx index 57d3b817441406ed1fdeccbc1361af1cbae96fb0..7ee37de49809327d3484ed675b6fe5e99150ea33 100644 --- a/assets/tiled_base64.tmx +++ b/assets/tiled_base64.tmx @@ -1,12 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <map version="1.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" backgroundcolor="#ff00ff" nextobjectid="5"> <tileset firstgid="1" name="tilesheet" tilewidth="32" tileheight="32"> - <image source="tilesheet.png" width="448" height="192"/> - <tile id="1"> <properties> - <property name="a tile property" value="123"/> + <property name="tileset property" value="tsp"/> </properties> - </tile> + <image source="tilesheet.png" width="448" height="192"/> + <tile id="1"> + <properties> + <property name="a tile property" value="123"/> + </properties> + </tile> + </tileset> <layer name="Tile Layer 1" width="100" height="100"> <properties> diff --git a/assets/tiled_base64_gzip.tmx b/assets/tiled_base64_gzip.tmx index dead54e814eb729b6b417fccf5af27d618dcaa59..97eae5e3b97cbee5daa69e34cc9467ddc86a666a 100644 --- a/assets/tiled_base64_gzip.tmx +++ b/assets/tiled_base64_gzip.tmx @@ -1,6 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <map version="1.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" backgroundcolor="#ff00ff" nextobjectid="5"> <tileset firstgid="1" name="tilesheet" tilewidth="32" tileheight="32"> + <properties> + <property name="tileset property" value="tsp"/> + </properties> <image source="tilesheet.png" width="448" height="192"/> <tile id="1"> <properties> diff --git a/assets/tiled_base64_zlib.tmx b/assets/tiled_base64_zlib.tmx index 9dd37cf378d35d47b2ec3687bb77832c08162d1f..b217f77943cf7a5d3f8b5dda2af0b62c5fdbcad3 100644 --- a/assets/tiled_base64_zlib.tmx +++ b/assets/tiled_base64_zlib.tmx @@ -1,6 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <map version="1.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" backgroundcolor="#ff00ff" nextobjectid="5"> <tileset firstgid="1" name="tilesheet" tilewidth="32" tileheight="32"> + <properties> + <property name="tileset property" value="tsp"/> + </properties> <image source="tilesheet.png" width="448" height="192"/> <tile id="1"> <properties> diff --git a/assets/tiled_csv.tmx b/assets/tiled_csv.tmx index 88773d73350643d91d2e9bbdb34aa0bd5e760de6..03806c1e8b727d0642b1b04848bd9ce132615355 100644 --- a/assets/tiled_csv.tmx +++ b/assets/tiled_csv.tmx @@ -1,6 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <map version="1.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" backgroundcolor="#ff00ff" nextobjectid="5"> <tileset firstgid="1" name="tilesheet" tilewidth="32" tileheight="32"> + <properties> + <property name="tileset property" value="tsp"/> + </properties> <image source="tilesheet.png" width="448" height="192"/> <tile id="1"> <properties> diff --git a/assets/tilesheet.tsx b/assets/tilesheet.tsx index f01a9da067a1ea6bd8fa1e5fe00c663efcef2b63..05c2c420e36633db3ed394bde891f4f84f8ee683 100644 --- a/assets/tilesheet.tsx +++ b/assets/tilesheet.tsx @@ -1,5 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <tileset name="tilesheet" tilewidth="32" tileheight="32" tilecount="84"> + <properties> + <property name="tileset property" value="tsp"/> + </properties> <image source="tilesheet.png" width="448" height="192"/> <tile id="1"> <properties> diff --git a/src/lib.rs b/src/lib.rs index 1b91600d2e30978b0665a365ebb53107f4cfa5fc..f4ad7a89ab5bb8ccbb230410be6ea1f7efcba2a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -357,6 +357,7 @@ pub struct Tileset { /// is used. Usually you will only use one. pub images: Vec<Image>, pub tiles: Vec<Tile>, + pub properties: Properties, } impl Tileset { @@ -389,11 +390,16 @@ impl Tileset { let mut images = Vec::new(); let mut tiles = Vec::new(); + let mut properties = HashMap::new(); parse_tag!(parser, "tileset", { "image" => |attrs| { images.push(Image::new(parser, attrs)?); Ok(()) }, + "properties" => |_| { + properties = parse_properties(parser)?; + Ok(()) + }, "tile" => |attrs| { tiles.push(Tile::new(parser, attrs)?); Ok(()) @@ -402,13 +408,14 @@ impl Tileset { Ok(Tileset { first_gid: first_gid, - name: name, + name, tile_width: width, tile_height: height, spacing: spacing.unwrap_or(0), margin: margin.unwrap_or(0), - images: images, - tiles: tiles, + images, + tiles, + properties, }) } @@ -485,6 +492,7 @@ impl Tileset { let mut images = Vec::new(); let mut tiles = Vec::new(); + let mut properties = HashMap::new(); parse_tag!(parser, "tileset", { "image" => |attrs| { images.push(Image::new(parser, attrs)?); @@ -494,6 +502,10 @@ impl Tileset { tiles.push(Tile::new(parser, attrs)?); Ok(()) }, + "properties" => |_| { + properties = parse_properties(parser)?; + Ok(()) + }, }); Ok(Tileset { @@ -505,6 +517,7 @@ impl Tileset { margin: margin.unwrap_or(0), images: images, tiles: tiles, + properties, }) } } diff --git a/tests/lib.rs b/tests/lib.rs index 8930381da271054dcd1bb535387ed884a3d4a366..3aca62930f94318a4b77332b58fe5523821ec881 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -88,6 +88,18 @@ fn test_object_group_property() { }; assert!(prop_value); } +#[test] +fn test_tileset_property() { + let r = read_from_file(&Path::new("assets/tiled_base64.tmx")).unwrap(); + let prop_value: String = if let Some(&PropertyValue::StringValue(ref v)) = + r.tilesets[0].properties.get("tileset property") + { + v.clone() + } else { + String::new() + }; + assert_eq!("tsp", prop_value); +} #[test] fn test_flipped_gid() {