Skip to content
Snippets Groups Projects
Commit 2a7a80d7 authored by jon lipstate's avatar jon lipstate
Browse files

added tileset properties & associated test

parent 12accd70
No related branches found
No related tags found
No related merge requests found
# Changelog # Changelog
All notable changes to this project will be documented in this file. 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/), 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 ...@@ -6,13 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.9.0] - 2019-25-11 ## [0.9.2] - 2020-Apr-25
### Added ### Added
-
- Properties to Tilesets.
- Test verifying `tileset.properties`
### Changed ### Changed
- Migration to `rust 2018` and `?`
-
### Removed ### Removed
- -
...@@ -10,7 +10,7 @@ Code contributions are welcome as are bug reports, documentation, suggestions an ...@@ -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: [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. to the dependencies section of your Cargo.toml.
...@@ -38,14 +38,16 @@ fn main() { ...@@ -38,14 +38,16 @@ fn main() {
``` ```
### Things missing ### Things missing
There are a few things missing at the moment: There are a few things missing at the moment:
* Terrain - Terrain
* Tile flipping - Tile flipping
* Image layers - 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. - 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 ### Licences
assets/tilesheet.png by Buch (http://blog-buch.rhcloud.com/) assets/tilesheet.png by Buch (http://blog-buch.rhcloud.com/)
Licenced under MIT Licenced under MIT
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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"> <tileset firstgid="1" name="tilesheet" tilewidth="32" tileheight="32">
<image source="tilesheet.png" width="448" height="192"/>
<tile id="1">
<properties> <properties>
<property name="a tile property" value="123"/> <property name="tileset property" value="tsp"/>
</properties> </properties>
</tile> <image source="tilesheet.png" width="448" height="192"/>
<tile id="1">
<properties>
<property name="a tile property" value="123"/>
</properties>
</tile>
</tileset> </tileset>
<layer name="Tile Layer 1" width="100" height="100"> <layer name="Tile Layer 1" width="100" height="100">
<properties> <properties>
......
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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"> <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"/> <image source="tilesheet.png" width="448" height="192"/>
<tile id="1"> <tile id="1">
<properties> <properties>
......
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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"> <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"/> <image source="tilesheet.png" width="448" height="192"/>
<tile id="1"> <tile id="1">
<properties> <properties>
......
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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"> <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"/> <image source="tilesheet.png" width="448" height="192"/>
<tile id="1"> <tile id="1">
<properties> <properties>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<tileset name="tilesheet" tilewidth="32" tileheight="32" tilecount="84"> <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"/> <image source="tilesheet.png" width="448" height="192"/>
<tile id="1"> <tile id="1">
<properties> <properties>
......
...@@ -357,6 +357,7 @@ pub struct Tileset { ...@@ -357,6 +357,7 @@ pub struct Tileset {
/// is used. Usually you will only use one. /// is used. Usually you will only use one.
pub images: Vec<Image>, pub images: Vec<Image>,
pub tiles: Vec<Tile>, pub tiles: Vec<Tile>,
pub properties: Properties,
} }
impl Tileset { impl Tileset {
...@@ -389,11 +390,16 @@ impl Tileset { ...@@ -389,11 +390,16 @@ impl Tileset {
let mut images = Vec::new(); let mut images = Vec::new();
let mut tiles = Vec::new(); let mut tiles = Vec::new();
let mut properties = HashMap::new();
parse_tag!(parser, "tileset", { parse_tag!(parser, "tileset", {
"image" => |attrs| { "image" => |attrs| {
images.push(Image::new(parser, attrs)?); images.push(Image::new(parser, attrs)?);
Ok(()) Ok(())
}, },
"properties" => |_| {
properties = parse_properties(parser)?;
Ok(())
},
"tile" => |attrs| { "tile" => |attrs| {
tiles.push(Tile::new(parser, attrs)?); tiles.push(Tile::new(parser, attrs)?);
Ok(()) Ok(())
...@@ -402,13 +408,14 @@ impl Tileset { ...@@ -402,13 +408,14 @@ impl Tileset {
Ok(Tileset { Ok(Tileset {
first_gid: first_gid, first_gid: first_gid,
name: name, name,
tile_width: width, tile_width: width,
tile_height: height, tile_height: height,
spacing: spacing.unwrap_or(0), spacing: spacing.unwrap_or(0),
margin: margin.unwrap_or(0), margin: margin.unwrap_or(0),
images: images, images,
tiles: tiles, tiles,
properties,
}) })
} }
...@@ -485,6 +492,7 @@ impl Tileset { ...@@ -485,6 +492,7 @@ impl Tileset {
let mut images = Vec::new(); let mut images = Vec::new();
let mut tiles = Vec::new(); let mut tiles = Vec::new();
let mut properties = HashMap::new();
parse_tag!(parser, "tileset", { parse_tag!(parser, "tileset", {
"image" => |attrs| { "image" => |attrs| {
images.push(Image::new(parser, attrs)?); images.push(Image::new(parser, attrs)?);
...@@ -494,6 +502,10 @@ impl Tileset { ...@@ -494,6 +502,10 @@ impl Tileset {
tiles.push(Tile::new(parser, attrs)?); tiles.push(Tile::new(parser, attrs)?);
Ok(()) Ok(())
}, },
"properties" => |_| {
properties = parse_properties(parser)?;
Ok(())
},
}); });
Ok(Tileset { Ok(Tileset {
...@@ -505,6 +517,7 @@ impl Tileset { ...@@ -505,6 +517,7 @@ impl Tileset {
margin: margin.unwrap_or(0), margin: margin.unwrap_or(0),
images: images, images: images,
tiles: tiles, tiles: tiles,
properties,
}) })
} }
} }
......
...@@ -88,6 +88,18 @@ fn test_object_group_property() { ...@@ -88,6 +88,18 @@ fn test_object_group_property() {
}; };
assert!(prop_value); 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] #[test]
fn test_flipped_gid() { fn test_flipped_gid() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment