summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tileset.rs7
-rw-r--r--src/xmlelements.rs27
2 files changed, 19 insertions, 15 deletions
diff --git a/src/tileset.rs b/src/tileset.rs
index a5c00af..44941df 100644
--- a/src/tileset.rs
+++ b/src/tileset.rs
@@ -3,7 +3,7 @@ use ggez::graphics::Rect;
use std::collections::HashMap;
use crate::constants;
-use crate::xmlelements::{XMLElements, Property};
+use crate::xmlelements::{Property, XMLElements};
pub struct Tileset {
tiles: HashMap<usize, Rect>,
@@ -45,7 +45,10 @@ impl Tileset {
let mut properties = HashMap::new();
for tile_element in elements.get_elements("tile") {
- let tile_id = XMLElements::get_attribute(&tile_element, "id").unwrap().parse().unwrap();
+ let tile_id = XMLElements::get_attribute(&tile_element, "id")
+ .unwrap()
+ .parse()
+ .unwrap();
let property_elements = elements.get_children(&tile_element, "property");
diff --git a/src/xmlelements.rs b/src/xmlelements.rs
index bf9a213..d05e9ff 100644
--- a/src/xmlelements.rs
+++ b/src/xmlelements.rs
@@ -14,11 +14,18 @@ pub struct Property {
impl Property {
pub fn new(property_elements: Vec<XmlEvent>) -> Property {
-
- let entity = XMLElements::get_attribute_value(&property_elements, "entity").unwrap().parse().unwrap();
- let keyframe =
- XMLElements::get_attribute_value(&property_elements, "keyframe").unwrap().parse().unwrap();
- let delay = XMLElements::get_attribute_value(&property_elements, "delay").unwrap().parse().unwrap();
+ let entity = XMLElements::get_attribute_value(&property_elements, "entity")
+ .unwrap()
+ .parse()
+ .unwrap();
+ let keyframe = XMLElements::get_attribute_value(&property_elements, "keyframe")
+ .unwrap()
+ .parse()
+ .unwrap();
+ let delay = XMLElements::get_attribute_value(&property_elements, "delay")
+ .unwrap()
+ .parse()
+ .unwrap();
Property {
entity,
@@ -126,18 +133,12 @@ impl XMLElements {
}
}
- pub fn get_attribute_value(
- elements: &Vec<XmlEvent>,
- attribute_name: &str,
- ) -> Result<String, ()> {
+ pub fn get_attribute_value(elements: &[XmlEvent], attribute_name: &str) -> Result<String, ()> {
let element = elements
.iter()
.find(|e| {
if let StartElement { attributes, .. } = e {
- attributes
- .iter()
- .find(|a| a.value == attribute_name)
- .is_some()
+ attributes.iter().any(|a| a.value == attribute_name)
} else {
false
}