Start integrating asset loading and animations

This commit is contained in:
2026-08-26 16:33:00 +02:00
parent 73855ea354
commit 4ff388f9c0
23 changed files with 724 additions and 301 deletions
+57 -15
View File
@@ -1,16 +1,23 @@
use std::{collections::HashMap, time::Duration};
use bevy::{mesh::skinning::SkinnedMesh, prelude::*};
use crate::{fighter::{FighterECB, FighterTranslation, FighterVisual}, player::Player};
#[derive(Component)]
pub struct FighterAnimations {
pub wait: Handle<AnimationClip>
}
use crate::{
fighter::{FighterECB, FighterTranslation, FighterVisual, visual::FighterAnimations}, player::Player,
};
#[derive(Component)]
pub struct FighterAnimationPlayerLink(Entity);
pub fn apply_fighter_translation_to_visuals(query: Query<(&FighterTranslation, &FighterECB, &mut Transform)>) {
impl FighterAnimationPlayerLink {
pub fn player(&self) -> Entity {
self.0
}
}
pub fn apply_fighter_translation_to_visuals(
query: Query<(&FighterTranslation, &FighterECB, &mut Transform)>,
) {
for (translation, ecb, mut transform) in query {
let translation = translation.0 + ecb.get_bottom_point();
transform.translation = Vec3::new(translation.x.to_num(), translation.y.to_num(), 0.0);
@@ -31,18 +38,53 @@ pub fn setup_fighter_animation_player(
else {
continue;
};
commands.entity(parent).insert(
FighterAnimationPlayerLink(child)
);
commands.entity(child).insert(AnimationTransitions::new());
info!("LINK");
commands
.entity(parent)
.insert(FighterAnimationPlayerLink(child));
}
}
pub fn apply_animation(
children: Query<&mut Transform, With<FighterVisual>>,
) {
pub fn apply_animation(children: Query<&mut Transform, With<FighterVisual>>) {
for mut trf in children {
// Melee model scale is in decimeters
trf.scale = Vec3::splat(0.1);
trf.rotation = Quat::IDENTITY;
trf.rotate_local_y(std::f32::consts::PI * 0.5);
}
}
}
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)]
pub enum AnimKind {
Wait,
Walk,
Run,
Dash,
}
#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)]
pub struct AnimManifest(pub HashMap<AnimKind, String>);