summaryrefslogtreecommitdiff
path: root/src/property.rs
blob: b57d54c7bd2a68cb5207fd1995856908c932b1e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use xml::reader::XmlEvent;

use crate::xmlelements::XMLElements;

#[derive(Debug, Clone, PartialEq)]
pub struct Property {
    pub entity: Option<String>,
    pub rotation: f32,
    pub keyframe: Option<usize>,
    pub delay: Option<usize>,
    pub spawn: Option<String>,
    pub visible: Option<bool>,
}

impl Property {
    pub fn new(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 {
            rotation: 0.0,
            entity,
            keyframe,
            delay,
            spawn,
            visible,
        }
    }
}

impl Default for Property {
    fn default() -> Property {
        Property {
            rotation: 0.0,
            entity: None,
            keyframe: None,
            delay: None,
            spawn: None,
            visible: None,
        }
    }
}