Make the baked animation system drive the character animations

This commit is contained in:
2026-09-01 21:07:53 +02:00
parent 89eeb6a868
commit b2da4a737d
11 changed files with 345 additions and 273 deletions
+1 -64
View File
@@ -1,23 +1,6 @@
use std::time::Duration;
use bevy::prelude::*;
use crate::{
fighter::{
FighterFacingDirection, FighterVisual,
visual::FighterAnimations,
},
player::Player,
};
#[derive(Component)]
pub struct FighterAnimationPlayerLink(Entity);
impl FighterAnimationPlayerLink {
pub fn player(&self) -> Entity {
self.0
}
}
use crate::fighter::{FighterFacingDirection, FighterVisual};
/// The simulation-owned animation clock. Rendering may interpolate freely, but
/// gameplay samples baked data only with this rollback-tracked value.
@@ -54,29 +37,6 @@ pub fn advance_fighter_animation_frames(mut fighters: Query<&mut FighterAnimatio
}
}
pub fn setup_fighter_animation_player(
mut commands: Commands,
animated: Query<Entity, Added<AnimationPlayer>>,
parents: Query<&ChildOf>,
fighters: Query<Entity, With<Player>>,
) {
for child in &animated {
let Some(parent) = parents
.iter_ancestors(child)
.filter_map(|parent| fighters.get(parent).ok())
.next()
else {
continue;
};
commands.entity(child).insert(AnimationTransitions::new());
info!("LINK");
commands
.entity(parent)
.insert(FighterAnimationPlayerLink(child));
}
}
pub fn apply_animation(
children: Query<
(
@@ -102,28 +62,6 @@ pub fn apply_animation(
}
}
pub fn animation_init(
fighters: Query<
(&FighterAnimations, &FighterAnimationPlayerLink),
Added<FighterAnimationPlayerLink>,
>,
mut commands: Commands,
mut anim_player_query: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
) {
for (anim, link) in fighters {
commands
.entity(link.0)
.insert(AnimationGraphHandle(anim.graph.clone()));
info!("BEGIN! {:?}", fighters);
if let Ok((mut player, mut transitions)) = anim_player_query.get_mut(link.0) {
info!("DOS");
transitions
.play(&mut player, anim.clips[&AnimKind::Wait], Duration::ZERO)
.repeat();
}
}
}
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Deserialize, serde::Serialize, Reflect,
)]
@@ -142,7 +80,6 @@ pub enum AnimKind {
Turn,
// Attacks
AttackJab1,
AttackUpTilt,
}