Skip to content

Commit

Permalink
Fix issues with Reflect -> PartialReflect from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mweatherley committed Aug 27, 2024
1 parent 2d71527 commit 90b9dec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions crates/bevy_remote/src/builtin_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevy_ecs::{
use bevy_hierarchy::BuildChildren as _;
use bevy_reflect::{
serde::{ReflectSerializer, TypedReflectDeserializer},
Reflect, TypeRegistration, TypeRegistry,
PartialReflect, TypeRegistration, TypeRegistry,
};
use bevy_utils::HashMap;
use serde::de::DeserializeSeed as _;
Expand Down Expand Up @@ -245,7 +245,8 @@ pub fn process_remote_get_request(In(params): In<Option<Value>>, world: &World)
};

// Each component value serializes to a map with a single entry.
let reflect_serializer = ReflectSerializer::new(reflected, &type_registry);
let reflect_serializer =
ReflectSerializer::new(reflected.as_partial_reflect(), &type_registry);
let Value::Object(serialized_object) =
serde_json::to_value(&reflect_serializer).map_err(|err| BrpError {
code: error_codes::COMPONENT_ERROR,
Expand Down Expand Up @@ -538,7 +539,8 @@ fn serialize_components(
));
};

let reflect_serializer = ReflectSerializer::new(reflected, type_registry);
let reflect_serializer =
ReflectSerializer::new(reflected.as_partial_reflect(), type_registry);
let Value::Object(serialized_object) = serde_json::to_value(&reflect_serializer)? else {
return Err(anyhow!("Component `{}` could not be serialized", type_path));
};
Expand All @@ -554,14 +556,14 @@ fn serialize_components(
fn deserialize_components(
type_registry: &TypeRegistry,
components: HashMap<String, Value>,
) -> AnyhowResult<Vec<Box<dyn Reflect>>> {
) -> AnyhowResult<Vec<Box<dyn PartialReflect>>> {
let mut reflect_components = vec![];

for (component_path, component) in components {
let Some(component_type) = type_registry.get_with_type_path(&component_path) else {
return Err(anyhow!("Unknown component type: `{}`", component_path));
};
let reflected: Box<dyn Reflect> =
let reflected: Box<dyn PartialReflect> =
TypedReflectDeserializer::new(component_type, type_registry)
.deserialize(&component)
.unwrap();
Expand All @@ -576,7 +578,7 @@ fn deserialize_components(
fn insert_reflected_components(
type_registry: &TypeRegistry,
mut entity_world_mut: EntityWorldMut,
reflect_components: Vec<Box<dyn Reflect>>,
reflect_components: Vec<Box<dyn PartialReflect>>,
) -> AnyhowResult<()> {
for reflected in reflect_components {
let reflect_component =
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_remote/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ async fn process_request_batch(
let mut responses = Vec::new();

for request in requests {
responses.push(process_single_request(request, &request_sender).await?);
responses.push(process_single_request(request, request_sender).await?);
}

serde_json::to_string(&responses)?
Expand Down

0 comments on commit 90b9dec

Please sign in to comment.