mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
prop: impl prop macro. add impls for glam, legion, smallvec
This commit is contained in:
parent
cb6638ba06
commit
f0cbe8cd86
18 changed files with 867 additions and 903 deletions
|
@ -8,6 +8,14 @@ use crate::{
|
|||
};
|
||||
use serde::{ser::SerializeStruct, Serialize, Serializer};
|
||||
|
||||
impl Serialize for Entity {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
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,
|
||||
|
|
|
@ -11,3 +11,6 @@ serde = "1"
|
|||
erased-serde = "0.3"
|
||||
bevy_property_derive = { path = "bevy_property_derive" }
|
||||
ron = { path = "../ron" }
|
||||
glam = { path = "../bevy_glam" }
|
||||
legion = { path = "../bevy_legion" }
|
||||
smallvec = { version = "1.4", features = ["serde"] }
|
9
crates/bevy_property/src/impl_property_glam.rs
Normal file
9
crates/bevy_property/src/impl_property_glam.rs
Normal file
|
@ -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);
|
5
crates/bevy_property/src/impl_property_legion.rs
Normal file
5
crates/bevy_property/src/impl_property_legion.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use crate::{impl_property, AsProperties, Properties, Property};
|
||||
use legion::prelude::Entity;
|
||||
use std::any::Any;
|
||||
|
||||
impl_property!(Entity);
|
43
crates/bevy_property/src/impl_property_smallvec.rs
Normal file
43
crates/bevy_property/src/impl_property_smallvec.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use crate::{AsProperties, Properties, Property};
|
||||
use smallvec::{SmallVec, Array};
|
||||
use std::any::Any;
|
||||
use serde::Serialize;
|
||||
|
||||
impl<T, I> Property for SmallVec<T>
|
||||
where
|
||||
T: Clone + Send + Sync + Serialize + 'static + Array<Item=I>,
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = prop.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsProperties for SmallVec<T> where T: Array {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
677
crates/bevy_property/src/impl_property_std.rs
Normal file
677
crates/bevy_property/src/impl_property_std.rs
Normal file
|
@ -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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<f64>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<f32>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsProperties for f64 {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl_property!(String);
|
||||
impl_property!(bool);
|
||||
impl_property!(Vec<T> where T: Clone + Send + Sync + Serialize + 'static);
|
||||
impl_property!(VecDeque<T> where T: Clone + Send + Sync + Serialize + 'static);
|
||||
impl_property!(HashSet<T> where T: Clone + Eq + Send + Sync + Hash + Serialize + 'static);
|
||||
impl_property!(HashMap<K, V> where
|
||||
K: Clone + Eq + Send + Sync + Hash + Serialize + 'static,
|
||||
V: Clone + Send + Sync + Serialize + 'static,);
|
||||
impl_property!(BTreeMap<K, V> where
|
||||
K: Clone + Ord + Send + Sync + Serialize + 'static,
|
||||
V: Clone + Send + Sync + Serialize + 'static);
|
||||
|
||||
impl<T> AsProperties for Vec<T> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsProperties for VecDeque<T> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<K> AsProperties for HashSet<K> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> AsProperties for HashMap<K, V> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> AsProperties for BTreeMap<K, V> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -41,635 +41,14 @@ impl PropertyVal for dyn Property {
|
|||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i8>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<i64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<i16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<isize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<usize>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u64>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u32>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u16>() {
|
||||
*self = *prop as Self;
|
||||
} else if let Some(prop) = value.downcast_ref::<u8>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<f64>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = *prop;
|
||||
} else if let Some(prop) = value.downcast_ref::<f32>() {
|
||||
*self = *prop as Self;
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsProperties for f64 {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Property for String {
|
||||
// used by impl_property
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! as_item { ($i:item) => {$i} }
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_property {
|
||||
($ty:ident) => {
|
||||
impl Property for $ty {
|
||||
#[inline]
|
||||
fn any(&self) -> &dyn Any {
|
||||
self
|
||||
|
@ -694,17 +73,23 @@ impl Property for String {
|
|||
let value = value.any();
|
||||
if let Some(prop) = value.downcast_ref::<Self>() {
|
||||
*self = prop.clone();
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsProperties for String {
|
||||
impl AsProperties for $ty {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Property for bool {
|
||||
}
|
||||
};
|
||||
(@$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
|
||||
|
@ -729,204 +114,19 @@ impl Property for bool {
|
|||
let value = value.any();
|
||||
if let Some(prop) = value.downcast_ref::<Self>() {
|
||||
*self = prop.clone();
|
||||
} else {
|
||||
panic!("prop value is not {}", std::any::type_name::<Self>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsProperties for bool {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Property for Vec<T>
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = prop.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsProperties for Vec<T> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Property for VecDeque<T>
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = prop.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsProperties for VecDeque<T> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<K> Property for HashSet<K>
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = prop.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K> AsProperties for HashSet<K> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Property for HashMap<K, V>
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = prop.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> AsProperties for HashMap<K, V> {
|
||||
fn as_properties(&self) -> Option<&dyn Properties> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Property for BTreeMap<K, V>
|
||||
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<dyn Property> {
|
||||
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>() {
|
||||
*self = prop.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> AsProperties for BTreeMap<K, V> {
|
||||
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)*] }
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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" }
|
||||
|
||||
|
|
|
@ -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<Handle<PipelineDescriptor>>,
|
||||
#[prop(ignore)]
|
||||
pub render_resource_assignments: RenderResourceAssignments,
|
||||
}
|
||||
|
||||
|
|
|
@ -88,4 +88,15 @@ impl Scene {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: move to AssetSaver when it is implemented
|
||||
pub fn serialize_ron(&self) -> Result<String, ron::Error> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<PropertyTypeRegistryContext>().unwrap();
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]>);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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::<ComponentRegistryContext>().unwrap();
|
||||
world
|
||||
.build()
|
||||
.build_entity()
|
||||
.add(Test { x: 1.0, y: 2.0 })
|
||||
.add(Handle::<Mesh>::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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue