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
use crate::darksiders1::gfc; use std::{ convert::{TryFrom, TryInto}, sync::Arc, }; #[derive(Debug)] pub struct DraggableActorData { pub position: gfc::TVector3<f32>, pub initialized: bool, } impl From<DraggableActorData> for gfc::Value { fn from(data: DraggableActorData) -> Self { gfc::Value::Object(Arc::new(gfc::Object { classname: "DraggableActorData".to_string(), properties: vec![ prop!("Position", data.position.into()), prop!("Initialized", gfc::Value::Bool(data.initialized)), ], })) } } impl TryFrom<&gfc::Value> for DraggableActorData { type Error = (); fn try_from(value: &gfc::Value) -> Result<Self, Self::Error> { let object = value.as_object().ok_or(())?; if object.classname != "DraggableActorData" { return Err(()); } Ok(Self { position: object.get_property("Position").ok_or(())?.try_into()?, initialized: object .get_property("Initialized") .and_then(gfc::Value::as_bool) .ok_or(())?, }) } }