use super::{FromValue, pptr::PPtr}; use crate::object::Value; use anyhow::Result; use serde::Serialize; #[derive(Debug, Serialize)] pub struct GameObject { pub components: Vec, pub layer: u32, pub tag: u16, pub name: String, pub is_active: bool, } impl FromValue for GameObject { fn from_value(v: Value) -> Result { 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::() .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(), }) } }