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
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
-
......@@ -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
<?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>
......
<?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>
......
<?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>
......
<?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>
......
<?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>
......
......@@ -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,
})
}
}
......
......@@ -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() {
......
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