Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splash screen allows exiting early (with escape key) #257

Merged
merged 12 commits into from
Aug 11, 2024
12 changes: 12 additions & 0 deletions src/screens/splash.rs
benfrankel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! A splash screen that plays briefly at startup.

use bevy::{
input::common_conditions::input_just_pressed,
prelude::*,
render::texture::{ImageLoaderSettings, ImageSampler},
};
Expand Down Expand Up @@ -35,12 +36,23 @@ pub(super) fn plugin(app: &mut App) {
)
.run_if(in_state(Screen::Splash)),
);

// Exit the splash screen early if the player hits escape.
app.add_systems(
Update,
exit_splash_screen
.run_if(input_just_pressed(KeyCode::Escape).and_then(in_state(Screen::Splash))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think that this reads better when written as two separate run_if because of the line break, but I'm not blocking on that.

Copy link
Collaborator

@benfrankel benfrankel Aug 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO that's confusing because you have to know whether that yields an and or an or behavior. Would be neat if run conditions could use && somehow to improve readability.

);
}

const SPLASH_BACKGROUND_COLOR: Color = Color::srgb(0.157, 0.157, 0.157);
const SPLASH_DURATION_SECS: f32 = 1.8;
const SPLASH_FADE_DURATION_SECS: f32 = 0.6;

fn exit_splash_screen(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Loading);
}

fn spawn_splash(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.ui_root()
Expand Down