summaryrefslogtreecommitdiff
path: root/src/tileset.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-06-18 07:23:10 -0500
committertom barrett <spalf0@gmail.com>2019-06-18 07:23:10 -0500
commitc510d4a406218c38e1146503473e9e10c282a56d (patch)
tree07ac460954a6919bb040b70ee791a9fe5473264a /src/tileset.rs
parent2ad96b7f882ff962f67a13c7c56a46df86cfe6e3 (diff)
much better way of receiving xml
Diffstat (limited to 'src/tileset.rs')
-rw-r--r--src/tileset.rs39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/tileset.rs b/src/tileset.rs
index 21e31d1..d4e652f 100644
--- a/src/tileset.rs
+++ b/src/tileset.rs
@@ -1,7 +1,7 @@
use ggez::filesystem::File;
use ggez::graphics::Rect;
-use std::io::BufReader;
-use xml::reader::{EventReader, XmlEvent};
+
+use crate::xmlelements::XMLElements;
pub struct Tileset {
pub tiles: Vec<Rect>,
@@ -11,29 +11,18 @@ pub struct Tileset {
impl Tileset {
pub fn new(file: File) -> Tileset {
- let mut tile_width = None;
- let mut tile_height = None;
- let mut columns = None;
- let mut height = None;
-
- for e in EventReader::new(BufReader::new(file)) {
- if let Ok(XmlEvent::StartElement { attributes, .. }) = e {
- for attribute in attributes {
- match attribute.name.local_name.as_str() {
- "columns" => columns = Some(attribute.value.parse::<usize>().unwrap()),
- "tilewidth" => tile_width = Some(attribute.value.parse::<f32>().unwrap()),
- "tileheight" => tile_height = Some(attribute.value.parse::<f32>().unwrap()),
- "height" => height = Some(attribute.value.parse::<usize>().unwrap()),
- _ => (),
- }
- }
- }
- }
-
- let columns = columns.unwrap();
- let tile_height = tile_height.unwrap();
- let tile_width = tile_width.unwrap();
- let height = height.unwrap();
+ let elements = XMLElements::new(file);
+
+ let columns = elements
+ .get_element_attribute("tileset", "columns")
+ .unwrap();
+ let height = elements.get_element_attribute("image", "height").unwrap();
+ let tile_width = elements
+ .get_element_attribute("tileset", "tilewidth")
+ .unwrap() as f32;
+ let tile_height = elements
+ .get_element_attribute("tileset", "tileheight")
+ .unwrap() as f32;
let rows = height / (tile_height as usize);