summaryrefslogtreecommitdiff
path: root/src/property.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-01 09:14:17 -0500
committertom barrett <spalf0@gmail.com>2019-07-01 09:14:17 -0500
commit0947ce5a918207efeaf2a4f67a1cc410795f057a (patch)
tree30d601261754e236fc064faa9138eec9d1314d7c /src/property.rs
parent4b01b87d8aca041304c927560095af92feb406da (diff)
simpilfied interfaces and added new xml properties
Diffstat (limited to 'src/property.rs')
-rw-r--r--src/property.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/property.rs b/src/property.rs
new file mode 100644
index 0000000..fb4e912
--- /dev/null
+++ b/src/property.rs
@@ -0,0 +1,44 @@
+use xml::reader::XmlEvent;
+
+use crate::xmlelements::XMLElements;
+
+#[derive(Debug, Clone)]
+pub struct Property {
+ pub tile_id: usize,
+ pub entity: Option<String>,
+ pub keyframe: Option<usize>,
+ pub delay: Option<usize>,
+ pub spawn: Option<String>,
+ pub visible: Option<bool>,
+}
+
+impl Property {
+ pub fn new(tile_id: usize, property_elements: Vec<XmlEvent>) -> Property {
+ let entity = match XMLElements::get_attribute_value(&property_elements, "entity") {
+ Ok(entity) => entity.parse().ok(),
+ Err(_) => None,
+ };
+ let keyframe = match XMLElements::get_attribute_value(&property_elements, "keyframe") {
+ Ok(keyframe) => keyframe.parse().ok(),
+ Err(_) => None,
+ };
+ let delay = match XMLElements::get_attribute_value(&property_elements, "delay") {
+ Ok(delay) => delay.parse().ok(),
+ Err(_) => None,
+ };
+ let spawn = XMLElements::get_attribute_value(&property_elements, "spawn").ok();
+ let visible = match XMLElements::get_attribute_value(&property_elements, "visible") {
+ Ok(visible) => visible.parse().ok(),
+ Err(_) => None,
+ };
+
+ Property {
+ tile_id,
+ entity,
+ keyframe,
+ delay,
+ spawn,
+ visible,
+ }
+ }
+}