aboutsummaryrefslogtreecommitdiff
path: root/src/classes/gameobject.rs
blob: 94436fae50a4d574ef2605b38acf8efe224efa47 (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
use super::{FromValue, pptr::PPtr};
use crate::object::Value;
use anyhow::Result;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct GameObject {
    pub components: Vec<PPtr>,
    pub layer: u32,
    pub tag: u16,
    pub name: String,
    pub is_active: bool,
}
impl FromValue for GameObject {
    fn from_value(v: Value) -> Result<Self> {
        let mut fields = v.as_class("GameObject").unwrap();
        Ok(GameObject {
            components: fields
                .remove("m_Component")
                .unwrap()
                .as_class("vector")
                .unwrap()
                .remove("Array")
                .unwrap()
                .as_array()
                .unwrap()
                .into_iter()
                .map(|e| {
                    e.as_class("ComponentPair")
                        .unwrap()
                        .remove("component")
                        .unwrap()
                        .parse::<PPtr>()
                        .unwrap()
                })
                .collect(),
            layer: fields["m_Layer"].as_u32().unwrap(),
            tag: fields["m_Tag"].as_u16().unwrap(),
            name: fields["m_Name"].clone().as_string().unwrap(),
            is_active: fields["m_IsActive"].as_bool().unwrap(),
        })
    }
}