1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
use crate::TypeRegistry; use bevy_app::AppBuilder; use bevy_ecs::{Component, FromResources}; use bevy_property::{DeserializeProperty, Properties, Property}; pub trait RegisterType { fn register_component<T>(&mut self) -> &mut Self where T: Properties + DeserializeProperty + Component + FromResources; fn register_properties<T>(&mut self) -> &mut Self where T: Properties + DeserializeProperty + FromResources; fn register_property<T>(&mut self) -> &mut Self where T: Property + DeserializeProperty; } impl RegisterType for AppBuilder { fn register_component<T>(&mut self) -> &mut Self where T: Properties + DeserializeProperty + Component + FromResources, { { let type_registry = self.app.resources.get::<TypeRegistry>().unwrap(); type_registry.component.write().unwrap().register::<T>(); type_registry.property.write().unwrap().register::<T>(); } self } fn register_properties<T>(&mut self) -> &mut Self where T: Properties + DeserializeProperty + Component + FromResources, { { let type_registry = self.app.resources.get::<TypeRegistry>().unwrap(); type_registry.property.write().unwrap().register::<T>(); } self } fn register_property<T>(&mut self) -> &mut Self where T: Property + DeserializeProperty, { { let type_registry = self.app.resources.get::<TypeRegistry>().unwrap(); type_registry.property.write().unwrap().register::<T>(); } self } }