use crate::events::{delay_spawn_events, ReadySpawnEvent, SpawnEvent};
use crate::spawner::{Spawner, Spawners};
use bevy::prelude::*;
#[allow(clippy::needless_doctest_main)]
pub struct SpewPlugin<T, D = ()>
where
T: Eq + Send + Sync + 'static,
D: Send + Sync + 'static,
{
_spawner_enum_type: std::marker::PhantomData<T>,
_data_type: std::marker::PhantomData<D>,
}
impl<T, D> Default for SpewPlugin<T, D>
where
T: Eq + Send + Sync + 'static,
D: Send + Sync + 'static,
{
fn default() -> Self {
Self {
_spawner_enum_type: std::marker::PhantomData,
_data_type: std::marker::PhantomData,
}
}
}
impl<T, D> Plugin for SpewPlugin<T, D>
where
T: Eq + Send + Sync + 'static,
D: Send + Sync + 'static,
{
fn build(&self, app: &mut App) {
app.add_event::<SpawnEvent<T, D>>()
.add_event::<ReadySpawnEvent<T, D>>()
.add_systems(Update, delay_spawn_events::<T, D>.in_set(SpewSystemSet));
}
fn is_unique(&self) -> bool {
false
}
}
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub struct SpewSystemSet;
pub trait SpewApp {
fn add_spawner<T, D>(&mut self, spawner: T) -> &mut App
where
T: Spawner<D>;
fn add_spawners<T, D>(&mut self, spawners: T) -> &mut App
where
T: Spawners<D>;
}
impl SpewApp for App {
fn add_spawner<T, D>(&mut self, spawner: T) -> &mut App
where
T: Spawner<D>,
{
spawner.add_to_app(self);
self
}
fn add_spawners<T, D>(&mut self, spawners: T) -> &mut App
where
T: Spawners<D>,
{
spawners.add_to_app(self);
self
}
}