summaryrefslogtreecommitdiff
path: root/src/tileset.rs
diff options
context:
space:
mode:
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)
+ }
}