use bevy::prelude::*;
#[derive(Component, Default, Debug, PartialEq, Eq)]
#[relationship_target(relationship = InvokedBy, linked_spawn)]
pub struct Invokes(Vec<Entity>);
impl<'a> IntoIterator for &'a Invokes {
type Item = <Self::IntoIter as Iterator>::Item;
type IntoIter = std::slice::Iter<'a, Entity>;
#[inline(always)]
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl Invokes {
pub fn new() -> Self {
Self(Vec::new())
}
}
#[derive(Component, Clone, PartialEq, Eq, Debug)]
#[relationship(relationship_target = Invokes)]
pub struct InvokedBy(#[entities] pub Entity);
impl FromWorld for InvokedBy {
#[inline(always)]
fn from_world(_world: &mut World) -> Self {
InvokedBy(Entity::PLACEHOLDER)
}
}
pub fn resolve_invoker(q_invoker: &Query<&InvokedBy>, entity: Entity) -> Entity {
q_invoker.root_ancestor(entity)
}
pub fn resolve_root(q_child_of: &Query<&ChildOf>, entity: Entity) -> Entity {
q_child_of.root_ancestor(entity)
}