mirror of
https://github.com/bevyengine/bevy
synced 2024-12-22 19:13:08 +00:00
0294bb191d
# Objective - Use `AppTypeRegistry` on API defined in `bevy_ecs` (https://github.com/bevyengine/bevy/pull/8895#discussion_r1234748418) A lot of the API on `Reflect` depends on a registry. When it comes to the ECS. We should use `AppTypeRegistry` in the general case. This is however impossible in `bevy_ecs`, since `AppTypeRegistry` is defined in `bevy_app`. ## Solution - Move `AppTypeRegistry` resource definition from `bevy_app` to `bevy_ecs` - Still add the resource in the `App` plugin, since bevy_ecs itself doesn't know of plugins Note that `bevy_ecs` is a dependency of `bevy_app`, so nothing revolutionary happens. ## Alternative - Define the API as a trait in `bevy_app` over `bevy_ecs`. (though this prevents us from using bevy_ecs internals) - Do not rely on `AppTypeRegistry` for the API in question, requring users to extract themselves the resource and pass it to the API methods. --- ## Changelog - Moved `AppTypeRegistry` resource definition from `bevy_app` to `bevy_ecs` ## Migration Guide - If you were **not** using a `prelude::*` to import `AppTypeRegistry`, you should update your imports: ```diff - use bevy::app::AppTypeRegistry; + use bevy::ecs::reflect::AppTypeRegistry ```
42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
//! Types that enable reflection support.
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
use crate as bevy_ecs;
|
|
use crate::{entity::Entity, system::Resource};
|
|
use bevy_reflect::{
|
|
impl_from_reflect_value, impl_reflect_value, ReflectDeserialize, ReflectSerialize,
|
|
TypeRegistryArc,
|
|
};
|
|
|
|
mod component;
|
|
mod map_entities;
|
|
mod resource;
|
|
|
|
pub use component::{ReflectComponent, ReflectComponentFns};
|
|
pub use map_entities::ReflectMapEntities;
|
|
pub use resource::{ReflectResource, ReflectResourceFns};
|
|
|
|
/// A [`Resource`] storing [`TypeRegistry`](bevy_reflect::TypeRegistry) for
|
|
/// type registrations relevant to a whole app.
|
|
#[derive(Resource, Clone, Default)]
|
|
pub struct AppTypeRegistry(pub TypeRegistryArc);
|
|
|
|
impl Deref for AppTypeRegistry {
|
|
type Target = TypeRegistryArc;
|
|
|
|
#[inline]
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl DerefMut for AppTypeRegistry {
|
|
#[inline]
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.0
|
|
}
|
|
}
|
|
|
|
impl_reflect_value!((in bevy_ecs) Entity(Hash, PartialEq, Serialize, Deserialize));
|
|
impl_from_reflect_value!(Entity);
|