use crate::app::{App, RendererFactory};
use crate::backend::{Backend, InputEvent};
use crate::ecs::World;
pub trait Plugin<B, F>
where
B: Backend,
F: RendererFactory<B>,
{
fn build(&mut self, app: &mut App<B, F>);
fn pre_render(&mut self, _world: &mut World) {}
fn post_render(&mut self, _world: &mut World, _render_nanos: u64) {}
fn on_event(&mut self, _world: &mut World, _event: &InputEvent) -> bool {
false
}
fn on_quit(&mut self, _world: &mut World) {}
fn name(&self) -> &'static str {
core::any::type_name::<Self>()
}
}
impl<B, F, G> Plugin<B, F> for G
where
B: Backend,
F: RendererFactory<B>,
G: FnMut(&mut App<B, F>) + 'static,
{
fn build(&mut self, app: &mut App<B, F>) {
(self)(app)
}
}