summaryrefslogtreecommitdiff
path: root/src/tileset.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-06-27 03:31:33 -0500
committertom barrett <spalf0@gmail.com>2019-06-27 03:31:33 -0500
commitee8d055be8326eb1561900bcca6acd9e38071f4a (patch)
treeadc6da1976866de4b3bf436f99e6eac673af2df3 /src/tileset.rs
parentf7bbf5646c8220bca2fbd9451d5c234049cf9225 (diff)
tiles can now animate
Diffstat (limited to 'src/tileset.rs')
-rw-r--r--src/tileset.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/tileset.rs b/src/tileset.rs
index 44941df..548cde6 100644
--- a/src/tileset.rs
+++ b/src/tileset.rs
@@ -47,12 +47,12 @@ impl Tileset {
for tile_element in elements.get_elements("tile") {
let tile_id = XMLElements::get_attribute(&tile_element, "id")
.unwrap()
- .parse()
+ .parse::<usize>()
.unwrap();
let property_elements = elements.get_children(&tile_element, "property");
- properties.insert(tile_id, Property::new(property_elements));
+ properties.insert(tile_id + 1, Property::new(property_elements));
}
Tileset { tiles, properties }
@@ -61,4 +61,27 @@ impl Tileset {
pub fn get(&self, id: usize) -> Rect {
*self.tiles.get(&id).unwrap()
}
+
+ pub fn get_animations(&self, id: usize) -> Option<Vec<(usize, Rect)>> {
+ if let Some(property) = self.properties.get(&id) {
+ let entitys_properties: HashMap<usize, Property> = self
+ .properties
+ .clone()
+ .into_iter()
+ .filter(|(_, p)| p.entity == property.entity)
+ .collect();
+ Some(
+ entitys_properties
+ .iter()
+ .map(|(id, p)| (p.delay, self.get(*id)))
+ .collect(),
+ )
+ } else {
+ None
+ }
+ }
+
+ pub fn get_property(&self, id: usize) -> Option<&Property> {
+ self.properties.get(&id)
+ }
}