use ggez::graphics::Rect; use xml::reader::XmlEvent; use crate::xmlelements::XMLElements; #[derive(Clone, Debug, PartialEq)] pub struct Tile { pub source: Rect, pub properties: Properties, } impl Tile { pub fn new(source: Rect, properties: Properties) -> Tile { Tile { source, properties } } pub fn flip(&mut self) { self.source.x *= -1.0; self.source.x -= self.source.w; } } impl Default for Tile { fn default() -> Tile { Tile::new(Rect::zero(), Properties::default()) } } #[derive(Debug, Clone, PartialEq)] pub struct Properties { pub entity: Option, pub rotation: f32, pub keyframe: Option, pub delay: Option, pub spawn: Option, pub visible: Option, } impl Properties { pub fn new(properties_elements: Vec) -> Properties { let entity = match XMLElements::get_attribute_value(&properties_elements, "entity") { Ok(entity) => entity.parse().ok(), Err(_) => None, }; let keyframe = match XMLElements::get_attribute_value(&properties_elements, "keyframe") { Ok(keyframe) => keyframe.parse().ok(), Err(_) => None, }; let delay = match XMLElements::get_attribute_value(&properties_elements, "delay") { Ok(delay) => delay.parse().ok(), Err(_) => None, }; let spawn = XMLElements::get_attribute_value(&properties_elements, "spawn").ok(); let visible = match XMLElements::get_attribute_value(&properties_elements, "visible") { Ok(visible) => visible.parse().ok(), Err(_) => None, }; Properties { rotation: 0.0, entity, keyframe, delay, spawn, visible, } } } impl Default for Properties { fn default() -> Properties { Properties { rotation: 0.0, entity: None, keyframe: None, delay: None, spawn: None, visible: None, } } }