use beet_core::prelude::*;
use beet_flow::prelude::*;
#[derive(Component)]
pub struct TriggerOnAnimationReady<P> {
pub payload: P,
}
impl TriggerOnAnimationReady<GetOutcome> {
pub fn run() -> Self {
Self {
payload: Default::default(),
}
}
}
pub fn trigger_on_animation_ready<P: ActionEvent + Clone>(
mut commands: Commands,
scene_roots: Query<Entity, With<SceneRoot>>,
parents: Query<&ChildOf>,
children: Query<&Children>,
actions: Query<(Entity, &TriggerOnAnimationReady<P>)>,
players: Populated<Entity, Added<AnimationPlayer>>,
) {
for entity in players.iter() {
for root in parents
.iter_ancestors_inclusive(entity)
.filter_map(|entity| scene_roots.get(entity).ok())
{
for child in children.iter_descendants_inclusive(root) {
if let Ok((action, trigger)) = actions.get(child) {
commands
.entity(action)
.trigger_target(trigger.payload.clone());
}
}
}
}
}