scene: require clone for registered components

This commit is contained in:
Carter Anderson 2020-05-21 18:51:03 -07:00
parent fd26588dbd
commit 9368242013
2 changed files with 7 additions and 6 deletions

View file

@ -22,7 +22,7 @@ pub struct ComponentRegistry {
impl ComponentRegistry {
pub fn register<T>(&mut self)
where
T: Send + Sync + 'static + Serialize + for<'de> Deserialize<'de>,
T: Clone + Send + Sync + 'static + Serialize + for<'de> Deserialize<'de>,
{
let registration = ComponentRegistration::of::<T>();
self.short_names
@ -69,7 +69,7 @@ pub struct ComponentRegistration {
}
impl ComponentRegistration {
pub fn of<T: Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static>() -> Self {
pub fn of<T: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static>() -> Self {
let ty = ComponentTypeId::of::<T>();
Self {
ty,
@ -107,13 +107,13 @@ impl ComponentRegistration {
pub trait RegisterComponent {
fn register_component<T>(&mut self) -> &mut Self
where
T: Send + Sync + 'static + Serialize + for<'de> Deserialize<'de>;
T: Clone + Send + Sync + 'static + Serialize + for<'de> Deserialize<'de>;
}
impl RegisterComponent for AppBuilder {
fn register_component<T>(&mut self) -> &mut Self
where
T: Send + Sync + 'static + Serialize + for<'de> Deserialize<'de>,
T: Clone + Send + Sync + 'static + Serialize + for<'de> Deserialize<'de>,
{
{
let registry_context = self.resources().get_mut::<ComponentRegistryContext>().unwrap();

View file

@ -5,6 +5,7 @@ fn main() {
App::build()
.add_default_plugins()
// Registering components informs Bevy that they exist. This allows them to be used when loading/saving scenes
// This step is only required if you want to load/save your components.
.register_component::<Test>()
.register_component::<Foo>()
// .add_startup_system(setup)
@ -12,13 +13,13 @@ fn main() {
.run();
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
struct Test {
pub x: f32,
pub y: f32,
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
struct Foo {
pub value: String,
}