character hierarchy system param

This commit is contained in:
2025-04-22 23:54:25 +02:00
parent cb8a2b26bf
commit e33882b348
2 changed files with 20 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
use crate::{GameState, heads_database::HeadsDatabase, loading_assets::GameAssets};
use bevy::{prelude::*, utils::HashMap};
use bevy::{ecs::system::SystemParam, prelude::*, utils::HashMap};
use std::time::Duration;
#[derive(Component, Debug)]
@@ -8,6 +8,20 @@ pub struct ProjectileOrigin;
#[derive(Component, Debug)]
pub struct AnimatedCharacter(pub usize);
#[derive(SystemParam)]
pub struct CharacterHierarchy<'w, 's> {
descendants: Query<'w, 's, &'static Children>,
projectile_origin: Query<'w, 's, &'static GlobalTransform, With<ProjectileOrigin>>,
}
impl CharacterHierarchy<'_, '_> {
pub fn projectile_origin(&self, entity: Entity) -> Option<&GlobalTransform> {
self.descendants
.iter_descendants(entity)
.find_map(|child| self.projectile_origin.get(child).ok())
}
}
#[derive(Component, Debug, Reflect)]
#[reflect(Component)]
pub struct CharacterAnimations {