diff --git a/crates/bevy_legion/legion_core/src/serialize/ser.rs b/crates/bevy_legion/legion_core/src/serialize/ser.rs index 8db3e89017..3116bb993e 100644 --- a/crates/bevy_legion/legion_core/src/serialize/ser.rs +++ b/crates/bevy_legion/legion_core/src/serialize/ser.rs @@ -8,6 +8,14 @@ use crate::{ }; use serde::{ser::SerializeStruct, Serialize, Serializer}; +impl Serialize for Entity { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer { + serializer.serialize_u32(self.index()) + } +} + /// Implements `Serialize` and can be passed to a `serde::Serializer`. pub struct WorldSerializable<'a, 'b, CS: WorldSerializer> { world_serializer: &'b CS, diff --git a/crates/bevy_property/Cargo.toml b/crates/bevy_property/Cargo.toml index 89db925dc9..773a399473 100644 --- a/crates/bevy_property/Cargo.toml +++ b/crates/bevy_property/Cargo.toml @@ -10,4 +10,7 @@ edition = "2018" serde = "1" erased-serde = "0.3" bevy_property_derive = { path = "bevy_property_derive" } -ron = { path = "../ron" } \ No newline at end of file +ron = { path = "../ron" } +glam = { path = "../bevy_glam" } +legion = { path = "../bevy_legion" } +smallvec = { version = "1.4", features = ["serde"] } \ No newline at end of file diff --git a/crates/bevy_property/src/impl_property_glam.rs b/crates/bevy_property/src/impl_property_glam.rs new file mode 100644 index 0000000000..1270bf9455 --- /dev/null +++ b/crates/bevy_property/src/impl_property_glam.rs @@ -0,0 +1,9 @@ +use crate::{impl_property, AsProperties, Properties, Property}; +use glam::{Mat3, Mat4, Quat, Vec2, Vec3}; +use std::any::Any; + +impl_property!(Vec2); +impl_property!(Vec3); +impl_property!(Mat3); +impl_property!(Mat4); +impl_property!(Quat); diff --git a/crates/bevy_property/src/impl_property_legion.rs b/crates/bevy_property/src/impl_property_legion.rs new file mode 100644 index 0000000000..227e10528f --- /dev/null +++ b/crates/bevy_property/src/impl_property_legion.rs @@ -0,0 +1,5 @@ +use crate::{impl_property, AsProperties, Properties, Property}; +use legion::prelude::Entity; +use std::any::Any; + +impl_property!(Entity); diff --git a/crates/bevy_property/src/impl_property_smallvec.rs b/crates/bevy_property/src/impl_property_smallvec.rs new file mode 100644 index 0000000000..d9752e28c4 --- /dev/null +++ b/crates/bevy_property/src/impl_property_smallvec.rs @@ -0,0 +1,43 @@ +use crate::{AsProperties, Properties, Property}; +use smallvec::{SmallVec, Array}; +use std::any::Any; +use serde::Serialize; + +impl Property for SmallVec +where + T: Clone + Send + Sync + Serialize + 'static + Array, + I: Send + Sync + Clone + Serialize + 'static +{ + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = prop.clone(); + } + } +} + +impl AsProperties for SmallVec where T: Array { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} \ No newline at end of file diff --git a/crates/bevy_property/src/impl_property_std.rs b/crates/bevy_property/src/impl_property_std.rs new file mode 100644 index 0000000000..f4b6654fea --- /dev/null +++ b/crates/bevy_property/src/impl_property_std.rs @@ -0,0 +1,677 @@ +use crate::{AsProperties, Properties, Property, impl_property}; +use serde::Serialize; +use std::{ + any::Any, + collections::{BTreeMap, HashMap, HashSet, VecDeque}, + hash::Hash, +}; + +impl Property for usize { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for usize { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for u64 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for u64 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for u32 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for u32 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for u16 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for u16 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for u8 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for u8 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for isize { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for isize { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for i64 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for i64 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for i32 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for i32 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for i16 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for i16 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for i8 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for i8 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for f32 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for f32 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl Property for f64 { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = *prop; + } else if let Some(prop) = value.downcast_ref::() { + *self = *prop as Self; + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } +} + +impl AsProperties for f64 { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl_property!(String); +impl_property!(bool); +impl_property!(Vec where T: Clone + Send + Sync + Serialize + 'static); +impl_property!(VecDeque where T: Clone + Send + Sync + Serialize + 'static); +impl_property!(HashSet where T: Clone + Eq + Send + Sync + Hash + Serialize + 'static); +impl_property!(HashMap where + K: Clone + Eq + Send + Sync + Hash + Serialize + 'static, + V: Clone + Send + Sync + Serialize + 'static,); +impl_property!(BTreeMap where + K: Clone + Ord + Send + Sync + Serialize + 'static, + V: Clone + Send + Sync + Serialize + 'static); + +impl AsProperties for Vec { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl AsProperties for VecDeque { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl AsProperties for HashSet { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl AsProperties for HashMap { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} + +impl AsProperties for BTreeMap { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } +} diff --git a/crates/bevy_property/src/lib.rs b/crates/bevy_property/src/lib.rs index c5703e6a37..2309697cef 100644 --- a/crates/bevy_property/src/lib.rs +++ b/crates/bevy_property/src/lib.rs @@ -2,12 +2,20 @@ mod property; mod properties; mod dynamic_properties; mod type_registry; +mod impl_property_std; +mod impl_property_smallvec; +mod impl_property_glam; +mod impl_property_legion; pub mod ron; pub use property::*; pub use properties::*; pub use dynamic_properties::*; pub use type_registry::*; +pub use impl_property_std::*; +pub use impl_property_glam::*; +pub use impl_property_smallvec::*; +pub use impl_property_legion::*; pub use bevy_property_derive::*; pub use serde; \ No newline at end of file diff --git a/crates/bevy_property/src/property.rs b/crates/bevy_property/src/property.rs index 4ffc0081aa..31e8764ecd 100644 --- a/crates/bevy_property/src/property.rs +++ b/crates/bevy_property/src/property.rs @@ -41,892 +41,92 @@ impl PropertyVal for dyn Property { } } -impl Property for usize { - #[inline] - fn any(&self) -> &dyn Any { - self - } +// used by impl_property +#[allow(unused_macros)] +macro_rules! as_item { ($i:item) => {$i} } - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); +#[macro_export] +macro_rules! impl_property { + ($ty:ident) => { + impl Property for $ty { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = prop.clone(); + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } } - } -} - -impl AsProperties for usize { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for u64 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); + + impl AsProperties for $ty { + fn as_properties(&self) -> Option<&dyn Properties> { + None + } } - } -} - -impl AsProperties for u64 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for u32 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); + }; + (@$trait_:ident [$($args:ident,)*] where [$($preds:tt)+]) => { + impl_property! { + @as_item + impl<$($args),*> Property for $trait_<$($args),*> where $($args: ::std::any::Any + 'static,)* + $($preds)* { + #[inline] + fn any(&self) -> &dyn Any { + self + } + + #[inline] + fn any_mut(&mut self) -> &mut dyn Any { + self + } + + #[inline] + fn clone_prop(&self) -> Box { + Box::new(self.clone()) + } + + #[inline] + fn apply(&mut self, value: &dyn Property) { + self.set(value); + } + + fn set(&mut self, value: &dyn Property) { + let value = value.any(); + if let Some(prop) = value.downcast_ref::() { + *self = prop.clone(); + } else { + panic!("prop value is not {}", std::any::type_name::()); + } + } + } } - } -} - -impl AsProperties for u32 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for u16 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for u16 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for u8 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for u8 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for isize { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for isize { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for i64 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for i64 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for i32 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for i32 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for i16 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for i16 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for i8 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for i8 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for f32 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for f32 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for f64 { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = *prop; - } else if let Some(prop) = value.downcast_ref::() { - *self = *prop as Self; - } else { - panic!("prop value is not {}", std::any::type_name::()); - } - } -} - -impl AsProperties for f64 { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for String { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = prop.clone(); - } - } -} - -impl AsProperties for String { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for bool { - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = prop.clone(); - } - } -} - -impl AsProperties for bool { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for Vec -where - T: Clone + Send + Sync + Serialize + 'static, -{ - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = prop.clone(); - } - } -} - -impl AsProperties for Vec { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for VecDeque -where - T: Clone + Send + Sync + Serialize + 'static, -{ - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = prop.clone(); - } - } -} - -impl AsProperties for VecDeque { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for HashSet -where - K: Clone + Eq + Send + Sync + Hash + Serialize + 'static, -{ - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = prop.clone(); - } - } -} - -impl AsProperties for HashSet { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for HashMap -where - K: Clone + Eq + Send + Sync + Hash + Serialize + 'static, - V: Clone + Send + Sync + Serialize + 'static, -{ - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = prop.clone(); - } - } -} - -impl AsProperties for HashMap { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } -} - -impl Property for BTreeMap -where - K: Clone + Ord + Send + Sync + Serialize + 'static, - V: Clone + Send + Sync + Serialize + 'static, -{ - #[inline] - fn any(&self) -> &dyn Any { - self - } - - #[inline] - fn any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn clone_prop(&self) -> Box { - Box::new(self.clone()) - } - - #[inline] - fn apply(&mut self, value: &dyn Property) { - self.set(value); - } - - fn set(&mut self, value: &dyn Property) { - let value = value.any(); - if let Some(prop) = value.downcast_ref::() { - *self = prop.clone(); - } - } -} - -impl AsProperties for BTreeMap { - fn as_properties(&self) -> Option<&dyn Properties> { - None - } + }; + (@as_item $i:item) => { $i }; + + ( + $trait_:ident < $($args:ident),* $(,)* > + where $($preds:tt)+ + ) => { + impl_property! { @$trait_ [$($args,)*] where [$($preds)*] } + }; } diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index e7050827c4..f88d2b7db4 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -8,10 +8,11 @@ edition = "2018" [dependencies] # bevy bevy_app = { path = "../bevy_app" } -bevy_core = { path = "../bevy_core" } -bevy_transform = { path = "../bevy_transform" } bevy_asset = { path = "../bevy_asset" } +bevy_core = { path = "../bevy_core" } bevy_derive = { path = "../bevy_derive" } +bevy_property = { path = "../bevy_property" } +bevy_transform = { path = "../bevy_transform" } bevy_window = { path = "../bevy_window" } legion = { path = "../bevy_legion" } diff --git a/crates/bevy_render/src/renderable.rs b/crates/bevy_render/src/renderable.rs index 8470184d97..08e8ee057b 100644 --- a/crates/bevy_render/src/renderable.rs +++ b/crates/bevy_render/src/renderable.rs @@ -1,12 +1,13 @@ use crate::{pipeline::PipelineDescriptor, render_resource::RenderResourceAssignments}; use bevy_asset::Handle; +use bevy_property::Properties; +#[derive(Properties)] pub struct Renderable { pub is_visible: bool, pub is_instanced: bool, - - // TODO: make these hidden if possible pub pipelines: Vec>, + #[prop(ignore)] pub render_resource_assignments: RenderResourceAssignments, } diff --git a/crates/bevy_scene/src/scene.rs b/crates/bevy_scene/src/scene.rs index 5958d9d352..ae2ca10c3e 100644 --- a/crates/bevy_scene/src/scene.rs +++ b/crates/bevy_scene/src/scene.rs @@ -88,4 +88,15 @@ impl Scene { Ok(()) } + + // TODO: move to AssetSaver when it is implemented + pub fn serialize_ron(&self) -> Result { + let pretty_config = ron::ser::PrettyConfig::default() + .with_decimal_floats(true) + .with_new_line("\n".to_string()); + let mut buf = Vec::new(); + let mut serializer = ron::ser::Serializer::new(&mut buf, Some(pretty_config), true)?; + self.serialize(&mut serializer)?; + Ok(String::from_utf8(buf).unwrap()) + } } diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 19113b19fe..00273adb17 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -10,6 +10,7 @@ use std::{cell::RefCell, path::Path, rc::Rc}; pub struct SceneLoader { property_type_registry: PropertyTypeRegistryContext, } + impl FromResources for SceneLoader { fn from_resources(resources: &Resources) -> Self { let property_type_registry = resources.get::().unwrap(); @@ -43,4 +44,4 @@ impl AssetLoader for SceneLoader { static EXTENSIONS: &[&str] = &["scn"]; EXTENSIONS } -} +} \ No newline at end of file diff --git a/crates/bevy_transform/Cargo.toml b/crates/bevy_transform/Cargo.toml index ce1d0bc046..0597a8300a 100644 --- a/crates/bevy_transform/Cargo.toml +++ b/crates/bevy_transform/Cargo.toml @@ -9,10 +9,11 @@ license = "MIT" [dependencies] legion = { path = "../bevy_legion", features = ["serialize"]} glam = { path = "../bevy_glam" } +bevy_property = { path = "../bevy_property" } log = "0.4" rayon = "1.2" serde = { version = "1", features = ["derive"] } -smallvec = "1.4" +smallvec = { version = "1.4", features = ["serde"] } shrinkwraprs = "0.2" [dev-dependencies] diff --git a/crates/bevy_transform/src/components/children.rs b/crates/bevy_transform/src/components/children.rs index 731253a2aa..76c835ab90 100644 --- a/crates/bevy_transform/src/components/children.rs +++ b/crates/bevy_transform/src/components/children.rs @@ -1,8 +1,9 @@ use crate::ecs::prelude::*; use shrinkwraprs::Shrinkwrap; use smallvec::SmallVec; +use bevy_property::Properties; -#[derive(Shrinkwrap, Default, Clone)] +#[derive(Shrinkwrap, Default, Clone, Properties)] #[shrinkwrap(mutable)] pub struct Children(pub SmallVec<[Entity; 8]>); diff --git a/crates/bevy_transform/src/components/local_to_parent.rs b/crates/bevy_transform/src/components/local_to_parent.rs index f9ce8783f0..1381f8f069 100644 --- a/crates/bevy_transform/src/components/local_to_parent.rs +++ b/crates/bevy_transform/src/components/local_to_parent.rs @@ -1,8 +1,9 @@ use crate::math::Mat4; use shrinkwraprs::Shrinkwrap; use std::fmt; +use bevy_property::Properties; -#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy)] +#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)] #[shrinkwrap(mutable)] pub struct LocalToParent(pub Mat4); diff --git a/crates/bevy_transform/src/components/local_to_world.rs b/crates/bevy_transform/src/components/local_to_world.rs index 05d230d3a0..99c0df5db8 100644 --- a/crates/bevy_transform/src/components/local_to_world.rs +++ b/crates/bevy_transform/src/components/local_to_world.rs @@ -1,8 +1,9 @@ use crate::math::Mat4; use shrinkwraprs::Shrinkwrap; use std::fmt; +use bevy_property::Properties; -#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy)] +#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)] #[shrinkwrap(mutable)] pub struct LocalToWorld(pub Mat4); diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 8761e346cb..33dab00c42 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] bevy_app = { path = "../bevy_app" } bevy_asset = { path = "../bevy_asset" } +bevy_component_registry = { path = "../bevy_component_registry" } bevy_core = { path = "../bevy_core" } bevy_derive = { path = "../bevy_derive" } bevy_text = { path = "../bevy_text" } diff --git a/examples/scene/load_scene.rs b/examples/scene/load_scene.rs index 1040f47087..f96e5b3850 100644 --- a/examples/scene/load_scene.rs +++ b/examples/scene/load_scene.rs @@ -1,5 +1,4 @@ use bevy::{component_registry::ComponentRegistryContext, prelude::*}; -use serde::Serialize; fn main() { App::build() @@ -44,9 +43,7 @@ fn serialize_scene(world: &mut World, resources: &mut Resources) { let component_registry = resources.get::().unwrap(); world .build() - .build_entity() .add(Test { x: 1.0, y: 2.0 }) - .add(Handle::::new()) .add(Foo { value: "hello".to_string(), }) @@ -54,10 +51,5 @@ fn serialize_scene(world: &mut World, resources: &mut Resources) { .add(Test { x: 3.0, y: 4.0 }); let scene = Scene::from_world(world, &component_registry.value.read().unwrap()); - let pretty_config = ron::ser::PrettyConfig::default().with_decimal_floats(true); - let mut buf = Vec::new(); - let mut serializer = ron::ser::Serializer::new(&mut buf, Some(pretty_config), true).unwrap(); - scene.serialize(&mut serializer).unwrap(); - let ron_string = String::from_utf8(buf).unwrap(); - println!("{}", ron_string); + println!("{}", scene.serialize_ron().unwrap()); }