Skip to content
Snippets Groups Projects
Commit 0895c585 authored by Matthew Hall's avatar Matthew Hall Committed by GitHub
Browse files

Merge pull request #27 from guodman/master

Load in properties from the tiles
parents 2ec9c563 d0bfbfb8
No related branches found
No related tags found
No related merge requests found
...@@ -307,7 +307,7 @@ impl FromStr for Orientation { ...@@ -307,7 +307,7 @@ impl FromStr for Orientation {
} }
/// A tileset, usually the tilesheet image. /// A tileset, usually the tilesheet image.
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq)]
pub struct Tileset { pub struct Tileset {
/// The GID of the first tile stored /// The GID of the first tile stored
pub first_gid: u32, pub first_gid: u32,
...@@ -420,10 +420,11 @@ impl Tileset { ...@@ -420,10 +420,11 @@ impl Tileset {
} }
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq)]
pub struct Tile { pub struct Tile {
pub id: u32, pub id: u32,
pub images: Vec<Image> pub images: Vec<Image>,
pub properties: Properties,
} }
impl Tile { impl Tile {
...@@ -435,12 +436,17 @@ impl Tile { ...@@ -435,12 +436,17 @@ impl Tile {
TiledError::MalformedAttributes("tile must have an id with the correct type".to_string())); TiledError::MalformedAttributes("tile must have an id with the correct type".to_string()));
let mut images = Vec::new(); let mut images = Vec::new();
let mut properties = HashMap::new();
parse_tag!(parser, "tile", parse_tag!(parser, "tile",
"image" => |attrs| { "image" => |attrs| {
images.push(try!(Image::new(parser, attrs))); images.push(Image::new(parser, attrs)?);
Ok(()) Ok(())
}); },
Ok(Tile {id: i, images: images}) "properties" => |_| {
properties = parse_properties(parser)?;
Ok(())
});
Ok(Tile {id: i, images: images, properties: properties})
} }
} }
......
...@@ -2,7 +2,7 @@ extern crate tiled; ...@@ -2,7 +2,7 @@ extern crate tiled;
use std::path::Path; use std::path::Path;
use std::fs::File; use std::fs::File;
use tiled::{Map, TiledError, parse, parse_file, parse_tileset}; use tiled::{Map, TiledError, PropertyValue, parse, parse_file, parse_tileset};
fn read_from_file(p: &Path) -> Result<Map, TiledError> { fn read_from_file(p: &Path) -> Result<Map, TiledError> {
let file = File::open(p).unwrap(); let file = File::open(p).unwrap();
...@@ -37,3 +37,14 @@ fn test_just_tileset() { ...@@ -37,3 +37,14 @@ fn test_just_tileset() {
let t = parse_tileset(File::open(Path::new("assets/tilesheet.tsx")).unwrap(), 1).unwrap(); let t = parse_tileset(File::open(Path::new("assets/tilesheet.tsx")).unwrap(), 1).unwrap();
assert_eq!(r.tilesets[0], t); assert_eq!(r.tilesets[0], t);
} }
#[test]
fn test_tile_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].tiles[0].properties.get("a tile property") {
v.clone()
} else {
String::new()
};
assert_eq!("123", prop_value);
}
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