props: rename prop/props to property/properties

its longer but a bit clearer
This commit is contained in:
Carter Anderson 2020-05-22 15:36:48 -07:00
parent e514bd14fe
commit 159acf52af
13 changed files with 120 additions and 111 deletions

View File

@ -6,7 +6,7 @@ edition = "2018"
[features] [features]
default = ["headless", "wgpu", "winit"] default = ["headless", "wgpu", "winit"]
headless = ["asset", "core", "derive", "diagnostic", "gltf", "input", "pbr", "props", "render", "scene", "text", "transform", "ui", "window"] headless = ["asset", "core", "derive", "diagnostic", "gltf", "input", "pbr", "property", "render", "scene", "text", "transform", "ui", "window"]
asset = ["bevy_asset"] asset = ["bevy_asset"]
core = ["bevy_core"] core = ["bevy_core"]
derive = ["bevy_derive"] derive = ["bevy_derive"]
@ -14,7 +14,7 @@ diagnostic = ["bevy_diagnostic"]
gltf = ["bevy_gltf"] gltf = ["bevy_gltf"]
input = ["bevy_input"] input = ["bevy_input"]
pbr = ["bevy_pbr"] pbr = ["bevy_pbr"]
props = ["bevy_props"] property = ["bevy_property"]
render = ["bevy_render"] render = ["bevy_render"]
scene = ["bevy_scene"] scene = ["bevy_scene"]
text = ["bevy_text"] text = ["bevy_text"]
@ -41,7 +41,7 @@ bevy_diagnostic = { path = "crates/bevy_diagnostic", optional = true }
bevy_gltf = { path = "crates/bevy_gltf", optional = true } bevy_gltf = { path = "crates/bevy_gltf", optional = true }
bevy_input = { path = "crates/bevy_input", optional = true } bevy_input = { path = "crates/bevy_input", optional = true }
bevy_pbr = { path = "crates/bevy_pbr", optional = true } bevy_pbr = { path = "crates/bevy_pbr", optional = true }
bevy_props = { path = "crates/bevy_props", optional = true } bevy_property = { path = "crates/bevy_property", optional = true }
bevy_render = { path = "crates/bevy_render", optional = true } bevy_render = { path = "crates/bevy_render", optional = true }
bevy_scene = { path = "crates/bevy_scene", optional = true } bevy_scene = { path = "crates/bevy_scene", optional = true }
bevy_transform = { path = "crates/bevy_transform", optional = true } bevy_transform = { path = "crates/bevy_transform", optional = true }
@ -154,8 +154,8 @@ name = "load_scene"
path = "examples/scene/load_scene.rs" path = "examples/scene/load_scene.rs"
[[example]] [[example]]
name = "props" name = "properties"
path = "examples/scene/props.rs" path = "examples/scene/properties.rs"
[[example]] [[example]]
name = "shader_custom_material" name = "shader_custom_material"

View File

@ -62,7 +62,7 @@ pub fn derive_props(input: TokenStream) -> TokenStream {
}; };
let modules = get_modules(&ast); let modules = get_modules(&ast);
let bevy_props_path = get_path(&modules.bevy_props); let bevy_property_path = get_path(&modules.bevy_property);
let field_names = fields.iter().map(|field| field.ident let field_names = fields.iter().map(|field| field.ident
.as_ref() .as_ref()
@ -79,32 +79,32 @@ pub fn derive_props(input: TokenStream) -> TokenStream {
let struct_name = &ast.ident; let struct_name = &ast.ident;
TokenStream::from(quote! { TokenStream::from(quote! {
impl #impl_generics #bevy_props_path::Props for #struct_name#ty_generics { impl #impl_generics #bevy_property_path::Properties for #struct_name#ty_generics {
fn type_name(&self) -> &str { fn type_name(&self) -> &str {
std::any::type_name::<Self>() std::any::type_name::<Self>()
} }
fn prop(&self, name: &str) -> Option<&dyn #bevy_props_path::Prop> { fn prop(&self, name: &str) -> Option<&dyn #bevy_property_path::Property> {
match name { match name {
#(#field_names => Some(&self.#field_idents),)* #(#field_names => Some(&self.#field_idents),)*
_ => None, _ => None,
} }
} }
fn prop_mut(&mut self, name: &str) -> Option<&mut dyn #bevy_props_path::Prop> { fn prop_mut(&mut self, name: &str) -> Option<&mut dyn #bevy_property_path::Property> {
match name { match name {
#(#field_names => Some(&mut self.#field_idents),)* #(#field_names => Some(&mut self.#field_idents),)*
_ => None, _ => None,
} }
} }
fn prop_with_index(&self, index: usize) -> Option<&dyn #bevy_props_path::Prop> { fn prop_with_index(&self, index: usize) -> Option<&dyn #bevy_property_path::Property> {
match index { match index {
#(#field_indices => Some(&self.#field_idents),)* #(#field_indices => Some(&self.#field_idents),)*
_ => None, _ => None,
} }
} }
fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn #bevy_props_path::Prop> { fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn #bevy_property_path::Property> {
match index { match index {
#(#field_indices => Some(&mut self.#field_idents),)* #(#field_indices => Some(&mut self.#field_idents),)*
_ => None, _ => None,
@ -122,8 +122,8 @@ pub fn derive_props(input: TokenStream) -> TokenStream {
#field_count #field_count
} }
fn iter_props(&self) -> #bevy_props_path::PropIter { fn iter_props(&self) -> #bevy_property_path::PropertyIter {
#bevy_props_path::PropIter::new(self) #bevy_property_path::PropertyIter::new(self)
} }
} }
}) })

View File

@ -11,7 +11,7 @@ pub struct ModuleAttributeArgs {
#[darling(default)] #[darling(default)]
pub bevy_core: Option<String>, pub bevy_core: Option<String>,
#[darling(default)] #[darling(default)]
pub bevy_props: Option<String>, pub bevy_property: Option<String>,
#[darling(default)] #[darling(default)]
pub bevy_app: Option<String>, pub bevy_app: Option<String>,
#[darling(default)] #[darling(default)]
@ -27,7 +27,7 @@ pub struct Modules {
pub bevy_render: String, pub bevy_render: String,
pub bevy_asset: String, pub bevy_asset: String,
pub bevy_core: String, pub bevy_core: String,
pub bevy_props: String, pub bevy_property: String,
pub bevy_app: String, pub bevy_app: String,
pub legion: String, pub legion: String,
} }
@ -38,7 +38,7 @@ impl Modules {
bevy_asset: "bevy::asset".to_string(), bevy_asset: "bevy::asset".to_string(),
bevy_render: "bevy::render".to_string(), bevy_render: "bevy::render".to_string(),
bevy_core: "bevy::core".to_string(), bevy_core: "bevy::core".to_string(),
bevy_props: "bevy::props".to_string(), bevy_property: "bevy::property".to_string(),
bevy_app: "bevy::app".to_string(), bevy_app: "bevy::app".to_string(),
legion: "bevy".to_string(), legion: "bevy".to_string(),
} }
@ -49,7 +49,7 @@ impl Modules {
bevy_asset: "bevy_asset".to_string(), bevy_asset: "bevy_asset".to_string(),
bevy_render: "bevy_render".to_string(), bevy_render: "bevy_render".to_string(),
bevy_core: "bevy_core".to_string(), bevy_core: "bevy_core".to_string(),
bevy_props: "bevy_props".to_string(), bevy_property: "bevy_property".to_string(),
bevy_app: "bevy_app".to_string(), bevy_app: "bevy_app".to_string(),
legion: "legion".to_string(), legion: "legion".to_string(),
} }
@ -62,7 +62,7 @@ impl Default for ModuleAttributeArgs {
bevy_asset: None, bevy_asset: None,
bevy_render: None, bevy_render: None,
bevy_core: None, bevy_core: None,
bevy_props: None, bevy_property: None,
bevy_app: None, bevy_app: None,
legion: None, legion: None,
meta: true, meta: true,
@ -96,6 +96,10 @@ pub fn get_modules(ast: &DeriveInput) -> Modules {
modules.bevy_render = path; modules.bevy_render = path;
} }
if let Some(path) = module_attribute_args.bevy_property {
modules.bevy_property = path;
}
if let Some(path) = module_attribute_args.bevy_core { if let Some(path) = module_attribute_args.bevy_core {
modules.bevy_core = path; modules.bevy_core = path;
} }

View File

@ -1,5 +1,5 @@
[package] [package]
name = "bevy_props" name = "bevy_property"
version = "0.1.0" version = "0.1.0"
authors = ["Carter Anderson <mcanders1@gmail.com>"] authors = ["Carter Anderson <mcanders1@gmail.com>"]
edition = "2018" edition = "2018"

View File

@ -1,29 +1,29 @@
use std::{collections::HashMap, borrow::Cow}; use std::{collections::HashMap, borrow::Cow};
use crate::{Props, Prop, PropIter}; use crate::{Properties, Property, PropertyIter};
use serde::{Deserialize, Serialize, ser::SerializeMap}; use serde::{Deserialize, Serialize, ser::SerializeMap};
#[derive(Default)] #[derive(Default)]
pub struct DynamicProperties { pub struct DynamicProperties {
pub type_name: &'static str, pub type_name: &'static str,
pub props: Vec<(Cow<'static, str>, Box<dyn Prop>)>, pub props: Vec<(Cow<'static, str>, Box<dyn Property>)>,
pub prop_indices: HashMap<Cow<'static, str>, usize>, pub prop_indices: HashMap<Cow<'static, str>, usize>,
} }
impl DynamicProperties { impl DynamicProperties {
fn push(&mut self, name: &str, prop: Box<dyn Prop>) { fn push(&mut self, name: &str, prop: Box<dyn Property>) {
let name: Cow<'static, str> = Cow::Owned(name.to_string()); let name: Cow<'static, str> = Cow::Owned(name.to_string());
self.props.push((name.clone(), prop)); self.props.push((name.clone(), prop));
self.prop_indices.insert(name, self.props.len()); self.prop_indices.insert(name, self.props.len());
} }
pub fn set<T: Prop>(&mut self, name: &str, prop: T) { pub fn set<T: Property>(&mut self, name: &str, prop: T) {
if let Some(index) = self.prop_indices.get(name) { if let Some(index) = self.prop_indices.get(name) {
self.props[*index].1 = Box::new(prop); self.props[*index].1 = Box::new(prop);
} else { } else {
self.push(name, Box::new(prop)); self.push(name, Box::new(prop));
} }
} }
pub fn set_box(&mut self, name: &str, prop: Box<dyn Prop>) { pub fn set_box(&mut self, name: &str, prop: Box<dyn Property>) {
if let Some(index) = self.prop_indices.get(name) { if let Some(index) = self.prop_indices.get(name) {
self.props[*index].1 = prop; self.props[*index].1 = prop;
} else { } else {
@ -33,13 +33,13 @@ impl DynamicProperties {
} }
impl Props for DynamicProperties { impl Properties for DynamicProperties {
#[inline] #[inline]
fn type_name(&self) -> &str { fn type_name(&self) -> &str {
self.type_name self.type_name
} }
#[inline] #[inline]
fn prop(&self, name: &str) -> Option<&dyn Prop> { fn prop(&self, name: &str) -> Option<&dyn Property> {
if let Some(index) = self.prop_indices.get(name) { if let Some(index) = self.prop_indices.get(name) {
Some(&*self.props[*index].1) Some(&*self.props[*index].1)
} else { } else {
@ -48,7 +48,7 @@ impl Props for DynamicProperties {
} }
#[inline] #[inline]
fn prop_mut(&mut self, name: &str) -> Option<&mut dyn Prop> { fn prop_mut(&mut self, name: &str) -> Option<&mut dyn Property> {
if let Some(index) = self.prop_indices.get(name) { if let Some(index) = self.prop_indices.get(name) {
Some(&mut *self.props[*index].1) Some(&mut *self.props[*index].1)
} else { } else {
@ -57,12 +57,12 @@ impl Props for DynamicProperties {
} }
#[inline] #[inline]
fn prop_with_index(&self, index: usize) -> Option<&dyn Prop> { fn prop_with_index(&self, index: usize) -> Option<&dyn Property> {
self.props.get(index).map(|(_i, prop)| &**prop) self.props.get(index).map(|(_i, prop)| &**prop)
} }
#[inline] #[inline]
fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn Prop> { fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn Property> {
self.props.get_mut(index).map(|(_i, prop)| &mut **prop) self.props.get_mut(index).map(|(_i, prop)| &mut **prop)
} }
@ -76,8 +76,8 @@ impl Props for DynamicProperties {
self.props.len() self.props.len()
} }
fn iter_props(&self) -> PropIter { fn iter_props(&self) -> PropertyIter {
PropIter { PropertyIter {
props: self, props: self,
index: 0, index: 0,
} }

View File

@ -1,9 +1,9 @@
#![feature(min_specialization)] #![feature(min_specialization)]
mod prop; mod property;
mod props; mod properties;
mod dynamic_properties; mod dynamic_properties;
pub use prop::*; pub use property::*;
pub use props::*; pub use properties::*;
pub use dynamic_properties::*; pub use dynamic_properties::*;

View File

@ -1,23 +1,23 @@
use crate::{DynamicProperties, Prop, PropVal}; use crate::{DynamicProperties, Property, PropertyVal};
use serde::{ser::SerializeMap, Serialize}; use serde::{ser::SerializeMap, Serialize};
pub trait Props { pub trait Properties {
fn type_name(&self) -> &str; fn type_name(&self) -> &str;
fn prop(&self, name: &str) -> Option<&dyn Prop>; fn prop(&self, name: &str) -> Option<&dyn Property>;
fn prop_mut(&mut self, name: &str) -> Option<&mut dyn Prop>; fn prop_mut(&mut self, name: &str) -> Option<&mut dyn Property>;
fn prop_with_index(&self, index: usize) -> Option<&dyn Prop>; fn prop_with_index(&self, index: usize) -> Option<&dyn Property>;
fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn Prop>; fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn Property>;
fn prop_name(&self, index: usize) -> Option<&str>; fn prop_name(&self, index: usize) -> Option<&str>;
fn prop_len(&self) -> usize; fn prop_len(&self) -> usize;
fn iter_props(&self) -> PropIter; fn iter_props(&self) -> PropertyIter;
fn set_prop(&mut self, name: &str, value: &dyn Prop) { fn set_prop(&mut self, name: &str, value: &dyn Property) {
if let Some(prop) = self.prop_mut(name) { if let Some(prop) = self.prop_mut(name) {
prop.set(value); prop.set(value);
} else { } else {
panic!("prop does not exist: {}", name); panic!("prop does not exist: {}", name);
} }
} }
fn apply(&mut self, props: &dyn Props) { fn apply(&mut self, props: &dyn Properties) {
for (name, prop) in props.iter_props() { for (name, prop) in props.iter_props() {
self.set_prop(name, prop); self.set_prop(name, prop);
} }
@ -36,19 +36,19 @@ pub trait Props {
} }
} }
pub struct PropIter<'a> { pub struct PropertyIter<'a> {
pub(crate) props: &'a dyn Props, pub(crate) props: &'a dyn Properties,
pub(crate) index: usize, pub(crate) index: usize,
} }
impl<'a> PropIter<'a> { impl<'a> PropertyIter<'a> {
pub fn new(props: &'a dyn Props) -> Self { pub fn new(props: &'a dyn Properties) -> Self {
PropIter { props, index: 0 } PropertyIter { props, index: 0 }
} }
} }
impl<'a> Iterator for PropIter<'a> { impl<'a> Iterator for PropertyIter<'a> {
type Item = (&'a str, &'a dyn Prop); type Item = (&'a str, &'a dyn Property);
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.index < self.props.prop_len() { if self.index < self.props.prop_len() {
let prop = self.props.prop_with_index(self.index).unwrap(); let prop = self.props.prop_with_index(self.index).unwrap();
@ -61,14 +61,14 @@ impl<'a> Iterator for PropIter<'a> {
} }
} }
pub trait PropsVal { pub trait PropertiesVal {
fn prop_val<T: 'static>(&self, name: &str) -> Option<&T>; fn prop_val<T: 'static>(&self, name: &str) -> Option<&T>;
fn set_prop_val<T: 'static>(&mut self, name: &str, value: T); fn set_prop_val<T: 'static>(&mut self, name: &str, value: T);
} }
impl<P> PropsVal for P impl<P> PropertiesVal for P
where where
P: Props, P: Properties,
{ {
// #[inline] // #[inline]
fn prop_val<T: 'static>(&self, name: &str) -> Option<&T> { fn prop_val<T: 'static>(&self, name: &str) -> Option<&T> {
@ -84,11 +84,11 @@ where
} }
} }
pub struct SerializableProps<'a> { pub struct SerializableProperties<'a> {
pub props: &'a dyn Props, pub props: &'a dyn Properties,
} }
impl<'a> Serialize for SerializableProps<'a> { impl<'a> Serialize for SerializableProperties<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: serde::Serializer, S: serde::Serializer,

View File

@ -1,21 +1,21 @@
use serde::Serialize; use serde::Serialize;
use std::any::Any; use std::any::Any;
pub trait Prop: erased_serde::Serialize + Send + Sync + Any + 'static { pub trait Property: erased_serde::Serialize + Send + Sync + Any + 'static {
fn any(&self) -> &dyn Any; fn any(&self) -> &dyn Any;
fn any_mut(&mut self) -> &mut dyn Any; fn any_mut(&mut self) -> &mut dyn Any;
fn clone_prop(&self) -> Box<dyn Prop>; fn clone_prop(&self) -> Box<dyn Property>;
fn set(&mut self, value: &dyn Prop); fn set(&mut self, value: &dyn Property);
} }
erased_serde::serialize_trait_object!(Prop); erased_serde::serialize_trait_object!(Property);
pub trait PropVal { pub trait PropertyVal {
fn val<T: 'static>(&self) -> Option<&T>; fn val<T: 'static>(&self) -> Option<&T>;
fn set_val<T: 'static>(&mut self, value: T); fn set_val<T: 'static>(&mut self, value: T);
} }
impl PropVal for dyn Prop { impl PropertyVal for dyn Property {
// #[inline] // #[inline]
default fn val<T: 'static>(&self) -> Option<&T> { default fn val<T: 'static>(&self) -> Option<&T> {
self.any().downcast_ref::<T>() self.any().downcast_ref::<T>()
@ -31,7 +31,7 @@ impl PropVal for dyn Prop {
} }
} }
impl<T> Prop for T impl<T> Property for T
where where
T: Clone + Serialize + Send + Sync + Any + 'static, T: Clone + Serialize + Send + Sync + Any + 'static,
{ {
@ -44,11 +44,11 @@ where
self self
} }
#[inline] #[inline]
default fn clone_prop(&self) -> Box<dyn Prop> { default fn clone_prop(&self) -> Box<dyn Property> {
Box::new(self.clone()) Box::new(self.clone())
} }
#[inline] #[inline]
default fn set(&mut self, value: &dyn Prop) { default fn set(&mut self, value: &dyn Property) {
if let Some(prop) = value.any().downcast_ref::<T>() { if let Some(prop) = value.any().downcast_ref::<T>() {
*self = prop.clone(); *self = prop.clone();
} else { } else {
@ -57,8 +57,8 @@ where
} }
} }
impl Prop for usize { impl Property for usize {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -86,8 +86,8 @@ impl Prop for usize {
} }
} }
impl Prop for u64 { impl Property for u64 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -115,8 +115,8 @@ impl Prop for u64 {
} }
} }
impl Prop for u32 { impl Property for u32 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -144,8 +144,8 @@ impl Prop for u32 {
} }
} }
impl Prop for u16 { impl Property for u16 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -173,8 +173,8 @@ impl Prop for u16 {
} }
} }
impl Prop for u8 { impl Property for u8 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -202,8 +202,8 @@ impl Prop for u8 {
} }
} }
impl Prop for isize { impl Property for isize {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -231,8 +231,8 @@ impl Prop for isize {
} }
} }
impl Prop for i64 { impl Property for i64 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -260,8 +260,8 @@ impl Prop for i64 {
} }
} }
impl Prop for i32 { impl Property for i32 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -289,8 +289,8 @@ impl Prop for i32 {
} }
} }
impl Prop for i16 { impl Property for i16 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -318,8 +318,8 @@ impl Prop for i16 {
} }
} }
impl Prop for i8 { impl Property for i8 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -348,8 +348,8 @@ impl Prop for i8 {
} }
impl Prop for f32 { impl Property for f32 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;
@ -361,8 +361,8 @@ impl Prop for f32 {
} }
} }
impl Prop for f64 { impl Property for f64 {
fn set(&mut self, value: &dyn Prop) { fn set(&mut self, value: &dyn Property) {
let value = value.any(); let value = value.any();
if let Some(prop) = value.downcast_ref::<Self>() { if let Some(prop) = value.downcast_ref::<Self>() {
*self = *prop; *self = *prop;

View File

@ -7,7 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
bevy_app = { path = "../bevy_app" } bevy_app = { path = "../bevy_app" }
bevy_asset = { path = "../bevy_asset" } bevy_asset = { path = "../bevy_asset" }
bevy_props = { path = "../bevy_props" } bevy_property = { path = "../bevy_property" }
legion = { path = "../bevy_legion", features = ["serialize"] } legion = { path = "../bevy_legion", features = ["serialize"] }
serde = { version = "1.0", features = ["derive"]} serde = { version = "1.0", features = ["derive"]}
erased-serde = "0.3" erased-serde = "0.3"

View File

@ -2,7 +2,7 @@ use crate::{ComponentRegistry, ComponentRegistryContext, SceneDeserializer};
use anyhow::Result; use anyhow::Result;
use bevy_app::FromResources; use bevy_app::FromResources;
use bevy_asset::AssetLoader; use bevy_asset::AssetLoader;
use bevy_props::DynamicProperties; use bevy_property::DynamicProperties;
use legion::prelude::{Resources, World}; use legion::prelude::{Resources, World};
use serde::de::DeserializeSeed; use serde::de::DeserializeSeed;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};

View File

@ -1,6 +1,8 @@
use bevy::prelude::*; use bevy::{
use bevy_props::SerializableProps; prelude::*,
use bevy_scene::{DynamicScene, SceneEntity}; property::SerializableProperties,
scene::{DynamicScene, SceneEntity},
};
use serde::ser::Serialize; use serde::ser::Serialize;
fn main() { fn main() {
@ -10,7 +12,7 @@ fn main() {
.run(); .run();
} }
#[derive(Properties)] #[derive(Properties, Default)]
pub struct Test { pub struct Test {
a: usize, a: usize,
b: String, b: String,
@ -41,20 +43,23 @@ fn setup() {
assert_eq!(test.a, 3); assert_eq!(test.a, 3);
let ser = SerializableProps { props: &test }; let ser = SerializableProperties { props: &test };
let mut serializer = ron::ser::Serializer::new(Some(ron::ser::PrettyConfig::default()), false); let mut serializer = ron::ser::Serializer::new(Some(ron::ser::PrettyConfig::default()), false);
ser.serialize(&mut serializer).unwrap(); ser.serialize(&mut serializer).unwrap();
println!("{}", serializer.into_output_string()); let ron_string = serializer.into_output_string();
println!("{}", ron_string);
let dynamic_scene = DynamicScene { // let dynamic_scene = DynamicScene {
entities: vec![SceneEntity { // entities: vec![SceneEntity {
entity: 12345, // entity: 12345,
components: vec![patch], // components: vec![patch],
}], // }],
}; // };
let mut serializer = ron::ser::Serializer::new(Some(ron::ser::PrettyConfig::default()), false); // let mut serializer = ron::ser::Serializer::new(Some(ron::ser::PrettyConfig::default()), false);
dynamic_scene.entities.serialize(&mut serializer).unwrap(); // dynamic_scene.entities.serialize(&mut serializer).unwrap();
println!("{}", serializer.into_output_string()); // println!("{}", serializer.into_output_string());
let mut deserializer = ron::de::Deserializer::from_str(&ron_string).unwrap();
} }

View File

@ -61,8 +61,8 @@ pub use bevy_gltf as gltf;
pub use bevy_input as input; pub use bevy_input as input;
#[cfg(feature = "pbr")] #[cfg(feature = "pbr")]
pub use bevy_pbr as pbr; pub use bevy_pbr as pbr;
#[cfg(feature = "props")] #[cfg(feature = "property")]
pub use bevy_props as props; pub use bevy_property as property;
#[cfg(feature = "render")] #[cfg(feature = "render")]
pub use bevy_render as render; pub use bevy_render as render;
#[cfg(feature = "scene")] #[cfg(feature = "scene")]

View File

@ -11,8 +11,8 @@ pub use crate::derive::*;
pub use crate::diagnostic::DiagnosticsPlugin; pub use crate::diagnostic::DiagnosticsPlugin;
#[cfg(feature = "pbr")] #[cfg(feature = "pbr")]
pub use crate::pbr::{entity::*, light::Light, material::StandardMaterial}; pub use crate::pbr::{entity::*, light::Light, material::StandardMaterial};
#[cfg(feature = "props")] #[cfg(feature = "property")]
pub use crate::props::{Prop, Props, PropVal, PropsVal, DynamicProperties}; pub use crate::property::{Property, Properties, PropertyVal, PropertiesVal, DynamicProperties};
#[cfg(feature = "render")] #[cfg(feature = "render")]
pub use crate::render::{ pub use crate::render::{
draw_target, draw_target,