|
- use specs::{Dispatcher as Inner, DispatcherBuilder, World, WorldExt};
-
- use crate::{
- components::Player,
- resources::Global,
- systems::{
- FleetControl, FleetOrbitingUpdate, FleetOwnedUpdate, Process, ShipControl, ShipsMovement,
- ShipsMoving, ShipsOrbiting,
- },
- Error,
- };
-
- pub struct Dispatcher<'a, 'b> {
- dispatcher: Inner<'a, 'b>,
- }
-
- impl<'a, 'b> Dispatcher<'a, 'b> {
- pub fn new(world: &mut World) -> Result<Self, Error> {
- world.insert(Global::default());
-
- world.register::<Player>();
-
- let mut dispatcher = DispatcherBuilder::new()
- .with(Process::default(), "process", &[])
- .with(ShipControl::new(world)?, "ship_control", &[])
- .with(ShipsOrbiting::default(), "ships_orbiting", &[])
- .with(ShipsMoving::default(), "ships_moving", &[])
- .with(ShipsMovement::default(), "ships_movement", &[])
- .with(FleetControl::new(world)?, "fleet_control", &[])
- .with(FleetOwnedUpdate::new(world), "fleet_owned_update", &[])
- .with(FleetOrbitingUpdate::new(world), "fleet_orbiting", &[])
- .build();
- dispatcher.setup(world);
-
- Ok(Self { dispatcher })
- }
-
- pub fn process(&mut self, world: &World) {
- self.dispatcher.dispatch(world);
- }
- }
|