reactive_graph_std_comparison/
plugin.rs

1use reactive_graph_plugin_api::EntityBehaviourRegistry;
2use reactive_graph_plugin_api::prelude::plugin::*;
3use reactive_graph_plugin_api::prelude::providers::*;
4
5use crate::behaviour::entity::gate::COMPARISON_GATES;
6
7export_plugin!({
8    "dependencies": [
9        { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" },
10        { "name": "reactive-graph-std-result", "version": ">=0.10.0, <0.11.0" }
11    ]
12});
13
14#[injectable]
15pub trait ComparisonPlugin: Plugin + Send + Sync {}
16
17#[derive(Component)]
18pub struct ComparisonPluginImpl {
19    component_provider: Arc<dyn TypeProvider<Components> + Send + Sync>,
20
21    #[component(default = "component_provider_registry")]
22    component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
23
24    entity_types_provider: Arc<dyn TypeProvider<EntityTypes> + Send + Sync>,
25
26    #[component(default = "entity_types_provider_registry")]
27    entity_type_provider_registry: Arc<dyn EntityTypeProviderRegistry + Send + Sync>,
28
29    #[component(default = "entity_behaviour_registry")]
30    entity_behaviour_registry: Arc<dyn EntityBehaviourRegistry + Send + Sync>,
31}
32
33#[async_trait]
34#[component_alias]
35impl Plugin for ComparisonPluginImpl {
36    async fn activate(&self) -> Result<(), PluginActivationError> {
37        self.component_provider_registry.register_provider(self.component_provider.clone()).await;
38        self.entity_type_provider_registry.register_provider(self.entity_types_provider.clone()).await;
39        self.entity_behaviour_registry.register_all(&COMPARISON_GATES.get_factories()).await;
40        Ok(())
41    }
42
43    async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
44        self.entity_behaviour_registry.unregister_all(&COMPARISON_GATES.to_entity_behaviour_tys()).await;
45        self.entity_type_provider_registry.unregister_provider(self.entity_types_provider.id()).await;
46        self.component_provider_registry.unregister_provider(self.component_provider.id()).await;
47        Ok(())
48    }
49}