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