Skip to content
Snippets Groups Projects
Commit d0bfbfb8 authored by Doug Reeves's avatar Doug Reeves
Browse files

Load in properties from the tiles

parent 2ec9c563
No related branches found
No related tags found
No related merge requests found
......@@ -307,7 +307,7 @@ impl FromStr for Orientation {
}
/// A tileset, usually the tilesheet image.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq)]
pub struct Tileset {
/// The GID of the first tile stored
pub first_gid: u32,
......@@ -420,10 +420,11 @@ impl Tileset {
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq)]
pub struct Tile {
pub id: u32,
pub images: Vec<Image>
pub images: Vec<Image>,
pub properties: Properties,
}
impl Tile {
......@@ -435,12 +436,17 @@ impl Tile {
TiledError::MalformedAttributes("tile must have an id with the correct type".to_string()));
let mut images = Vec::new();
let mut properties = HashMap::new();
parse_tag!(parser, "tile",
"image" => |attrs| {
images.push(try!(Image::new(parser, attrs)));
Ok(())
});
Ok(Tile {id: i, images: images})
images.push(Image::new(parser, attrs)?);
Ok(())
},
"properties" => |_| {
properties = parse_properties(parser)?;
Ok(())
});
Ok(Tile {id: i, images: images, properties: properties})
}
}
......
......@@ -2,7 +2,7 @@ extern crate tiled;
use std::path::Path;
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> {
let file = File::open(p).unwrap();
......@@ -37,3 +37,14 @@ fn test_just_tileset() {
let t = parse_tileset(File::open(Path::new("assets/tilesheet.tsx")).unwrap(), 1).unwrap();
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