use specs::{Dispatcher as Inner, DispatcherBuilder, World, WorldExt};

use crate::{
    components::Player,
    resources::Global,
    systems::{Fleets, Movement, Process},
};

pub struct Dispatcher<'a, 'b> {
    dispatcher: Inner<'a, 'b>,
}

impl<'a, 'b> Dispatcher<'a, 'b> {
    pub fn new(world: &mut World) -> Self {
        world.insert(Global::default());

        world.register::<Player>();

        let mut dispatcher = DispatcherBuilder::new()
            .with(Process::default(), "process", &[])
            .with(Movement::default(), "movement", &[])
            .with(Fleets::default(), "fleets", &[])
            .build();
        dispatcher.setup(world);

        Self { dispatcher }
    }

    pub fn process(&mut self, world: &World) {
        self.dispatcher.dispatch(world);
    }
}
