From ee8d055be8326eb1561900bcca6acd9e38071f4a Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 27 Jun 2019 03:31:33 -0500 Subject: tiles can now animate --- src/tileset.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/tileset.rs') 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::() .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> { + if let Some(property) = self.properties.get(&id) { + let entitys_properties: HashMap = 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) + } } -- cgit v1.2.3