cargo fmt

main
Elijah C. Voigt 2 years ago
parent 207d691b2e
commit 7566ca1ca2

@ -13,13 +13,17 @@ impl Plugin for IntroPlugin {
.init_resource::<IntroProgress>() .init_resource::<IntroProgress>()
.add_systems(OnEnter(GameState::Intro), activate::<Intro>) .add_systems(OnEnter(GameState::Intro), activate::<Intro>)
.add_systems(OnExit(GameState::Intro), deactivate::<Intro>) .add_systems(OnExit(GameState::Intro), deactivate::<Intro>)
.add_systems(Update, manage_intro_progress .add_systems(
.run_if(in_state(GameState::Intro)) Update,
.run_if(not(resource_exists::<IntroPlayed>())) manage_intro_progress
.run_if(in_state(GameState::Intro))
.run_if(not(resource_exists::<IntroPlayed>())),
) )
.add_systems(Update, play_intro .add_systems(
.run_if(in_state(GameState::Intro)) Update,
.run_if(resource_changed::<IntroProgress>()) play_intro
.run_if(in_state(GameState::Intro))
.run_if(resource_changed::<IntroProgress>()),
) )
// Continue to play state if the intro is done playing out // Continue to play state if the intro is done playing out
.add_systems( .add_systems(
@ -89,9 +93,9 @@ fn init_intro_text(
fn manage_intro_progress( fn manage_intro_progress(
keys: Res<Input<KeyCode>>, keys: Res<Input<KeyCode>>,
mut start: Local<u32>, mut start: Local<u32>,
mut progress: ResMut<IntroProgress>, mut progress: ResMut<IntroProgress>,
framecount: Res<FrameCount>, framecount: Res<FrameCount>,
mut commands: Commands, mut commands: Commands,
tweaks_file: Res<tweak::GameTweaks>, tweaks_file: Res<tweak::GameTweaks>,
tweaks: Res<Assets<tweak::Tweaks>>, tweaks: Res<Assets<tweak::Tweaks>>,
) { ) {
@ -103,12 +107,10 @@ fn manage_intro_progress(
// If the user hits 'return' set this to the end of the animation // If the user hits 'return' set this to the end of the animation
if keys.just_pressed(KeyCode::Return) { if keys.just_pressed(KeyCode::Return) {
progress.0 = usize::MAX; progress.0 = usize::MAX;
commands.insert_resource(IntroPlayed); commands.insert_resource(IntroPlayed);
// Otherwise progress by N characters (1) // Otherwise progress by N characters (1)
} else { } else {
let tweak = tweaks let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
.get(tweaks_file.handle.clone())
.expect("Load tweaks");
let rate = tweak.get::<u32>("intro_rate").expect("[intro] rate = #"); let rate = tweak.get::<u32>("intro_rate").expect("[intro] rate = #");
progress.0 = ((framecount.0 - *start) / rate) as usize; progress.0 = ((framecount.0 - *start) / rate) as usize;
@ -117,9 +119,9 @@ fn manage_intro_progress(
// Upon entering the Intro state, start the intro "animation" // Upon entering the Intro state, start the intro "animation"
fn play_intro( fn play_intro(
mut text: Query<(&mut Text, &mut Visibility), With<Intro>>, mut text: Query<(&mut Text, &mut Visibility), With<Intro>>,
progress: Res<IntroProgress>, progress: Res<IntroProgress>,
mut commands: Commands, mut commands: Commands,
) { ) {
// Iterate over all (one) text // Iterate over all (one) text
text.iter_mut().for_each(|(mut t, mut v)| { text.iter_mut().for_each(|(mut t, mut v)| {
@ -133,9 +135,7 @@ fn play_intro(
.iter_mut() .iter_mut()
.enumerate() .enumerate()
// Only operate on sections up to this point // Only operate on sections up to this point
.filter_map(|(i, s)| { .filter_map(|(i, s)| (i <= progress.0).then_some(s))
(i <= progress.0).then_some(s)
})
// Set the alpha to 1.0 making it visible // Set the alpha to 1.0 making it visible
.for_each(|s| { .for_each(|s| {
s.style.color.set_a(1.0); s.style.color.set_a(1.0);

Loading…
Cancel
Save