Make intro speedier

main
Elijah C. Voigt 1 year ago
parent 3fd9f483ae
commit 6f53ff2611

@ -271,7 +271,7 @@ QueenRed = "QueenRedPieceIdle"
### Animation Settings ### Animation Settings
###################### ######################
[animation] [animation]
fast_movement_speed = 2.0 fast_movement_speed = 5.0
fast_text_speed = 4.0 fast_text_speed = 999.0
fast_dissolve_speed = 1.0 fast_dissolve_speed = 1.0
fast_light_speed = 1.0 fast_light_speed = 1.0

@ -190,7 +190,6 @@ pub(crate) enum Dissolving {
#[derive(Debug, Resource)] #[derive(Debug, Resource)]
pub(crate) struct AnimationSpeed { pub(crate) struct AnimationSpeed {
pub movement: f32, pub movement: f32,
pub text: f32,
pub dissolve: f32, pub dissolve: f32,
} }
@ -198,7 +197,6 @@ impl Default for AnimationSpeed {
fn default() -> Self { fn default() -> Self {
AnimationSpeed { AnimationSpeed {
movement: 1.0, movement: 1.0,
text: 1.0,
dissolve: 1.0, dissolve: 1.0,
} }
} }
@ -1029,19 +1027,18 @@ fn set_animation_speed(
keys: Res<ButtonInput<KeyCode>>, keys: Res<ButtonInput<KeyCode>>,
mouse: Res<ButtonInput<MouseButton>>, mouse: Res<ButtonInput<MouseButton>>,
) { ) {
*animation_speed = if keys.pressed(KeyCode::Enter) || mouse.pressed(MouseButton::Left) { *animation_speed = if keys.just_pressed(KeyCode::Enter) || mouse.just_pressed(MouseButton::Left) {
let tweak = tweaks let tweak = tweaks
.get(tweaks_file.handle.clone()) .get(tweaks_file.handle.clone())
.expect("Load tweakfile"); .expect("Load tweakfile");
let movement = tweak.get::<f32>("animation_fast_movement_speed").unwrap(); 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 dissolve = tweak.get::<f32>("animation_fast_dissolve_speed").unwrap();
AnimationSpeed { movement, text, dissolve } AnimationSpeed { movement, dissolve }
} else { } else {
AnimationSpeed::default() AnimationSpeed::default()
}; };
debug!("Animation speed: {:?}", animation_speed.movement); info!("Set animation speeds {:?}", *animation_speed);
} }
// When an animation starts, or the animation speed changes, update player speed // When an animation starts, or the animation speed changes, update player speed

@ -7,6 +7,7 @@ pub(crate) struct IntroPlugin;
impl Plugin for IntroPlugin { impl Plugin for IntroPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_resource::<CurrentIntroParagraph>() app.init_resource::<CurrentIntroParagraph>()
.init_resource::<TextAnimationSpeed>()
.add_systems( .add_systems(
OnExit(GameState::Loading), OnExit(GameState::Loading),
init_intro_text init_intro_text
@ -30,6 +31,13 @@ impl Plugin for IntroPlugin {
// Play intro manages playing the intro of each individual paragraph // Play intro manages playing the intro of each individual paragraph
// Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated // Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated
scroll_text.run_if(any_with_component::<ui::TextScroll>), scroll_text.run_if(any_with_component::<ui::TextScroll>),
set_text_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))
)
) )
.run_if(in_state(GameState::Intro)), .run_if(in_state(GameState::Intro)),
); );
@ -39,6 +47,35 @@ impl Plugin for IntroPlugin {
#[derive(Debug, Component)] #[derive(Debug, Component)]
struct IntroUi; struct IntroUi;
#[derive(Debug, Resource)]
struct TextAnimationSpeed(f32);
impl Default for TextAnimationSpeed {
fn default() -> Self {
TextAnimationSpeed(5.0)
}
}
fn set_text_animation_speed(
mut animation_speed: ResMut<TextAnimationSpeed>,
tweaks: Res<Assets<Tweaks>>,
tweaks_file: Res<tweak::GameTweaks>,
keys: Res<ButtonInput<KeyCode>>,
mouse: Res<ButtonInput<MouseButton>>,
) {
*animation_speed = if keys.just_pressed(KeyCode::Enter) || mouse.just_pressed(MouseButton::Left) {
let tweak = tweaks
.get(tweaks_file.handle.clone())
.expect("Load tweakfile");
let speed = tweak.get::<f32>("animation_fast_text_speed").unwrap();
TextAnimationSpeed(speed)
} else {
TextAnimationSpeed::default()
};
info!("Set animation speeds {:?}", *animation_speed);
}
// Draw the intro text (invisible) on startup // Draw the intro text (invisible) on startup
// Requires the Tweakfile to be loaded // Requires the Tweakfile to be loaded
fn init_intro_text( fn init_intro_text(
@ -181,6 +218,9 @@ fn manage_scroll_text_animation(
mut next_state: ResMut<NextState<GameState>>, mut next_state: ResMut<NextState<GameState>>,
mut curr: ResMut<CurrentIntroParagraph>, mut curr: ResMut<CurrentIntroParagraph>,
mut commands: Commands, mut commands: Commands,
mut speed: ResMut<TextAnimationSpeed>,
mut keys: ResMut<ButtonInput<KeyCode>>,
mut mouse: ResMut<ButtonInput<MouseButton>>,
) { ) {
info!("Managing scroll text animation"); info!("Managing scroll text animation");
@ -203,6 +243,10 @@ fn manage_scroll_text_animation(
commands.entity(p.get()).insert(Visibility::Hidden); commands.entity(p.get()).insert(Visibility::Hidden);
commands.entity(e).insert(Visibility::Hidden); commands.entity(e).insert(Visibility::Hidden);
*speed = TextAnimationSpeed::default();
keys.clear();
mouse.clear();
} }
// Locate the last entity we were operating with // Locate the last entity we were operating with
for entity in paragraphs.by_ref() { for entity in paragraphs.by_ref() {
@ -216,11 +260,13 @@ fn manage_scroll_text_animation(
info!("Curr: {:?}", curr.0); info!("Curr: {:?}", curr.0);
// Progress to the next paragraph
if let Some(e) = curr.0 { if let Some(e) = curr.0 {
commands.entity(e).insert(ui::TextScroll { commands.entity(e).insert(ui::TextScroll {
progress: 0, progress: 0,
stopwatch: Stopwatch::new(), stopwatch: Stopwatch::new(),
}); });
// Continue to the title
} else { } else {
commands.entity(r).remove::<ui::TextScrollAnimation>(); commands.entity(r).remove::<ui::TextScrollAnimation>();
next_state.set(GameState::Title); next_state.set(GameState::Title);
@ -237,7 +283,7 @@ fn scroll_text(
parents: Query<&Parent>, parents: Query<&Parent>,
mut prompt: ResMut<NextState<ui::Prompt>>, mut prompt: ResMut<NextState<ui::Prompt>>,
mut commands: Commands, mut commands: Commands,
animation_speed: Res<display3d::AnimationSpeed>, animation_speed: Res<TextAnimationSpeed>,
) { ) {
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks"); let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
texts texts
@ -254,7 +300,7 @@ fn scroll_text(
*vis = Visibility::Inherited; *vis = Visibility::Inherited;
} }
text_scroll.stopwatch.tick(Duration::from_secs_f32(time.delta_seconds() * animation_speed.text)); text_scroll.stopwatch.tick(Duration::from_secs_f32(time.delta_seconds() * animation_speed.0));
text_scroll.progress = { text_scroll.progress = {
// Update animation progress for this paragrpah // Update animation progress for this paragrpah

@ -1,4 +1,4 @@
use bevy::time::Stopwatch; use bevy::{time::Stopwatch, window::WindowResized};
use crate::prelude::*; use crate::prelude::*;
@ -18,7 +18,7 @@ impl Plugin for UiPlugin {
interactive_button.run_if(any_component_changed::<Interaction>()), interactive_button.run_if(any_component_changed::<Interaction>()),
scale_ui.run_if( scale_ui.run_if(
on_event::<AssetEvent<tweak::Tweaks>>() on_event::<AssetEvent<tweak::Tweaks>>()
.or_else(any_component_changed::<Window>()) .or_else(on_event::<WindowResized>())
.and_then(resource_exists::<tweak::GameTweaks>), .and_then(resource_exists::<tweak::GameTweaks>),
), ),
), ),
@ -127,9 +127,8 @@ fn interactive_button(
} }
fn scale_ui( fn scale_ui(
mut windows: Query<&mut Window, Changed<Window>>, mut windows: Query<&mut Window>,
mut ui_scale: ResMut<UiScale>, mut ui_scale: ResMut<UiScale>,
mut resolution_set: Local<bool>,
tweakfile: Res<tweak::GameTweaks>, tweakfile: Res<tweak::GameTweaks>,
tweaks: Res<Assets<tweak::Tweaks>>, tweaks: Res<Assets<tweak::Tweaks>>,
) { ) {
@ -142,10 +141,7 @@ fn scale_ui(
windows.iter_mut().for_each(|mut w| { windows.iter_mut().for_each(|mut w| {
// Setting window resolution at startup // Setting window resolution at startup
if !*resolution_set { w.resolution.set(width, height);
w.resolution.set(width, height);
*resolution_set = true;
}
// Check if window is minimized // Check if window is minimized
if w.resolution.height() > 0.0 && w.resolution.height() > 0.0 { if w.resolution.height() > 0.0 && w.resolution.height() > 0.0 {

Loading…
Cancel
Save