Skip to content

Commit

Permalink
Bevy 0.14 minimal migration
Browse files Browse the repository at this point in the history
New animation system is not really a good fit for what was already there
  • Loading branch information
haihala committed Jul 14, 2024
1 parent 089cbb3 commit e7aaad8
Show file tree
Hide file tree
Showing 9 changed files with 810 additions and 519 deletions.
951 changes: 547 additions & 404 deletions client/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ incremental = true
opt-level = 3

[workspace.dependencies]
bevy = "0.13"
bevy_hanabi = "0.11"
bevy-inspector-egui = "0.24"
bevy = "0.14"
bevy_hanabi = "0.12"
bevy-inspector-egui = "0.25"

rand = "0.8"
strum = "0.26"
Expand Down
10 changes: 5 additions & 5 deletions client/input_parsing/src/input_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ mod test {
let mut app = App::new();
app.add_systems(Update, parse_input::<TestStream>);

app.world.spawn((
app.world_mut().spawn((
TestInputBundle::new(moves.into_iter().collect()),
Facing::Right,
));
Expand Down Expand Up @@ -303,9 +303,9 @@ mod test {
fn add_input(&mut self, change: InputEvent) {
for mut reader in self
.app
.world
.world_mut()
.query::<&mut TestStream>()
.iter_mut(&mut self.app.world)
.iter_mut(&mut self.app.world_mut())
{
reader.push(change.clone());
}
Expand Down Expand Up @@ -338,9 +338,9 @@ mod test {
// Running a query requires mutable access I guess?
fn get_parser_events(&mut self) -> Vec<ActionId> {
self.app
.world
.world_mut()
.query::<&InputParser>()
.iter(&self.app.world)
.iter(&self.app.world())
.next()
.unwrap()
.events
Expand Down
37 changes: 26 additions & 11 deletions client/lib/src/assets/animations/animation_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,42 @@ fn find_animation_player_entity(
}

pub fn update_animation(
mut commands: Commands,
animations: Res<Animations>,
mut main: Query<(&mut AnimationHelper, &Facing, &Stats)>,
mut players: Query<&mut AnimationPlayer>,
mut scenes: Query<&mut Transform, With<Handle<Scene>>>,
maybe_hitstop: Option<ResMut<Hitstop>>,
graphs: ResMut<Assets<AnimationGraph>>,
) {
for (mut helper, facing, stats) in &mut main {
let mut player = players.get_mut(helper.player_entity).unwrap();
let mut scene_root = scenes.get_mut(helper.scene_root).unwrap();

if let Some(request) = helper.request.take() {
// New animation set to start
let handle = animations.get(
let (graph_handle, index) = animations.get(
request.animation,
&if request.invert {
facing.opposite()
} else {
*facing
},
&graphs,
);

let graph = graphs.get(&graph_handle).unwrap();
dbg!(
index,
&graph_handle,
&graph,
graph.nodes().collect::<Vec<_>>()
);
player
.start(handle)

commands.entity(helper.player_entity).insert(graph_handle);

let animation = player
.start(index)
.seek_to(request.time_offset as f32 / wag_core::FPS)
.set_speed(if request.ignore_action_speed {
1.0
Expand All @@ -127,7 +141,7 @@ pub fn update_animation(
// FIXME: There is something wrong with this.
// First frames of the animation bleed through occasionally
if request.looping {
player.repeat();
animation.repeat();
}

helper.playing = request;
Expand All @@ -137,16 +151,17 @@ pub fn update_animation(
// Looping animations like idle ought to turn when the sides switch. Non looping like moves should not
} else if *facing != helper.facing && helper.playing.looping {
// Sideswitch
let handle = animations.get(helper.playing.animation, facing);
let elapsed = player.elapsed();
player.start(handle).seek_to(elapsed).repeat();
let (graph, index) = animations.get(helper.playing.animation, facing, &graphs);
commands.entity(helper.player_entity).insert(graph);
let elapsed = player.playing_animations().next().unwrap().1.elapsed();
player.start(index).seek_to(elapsed).repeat();
helper.facing = *facing;
} else if maybe_hitstop.is_none() && player.is_paused() {
} else if maybe_hitstop.is_none() && player.all_paused() {
// Hitstop is over, resume playing
player.resume();
} else if maybe_hitstop.is_some() && !player.is_paused() {
player.resume_all();
} else if maybe_hitstop.is_some() && !player.all_paused() {
// Hitstop started, pause
player.pause();
player.pause_all();
}
}
}
Loading

0 comments on commit e7aaad8

Please sign in to comment.