mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
make register
on TypeRegistry
idempotent (#6487)
# Objective - adding a new `.register` should not overwrite old type data - separate crates should both be able to register the same type I ran into this while debugging why `register::<Handle<T>>` removed the `ReflectHandle` type data from a prior `register_asset_reflect`. ## Solution - make `register` do nothing if called again for the same type - I also removed some unnecessary duplicate registrations
This commit is contained in:
parent
3d64acd0c3
commit
5ae94750a1
2 changed files with 6 additions and 5 deletions
|
@ -48,11 +48,6 @@ impl Plugin for CorePlugin {
|
|||
);
|
||||
|
||||
app.register_type::<Entity>().register_type::<Name>();
|
||||
app.register_type::<Entity>()
|
||||
.register_type::<Name>()
|
||||
.register_type::<Range<f32>>()
|
||||
.register_type_data::<Range<f32>, ReflectSerialize>()
|
||||
.register_type_data::<Range<f32>, ReflectDeserialize>();
|
||||
|
||||
register_rust_types(app);
|
||||
register_math_types(app);
|
||||
|
@ -63,6 +58,8 @@ impl Plugin for CorePlugin {
|
|||
|
||||
fn register_rust_types(app: &mut App) {
|
||||
app.register_type::<Range<f32>>()
|
||||
.register_type_data::<Range<f32>, ReflectSerialize>()
|
||||
.register_type_data::<Range<f32>, ReflectDeserialize>()
|
||||
.register_type::<String>()
|
||||
.register_type::<HashSet<String>>()
|
||||
.register_type::<Option<String>>()
|
||||
|
|
|
@ -87,6 +87,10 @@ impl TypeRegistry {
|
|||
|
||||
/// Registers the type described by `registration`.
|
||||
pub fn add_registration(&mut self, registration: TypeRegistration) {
|
||||
if self.registrations.contains_key(®istration.type_id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let short_name = registration.short_name.to_string();
|
||||
if self.short_name_to_id.contains_key(&short_name)
|
||||
|| self.ambiguous_names.contains(&short_name)
|
||||
|
|
Loading…
Reference in a new issue