reactive_graph_std_color/
plugin.rs1use reactive_graph_plugin_api::EntityBehaviourRegistry;
2use reactive_graph_plugin_api::prelude::plugin::*;
3use reactive_graph_plugin_api::prelude::providers::*;
4
5use crate::behaviour::entity::hsv_to_rgb::HsvToRgbFactory;
6use crate::behaviour::entity::rgb_to_hsv::RgbToHsvFactory;
7use reactive_graph_std_color_model::BEHAVIOUR_HSV_TO_RGB;
8use reactive_graph_std_color_model::BEHAVIOUR_RGB_TO_HSV;
9use reactive_graph_std_color_model::ENTITY_BEHAVIOUR_HSV_TO_RGB;
10use reactive_graph_std_color_model::ENTITY_BEHAVIOUR_RGB_TO_HSV;
11
12export_plugin!({
13 "dependencies": [
14 { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" }
15 ]
16});
17
18#[injectable]
19pub trait ColorPlugin: Plugin + Send + Sync {}
20
21#[derive(Component)]
22pub struct ColorPluginImpl {
23 component_provider: Arc<dyn TypeProvider<Components> + Send + Sync>,
24
25 #[component(default = "component_provider_registry")]
26 component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
27
28 entity_types_provider: Arc<dyn TypeProvider<EntityTypes> + Send + Sync>,
29
30 #[component(default = "entity_types_provider_registry")]
31 entity_type_provider_registry: Arc<dyn EntityTypeProviderRegistry + Send + Sync>,
32
33 #[component(default = "entity_behaviour_registry")]
34 entity_behaviour_registry: Arc<dyn EntityBehaviourRegistry + Send + Sync>,
35}
36
37#[async_trait]
38#[component_alias]
39impl Plugin for ColorPluginImpl {
40 async fn activate(&self) -> Result<(), PluginActivationError> {
41 self.component_provider_registry.register_provider(self.component_provider.clone()).await;
42 self.entity_type_provider_registry.register_provider(self.entity_types_provider.clone()).await;
43 let factory = Arc::new(RgbToHsvFactory::new(BEHAVIOUR_RGB_TO_HSV.clone()));
44 self.entity_behaviour_registry.register(ENTITY_BEHAVIOUR_RGB_TO_HSV.clone(), factory).await;
45
46 let factory = Arc::new(HsvToRgbFactory::new(BEHAVIOUR_HSV_TO_RGB.clone()));
47 self.entity_behaviour_registry.register(ENTITY_BEHAVIOUR_HSV_TO_RGB.clone(), factory).await;
48 Ok(())
49 }
50
51 async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
52 self.entity_behaviour_registry.unregister(&ENTITY_BEHAVIOUR_HSV_TO_RGB).await;
53 self.entity_behaviour_registry.unregister(&ENTITY_BEHAVIOUR_RGB_TO_HSV).await;
54 self.entity_type_provider_registry.unregister_provider(self.entity_types_provider.id()).await;
55 self.component_provider_registry.unregister_provider(self.component_provider.id()).await;
56 Ok(())
57 }
58}