From 9c4e43a24cfccae4973e963cf645086cc82b98dd Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Mon, 6 May 2024 15:51:24 -0700 Subject: [PATCH] Animation speed for dissolve looks sick as hell --- src/display3d.rs | 121 ++++++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/src/display3d.rs b/src/display3d.rs index 36a5bdd..af2561e 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -14,6 +14,7 @@ impl Plugin for Display3dPlugin { )) .init_state::() .init_resource::() + .insert_resource(AnimationSpeed(1.0)) .insert_resource(Msaa::Off) .insert_resource(AmbientLight { color: Color::WHITE, @@ -91,15 +92,19 @@ impl Plugin for Display3dPlugin { put_down.run_if(any_component_removed::()), dissolve_animation.run_if(any_with_component::), capture_piece.run_if(any_with_component::), - skip_animation - .run_if(in_state(GameState::Play)) - .run_if(pressed(KeyCode::Enter).or_else(pressed(MouseButton::Left))), - un_skip_animation.run_if(in_state(GameState::Play)).run_if( - just_released(KeyCode::Enter).or_else(just_released(MouseButton::Left)), - ), monitor_animations .run_if(in_state(GameState::Play)) .run_if(any_component_changed::()), + set_animation_player_speed + .run_if(any_component_added::() + .or_else(resource_changed::)), + set_animation_speed + .run_if( + just_pressed(KeyCode::Enter) + .or_else(just_pressed(MouseButton::Left)) + .or_else(just_released(KeyCode::Enter)) + .or_else(just_released(MouseButton::Left)) + ) ), ) .add_systems( @@ -128,25 +133,25 @@ impl Plugin for Display3dPlugin { ( // Toggle hidden/visible 3d entities manage_state_entities::(), - // fixup_shadows, color_grading_tweak.run_if(resource_exists::), fog_tweak.run_if(resource_exists::), bloom_tweak.run_if(resource_exists::), + update_pieces.run_if(resource_exists::), ), ) .add_systems( Update, - setup_dissolve_materials - .run_if(in_state(GameState::Intro)) - .run_if( - any_component_added::>() - .or_else(any_component_changed::>()), - ), + ( + setup_dissolve_materials + .run_if( + any_component_added::>() + .or_else(any_component_changed::>()), + ), + ) ) .add_systems( OnEnter(GameState::Play), ( - update_pieces.run_if(resource_exists::), opening_animation .run_if(run_once()) .run_if(in_state(DisplayState::Display3d)), @@ -154,7 +159,10 @@ impl Plugin for Display3dPlugin { ) .add_systems( OnEnter(GameState::Title), - (fixup_shadows, intro_title_dissolve), + ( + intro_title_dissolve, + fixup_shadows + ) ) .add_systems(OnExit(GameState::Title), outro_title_dissolve) .add_systems( @@ -193,6 +201,9 @@ enum DissolvingAnimation { Out, } +#[derive(Debug, Resource)] +struct AnimationSpeed(f32); + #[derive(Debug, Resource, Clone)] struct AssetsMap { hitbox_shape: Handle, @@ -992,26 +1003,32 @@ fn opening_animation(mut players: Query<&mut AnimationPlayer, (With, Wit }); } -// When called skips any running animations -fn skip_animation( - mut players: Query<&mut AnimationPlayer, With>, + +fn set_animation_speed( + mut animation_speed: ResMut, tweaks: Res>, tweaks_file: Res, + keys: Res>, + mouse: Res>, ) { - let tweak = tweaks - .get(tweaks_file.handle.clone()) - .expect("Load tweakfile"); - let speed = tweak.get::("animation_fast_speed").unwrap(); - players.iter_mut().for_each(|mut p| { - debug!("Skipping animation"); - p.set_speed(speed); - }) + animation_speed.0 = if keys.pressed(KeyCode::Enter) || mouse.pressed(MouseButton::Left) { + let tweak = tweaks + .get(tweaks_file.handle.clone()) + .expect("Load tweakfile"); + let speed = tweak.get::("animation_fast_speed").unwrap(); + speed + } else { + 1.0 + } } -fn un_skip_animation(mut players: Query<&mut AnimationPlayer, With>) { +// When an animation starts, or the animation speed changes, update player speed +fn set_animation_player_speed( + mut players: Query<&mut AnimationPlayer, With>, + animation_speed: Res, +) { players.iter_mut().for_each(|mut p| { - debug!("Un-Skipping animation"); - p.set_speed(1.0); + p.set_speed(animation_speed.0); }) } @@ -1093,7 +1110,7 @@ fn setup_dissolve_materials( .filter(|(child, _, _)| query.iter_many(parents.iter_ancestors(*child)).count() > 0) // Handle this entity (mesh) .for_each(|(child, std_handle, name)| { - debug!("Setting up dissolve material for {:?} {:?}", name, child); + info!("Setting up dissolve material for {:?} {:?}", name, child); // Get dissolvable data for percentage start let dissolvable = query @@ -1139,6 +1156,8 @@ fn capture_piece( mut state: Local>, mut commands: Commands, score: Res, + mut timer: Local, + time: Res