aboutsummaryrefslogtreecommitdiff
path: root/src/classes/gameobject.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/gameobject.rs')
-rw-r--r--src/classes/gameobject.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/classes/gameobject.rs b/src/classes/gameobject.rs
new file mode 100644
index 0000000..fde042d
--- /dev/null
+++ b/src/classes/gameobject.rs
@@ -0,0 +1,40 @@
+use anyhow::Result;
+use serde::Serialize;
+use crate::object::Value;
+use super::pptr::PPtr;
+
+#[derive(Debug, Serialize)]
+pub struct GameObject {
+ pub components: Vec<PPtr>,
+ pub layer: u32,
+ pub tag: u16,
+ pub name: String,
+ pub is_active: bool,
+}
+impl GameObject {
+ pub fn from_value(v: Value) -> Result<Self> {
+ let mut fields = v.as_class("GameObject").unwrap();
+ Ok(GameObject {
+ components: fields
+ .remove("m_Component")
+ .unwrap()
+ .as_array()
+ .unwrap()
+ .into_iter()
+ .map(|e| {
+ PPtr::from_value(
+ e.as_class("ComponentPair")
+ .unwrap()
+ .remove("component")
+ .unwrap(),
+ )
+ .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(),
+ })
+ }
+}