This commit is contained in:
1 parent
293811aecd
commit
d1a56f77cc
23 files changed
+1730
-62
No files matched your search
@@ -1415,16 +1415,13 @@ pub fn apply_reflected_component(
|
||||
let reflected = TypedReflectDeserializer::new(registration, &type_registry)
|
||||
.deserialize(&mut deserializer)
|
||||
.map_err(|error| error.to_string())?;
|
||||
let exists = reflect_component.reflect(world.entity(entity)).is_some();
|
||||
if exists {
|
||||
reflect_component.apply(world.entity_mut(entity), reflected.as_ref());
|
||||
} else {
|
||||
reflect_component.insert(
|
||||
&mut world.entity_mut(entity),
|
||||
reflected.as_ref(),
|
||||
&type_registry,
|
||||
);
|
||||
}
|
||||
// Reflected `apply` merges list fields and cannot restore a shorter snapshot.
|
||||
// Inserting the captured concrete component replaces the value atomically.
|
||||
reflect_component.insert(
|
||||
&mut world.entity_mut(entity),
|
||||
reflected.as_ref(),
|
||||
&type_registry,
|
||||
);
|
||||
}
|
||||
None => reflect_component.remove(&mut world.entity_mut(entity)),
|
||||
}
|
||||
@@ -1451,16 +1448,11 @@ pub fn apply_reflected_default(
|
||||
.data::<ReflectDefault>()
|
||||
.ok_or_else(|| format!("component `{type_path}` has no reflected Default"))?
|
||||
.default();
|
||||
let exists = reflect_component.reflect(world.entity(entity)).is_some();
|
||||
if exists {
|
||||
reflect_component.apply(world.entity_mut(entity), default.as_ref());
|
||||
} else {
|
||||
reflect_component.insert(
|
||||
&mut world.entity_mut(entity),
|
||||
default.as_ref(),
|
||||
&type_registry,
|
||||
);
|
||||
}
|
||||
reflect_component.insert(
|
||||
&mut world.entity_mut(entity),
|
||||
default.as_ref(),
|
||||
&type_registry,
|
||||
);
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user