upgrade ron
This commit is contained in:
parent
651f213570
commit
db27d63b91
@ -64,8 +64,6 @@ log = { version = "0.4", features = ["release_max_level_info"] }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.7.2"
|
rand = "0.7.2"
|
||||||
serde = { version = "1", features = ["derive"]}
|
serde = { version = "1", features = ["derive"]}
|
||||||
ron = { git = "https://github.com/ron-rs/ron", rev = "b43c1074d517131fd0cfc1deb96e11f95d6f42d8" }
|
|
||||||
serde_json = "1.0"
|
|
||||||
env_logger = "0.7"
|
env_logger = "0.7"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
@ -8,7 +8,7 @@ edition = "2018"
|
|||||||
serde = "1"
|
serde = "1"
|
||||||
erased-serde = "0.3"
|
erased-serde = "0.3"
|
||||||
bevy_property_derive = { path = "bevy_property_derive" }
|
bevy_property_derive = { path = "bevy_property_derive" }
|
||||||
ron = { git = "https://github.com/ron-rs/ron", rev = "b43c1074d517131fd0cfc1deb96e11f95d6f42d8" }
|
ron = { git = "https://github.com/ron-rs/ron", rev = "35355ba7eb495f07282162826c29873154c2fa14" }
|
||||||
glam = { path = "../bevy_glam", features = ["serde"] }
|
glam = { path = "../bevy_glam", features = ["serde"] }
|
||||||
legion = { path = "../bevy_legion" }
|
legion = { path = "../bevy_legion" }
|
||||||
smallvec = { version = "1.4", features = ["serde"] }
|
smallvec = { version = "1.4", features = ["serde"] }
|
@ -12,7 +12,7 @@ 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"]}
|
||||||
ron = { git = "https://github.com/ron-rs/ron", rev = "b43c1074d517131fd0cfc1deb96e11f95d6f42d8" }
|
ron = { git = "https://github.com/ron-rs/ron", rev = "35355ba7eb495f07282162826c29873154c2fa14" }
|
||||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
@ -55,14 +55,20 @@ impl Scene {
|
|||||||
|
|
||||||
// TODO: move to AssetSaver when it is implemented
|
// TODO: move to AssetSaver when it is implemented
|
||||||
pub fn serialize_ron(&self, registry: &PropertyTypeRegistry) -> Result<String, ron::Error> {
|
pub fn serialize_ron(&self, registry: &PropertyTypeRegistry) -> Result<String, ron::Error> {
|
||||||
|
serialize_ron(SceneSerializer::new(self, registry))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_ron<S>(serialize: S) -> Result<String, ron::Error>
|
||||||
|
where
|
||||||
|
S: Serialize,
|
||||||
|
{
|
||||||
let pretty_config = ron::ser::PrettyConfig::default()
|
let pretty_config = ron::ser::PrettyConfig::default()
|
||||||
.with_decimal_floats(true)
|
.with_decimal_floats(true)
|
||||||
.with_indentor(" ".to_string())
|
.with_indentor(" ".to_string())
|
||||||
.with_new_line("\n".to_string());
|
.with_new_line("\n".to_string());
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut serializer = ron::ser::Serializer::new(&mut buf, Some(pretty_config), false)?;
|
let mut ron_serializer = ron::ser::Serializer::new(&mut buf, Some(pretty_config), false)?;
|
||||||
let scene_serializer = SceneSerializer::new(self, registry);
|
serialize.serialize(&mut ron_serializer)?;
|
||||||
scene_serializer.serialize(&mut serializer)?;
|
|
||||||
Ok(String::from_utf8(buf).unwrap())
|
Ok(String::from_utf8(buf).unwrap())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
property::{ron::deserialize_dynamic_properties, PropertyTypeRegistry},
|
property::{ron::deserialize_dynamic_properties, PropertyTypeRegistry},
|
||||||
|
scene::serialize_ron,
|
||||||
type_registry::TypeRegistry,
|
type_registry::TypeRegistry,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -61,13 +62,13 @@ fn setup(type_registry: Res<TypeRegistry>) {
|
|||||||
// All properties can be serialized.
|
// All properties can be serialized.
|
||||||
// If you #[derive(Properties)] your type doesn't even need to directly implement the Serde trait!
|
// If you #[derive(Properties)] your type doesn't even need to directly implement the Serde trait!
|
||||||
let registry = type_registry.property.read().unwrap();
|
let registry = type_registry.property.read().unwrap();
|
||||||
let ron_string = serialize_ron(&test, ®istry).unwrap();
|
let ron_string = serialize_property(&test, ®istry);
|
||||||
println!("{}\n", ron_string);
|
println!("{}\n", ron_string);
|
||||||
|
|
||||||
// Dynamic properties can be deserialized
|
// Dynamic properties can be deserialized
|
||||||
let dynamic_properties = deserialize_dynamic_properties(&ron_string, ®istry).unwrap();
|
let dynamic_properties = deserialize_dynamic_properties(&ron_string, ®istry).unwrap();
|
||||||
|
|
||||||
let round_tripped = serialize_ron(&dynamic_properties, ®istry).unwrap();
|
let round_tripped = serialize_property(&dynamic_properties, ®istry);
|
||||||
println!("{}", round_tripped);
|
println!("{}", round_tripped);
|
||||||
assert_eq!(ron_string, round_tripped);
|
assert_eq!(ron_string, round_tripped);
|
||||||
|
|
||||||
@ -82,24 +83,16 @@ fn setup(type_registry: Res<TypeRegistry>) {
|
|||||||
seq.apply(&patch);
|
seq.apply(&patch);
|
||||||
assert_eq!(seq[0], 3);
|
assert_eq!(seq[0], 3);
|
||||||
|
|
||||||
let ron_string = serialize_ron(&patch, ®istry).unwrap();
|
let ron_string = serialize_property(&patch, ®istry);
|
||||||
println!("{}\n", ron_string);
|
println!("{}\n", ron_string);
|
||||||
let dynamic_properties = deserialize_dynamic_properties(&ron_string, ®istry).unwrap();
|
let dynamic_properties = deserialize_dynamic_properties(&ron_string, ®istry).unwrap();
|
||||||
let round_tripped = serialize_ron(&dynamic_properties, ®istry).unwrap();
|
let round_tripped = serialize_property(&dynamic_properties, ®istry);
|
||||||
assert_eq!(ron_string, round_tripped);
|
assert_eq!(ron_string, round_tripped);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_ron<T>(property: &T, registry: &PropertyTypeRegistry) -> Result<String, ron::Error>
|
fn serialize_property<T>(property: &T, registry: &PropertyTypeRegistry) -> String
|
||||||
where
|
where
|
||||||
T: Property,
|
T: Property,
|
||||||
{
|
{
|
||||||
let pretty_config = ron::ser::PrettyConfig::default().with_decimal_floats(true);
|
serialize_ron(property.serializable(registry).borrow()).unwrap()
|
||||||
let mut buf = Vec::new();
|
|
||||||
let mut serializer = ron::ser::Serializer::new(&mut buf, Some(pretty_config), false)?;
|
|
||||||
property
|
|
||||||
.serializable(registry)
|
|
||||||
.borrow()
|
|
||||||
.serialize(&mut serializer)?;
|
|
||||||
let ron_string = String::from_utf8(buf).unwrap();
|
|
||||||
Ok(ron_string)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user