amico_core/world/
manager.rs

1use crate::{ecs, traits::System};
2
3use super::{ActionSender, HandlerRegistry};
4
5/// The ECS World manager.
6///
7/// This type defines how to build the ECS `World` for our
8/// framework to use.
9#[derive(Debug)]
10pub struct WorldManager {
11    world: ecs::World,
12}
13
14impl WorldManager {
15    /// Creates a `World` and spawn all the entities.
16    pub fn new() -> Self {
17        let world = ecs::World::new();
18
19        // TODO: Spawn all the entities. (in the future)
20
21        Self { world }
22    }
23
24    /// Register a `System` to the world.
25    pub fn add_system<S: System>(&mut self, system: S) {
26        system.register_to(HandlerRegistry {
27            world: &mut self.world,
28        });
29    }
30
31    /// Gets the action sender.
32    pub(crate) fn action_sender(&mut self) -> ActionSender {
33        ActionSender {
34            world: &mut self.world,
35        }
36    }
37}
38
39impl Default for WorldManager {
40    fn default() -> Self {
41        Self::new()
42    }
43}