Tweakable animation speeds for everything

Pressing speeds up animations across the board
Animation "fast" speeds can be tweaked per category:
* text
* movement
* light
* dissolve
main
Elijah C. Voigt 1 year ago
parent 9c4e43a24c
commit bb2775b5eb

@ -272,4 +272,7 @@ QueenRed = "QueenRedPieceIdle"
### Animation Settings
######################
[animation]
fast_speed = 2.0
fast_movement_speed = 2.0
fast_text_speed = 4.0
fast_dissolve_speed = 1.0
fast_light_speed = 1.0

@ -1,6 +1,7 @@
use bevy::core_pipeline::{
contrast_adaptive_sharpening::ContrastAdaptiveSharpeningSettings, fxaa::Fxaa,
};
use gltf::Animation;
use crate::prelude::*;
@ -14,7 +15,7 @@ impl Plugin for Display3dPlugin {
))
.init_state::<DissolvingAnimation>()
.init_resource::<PiecePointer>()
.insert_resource(AnimationSpeed(1.0))
.init_resource::<AnimationSpeed>()
.insert_resource(Msaa::Off)
.insert_resource(AmbientLight {
color: Color::WHITE,
@ -202,7 +203,23 @@ enum DissolvingAnimation {
}
#[derive(Debug, Resource)]
struct AnimationSpeed(f32);
pub(crate) struct AnimationSpeed {
pub movement: f32,
pub text: f32,
pub dissolve: f32,
pub light: f32,
}
impl Default for AnimationSpeed {
fn default() -> Self {
AnimationSpeed {
movement: 1.0,
text: 1.0,
dissolve: 1.0,
light: 1.0,
}
}
}
#[derive(Debug, Resource, Clone)]
struct AssetsMap {
@ -1011,15 +1028,20 @@ fn set_animation_speed(
keys: Res<ButtonInput<KeyCode>>,
mouse: Res<ButtonInput<MouseButton>>,
) {
animation_speed.0 = if keys.pressed(KeyCode::Enter) || mouse.pressed(MouseButton::Left) {
*animation_speed = if keys.pressed(KeyCode::Enter) || mouse.pressed(MouseButton::Left) {
let tweak = tweaks
.get(tweaks_file.handle.clone())
.expect("Load tweakfile");
let speed = tweak.get::<f32>("animation_fast_speed").unwrap();
speed
let movement = tweak.get::<f32>("animation_fast_movement_speed").unwrap();
let text = tweak.get::<f32>("animation_fast_text_speed").unwrap();
let dissolve = tweak.get::<f32>("animation_fast_dissolve_speed").unwrap();
let light = tweak.get::<f32>("animation_fast_light_speed").unwrap();
AnimationSpeed { movement, text, dissolve, light }
} else {
1.0
}
AnimationSpeed::default()
};
info!("Animation speed: {:?}", animation_speed.movement);
}
// When an animation starts, or the animation speed changes, update player speed
@ -1028,7 +1050,7 @@ fn set_animation_player_speed(
animation_speed: Res<AnimationSpeed>,
) {
players.iter_mut().for_each(|mut p| {
p.set_speed(animation_speed.0);
p.set_speed(animation_speed.movement);
})
}
@ -1331,7 +1353,7 @@ fn dissolve_animation(
let percentage = match *dissolving {
Dissolving::In(mut sec) => {
// Check if seconds is below 0.0
sec = (sec - (time.delta_seconds() * animation_speed.0)).max(0.0);
sec = (sec - (time.delta_seconds() * animation_speed.dissolve)).max(0.0);
*dissolving = Dissolving::In(sec);
@ -1340,7 +1362,7 @@ fn dissolve_animation(
}
Dissolving::Out(mut sec) => {
// Check if seconds is below 0.0
sec = (sec - (time.delta_seconds() * animation_speed.0)).max(0.0);
sec = (sec - (time.delta_seconds() * animation_speed.dissolve)).max(0.0);
*dissolving = Dissolving::Out(sec);
@ -1449,21 +1471,14 @@ fn animate_title_light_in(
mut t: Local<Timer>,
mut started: Local<bool>,
time: Res<Time>,
keys: Res<ButtonInput<KeyCode>>,
mouse: Res<ButtonInput<MouseButton>>,
animation_speed: Res<AnimationSpeed>,
) {
// Over 6 seconds, fade in to 600 intensity
if !(*started) {
*t = Timer::from_seconds(6.0, TimerMode::Once);
*started = true
} else {
let skip = keys.just_pressed(KeyCode::Enter) || mouse.just_pressed(MouseButton::Left);
if skip {
t.tick(Duration::from_secs(6));
} else {
t.tick(time.delta());
}
t.tick(Duration::from_secs_f32(time.delta_seconds() * animation_speed.light));
}
let intensity = t.fraction() * 409800.0;
@ -1488,21 +1503,14 @@ fn animate_title_light_out(
mut t: Local<Timer>,
mut started: Local<bool>,
time: Res<Time>,
keys: Res<ButtonInput<KeyCode>>,
mouse: Res<ButtonInput<MouseButton>>,
animation_speed: Res<AnimationSpeed>,
) {
// Over 6 seconds, fade in to 600 intensity
if !(*started) {
*t = Timer::from_seconds(3.0, TimerMode::Once);
*started = true
} else {
let skip = keys.just_pressed(KeyCode::Enter) || mouse.just_pressed(MouseButton::Left);
if skip {
t.tick(Duration::from_secs(3));
} else {
t.tick(time.delta());
}
t.tick(Duration::from_secs_f32(time.delta_seconds() * animation_speed.light));
}
let intensity = (1.0 - t.fraction()) * 409800.0;

@ -1,3 +1,5 @@
use bevy::time::Stopwatch;
use crate::prelude::*;
pub(crate) struct IntroPlugin;
@ -218,7 +220,7 @@ fn manage_scroll_text_animation(
if let Some(e) = curr.0 {
commands.entity(e).insert(ui::TextScroll {
progress: 0,
start: time.elapsed_seconds(),
stopwatch: Stopwatch::new(),
});
} else {
commands.entity(r).remove::<ui::TextScrollAnimation>();
@ -233,11 +235,10 @@ fn scroll_text(
tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<tweak::Tweaks>>,
time: Res<Time>,
keys: Res<ButtonInput<KeyCode>>,
mouse: Res<ButtonInput<MouseButton>>,
parents: Query<&Parent>,
mut prompt: ResMut<NextState<ui::Prompt>>,
mut commands: Commands,
animation_speed: Res<display3d::AnimationSpeed>,
) {
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
texts
@ -254,19 +255,14 @@ fn scroll_text(
*vis = Visibility::Inherited;
}
// If user pressed enter, skip to end of paragraph
text_scroll.progress =
if keys.just_pressed(KeyCode::Enter) || mouse.just_pressed(MouseButton::Left) {
usize::MAX
}
// Otherwise, progress by some fixed increment
else {
// Update animation progress for this paragrpah
let delay = tweak.get::<f32>("intro_delay").unwrap();
text_scroll.stopwatch.tick(Duration::from_secs_f32(time.delta_seconds() * animation_speed.text));
text_scroll.progress = {
// Update animation progress for this paragrpah
let delay = tweak.get::<f32>("intro_delay").unwrap();
// Update text_scroll.progress based on frame count
((time.elapsed_seconds() - text_scroll.start) / delay) as usize
};
(text_scroll.stopwatch.elapsed_secs() / delay) as usize
};
// Fetch desired color from tweakfile
let text_visible_hex = tweak.get::<String>("intro_rgba_visible").unwrap();

@ -1,3 +1,5 @@
use bevy::time::Stopwatch;
use crate::prelude::*;
pub(crate) struct UiPlugin;
@ -34,7 +36,7 @@ pub(crate) struct UiFont {
#[derive(Debug, Component)]
pub(crate) struct TextScroll {
pub progress: usize,
pub start: f32,
pub stopwatch: Stopwatch,
}
#[derive(Debug, Component)]

Loading…
Cancel
Save