#![no_std]
#![cfg_attr(bevy_lint, feature(register_tool), register_tool(bevy))]
use bevy_ecs::{
bundle::Bundle, entity::Entity, event::Event, observer::Observer, relationship::Relationship,
spawn::SpawnableList, system::IntoObserverSystem, world::World,
};
use bevy_ptr::MovingPtr;
pub struct SpawnObserver(pub Observer);
impl<R: Relationship> SpawnableList<R> for SpawnObserver {
fn spawn(this: MovingPtr<Self>, world: &mut World, entity: Entity) {
world.spawn((R::from(entity), this.read().0.with_entity(entity)));
}
fn size_hint(&self) -> usize {
0
}
}
impl SpawnObserver {
pub fn new<E: Event, B: Bundle, M, I: IntoObserverSystem<E, B, M>>(observer: I) -> Self {
Self(Observer::new(observer))
}
}