Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: deserialize DynamicEnum using index #12464

Merged
merged 9 commits into from
Mar 14, 2024
25 changes: 25 additions & 0 deletions crates/bevy_scene/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,31 @@ mod tests {
assert_eq!(1, dst_world.query::<&Baz>().iter(&dst_world).count());
}

#[test]
fn should_reserialize() {
let mut world = create_world();

world.spawn(MyComponent {
foo: [1, 2, 3],
bar: (1.3, 3.7),
baz: MyEnum::Tuple("Hello World!".to_string()),
});

let registry = world.resource::<AppTypeRegistry>();
let scene = DynamicScene::from_world(&world);
let serialized_scene1 = scene.serialize_ron(&registry.0).unwrap();

let scene_deserializer = SceneDeserializer {
type_registry: &registry.0.read(),
};
let mut deserializer = ron::de::Deserializer::from_str(&serialized_scene1).unwrap();
let deserialized_scene = scene_deserializer.deserialize(&mut deserializer).unwrap();

let serialized_scene2 = deserialized_scene.serialize_ron(&registry.0).unwrap();

assert_eq!(serialized_scene1, serialized_scene2);
}

#[test]
fn should_roundtrip_with_later_generations_and_obsolete_references() {
let mut world = create_world();
Expand Down
Loading