diff --git a/src/game.rs b/src/game.rs index 4c394d2..c6ce46f 100644 --- a/src/game.rs +++ b/src/game.rs @@ -16,8 +16,8 @@ impl Plugin for GamePlugin { .add_systems( Update, ( - menu::exit_to_menu.run_if(in_state(GameState::Play)), - menu::exit_to_menu.run_if(in_state(GameState::Endgame)), + menu::exit_to_menu + .run_if(in_state(GameState::Play).or_else(in_state(GameState::Endgame))), update_board .run_if(on_event::()) .after(handle_selection), diff --git a/src/intro.rs b/src/intro.rs index 229ddc1..1fd2ba5 100644 --- a/src/intro.rs +++ b/src/intro.rs @@ -6,35 +6,32 @@ pub(crate) struct IntroPlugin; impl Plugin for IntroPlugin { fn build(&self, app: &mut App) { - app.add_systems( + app.init_resource::() + .add_systems( OnExit(GameState::Loading), init_intro_text .run_if(resource_exists::()) .run_if(run_once()), ) .add_systems(OnEnter(GameState::Intro), manage_intro) - .add_systems(OnExit(GameState::Intro), deactivate::) - .add_systems( - Update, - manage_intro.run_if(any_component_removed::()), - ) + .add_systems(OnExit(GameState::Intro), (deactivate::, cleanup_intro)) + // All of these run during GameState::Intro .add_systems( Update, - // Started when the TextScrollAnimation component is added to the parent entity - // Updated for as long as there is scrolling text - manage_scroll_text_animation - .run_if(in_state(GameState::Intro)) - .run_if(any_component_added::.or_else( - |keys: Res>| -> bool { keys.just_pressed(KeyCode::Return) }, - )), - ) - .add_systems( - Update, - // Play intro manages playing the intro of each individual paragraph - // Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated - scroll_text - .run_if(in_state(GameState::Intro)) - .run_if(any_with_component::()), + ( + menu::exit_to_menu, + manage_intro.run_if(any_component_removed::()), + // Started when the TextScrollAnimation component is added to the parent entity + // Updated for as long as there is scrolling text + manage_scroll_text_animation + .run_if(any_component_added::.or_else( + |keys: Res>| -> bool { keys.just_pressed(KeyCode::Return) }, + )), + // Play intro manages playing the intro of each individual paragraph + // Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated + scroll_text + .run_if(any_with_component::()), + ).run_if(in_state(GameState::Intro)) ); } } @@ -127,16 +124,49 @@ fn manage_intro( query: Query, With, Without)>, mut commands: Commands, ) { + info!("Managing intro"); query.iter().for_each(|e| { commands .entity(e) .insert(ui::TextScrollAnimation) - .insert(Visibility::Inherited); + .insert(Visibility::Visible); + }); +} + +fn cleanup_intro( + query: Query>, + mut texts: Query<&mut Text, With>, + mut curr: ResMut, + tweaks_file: Res, + tweaks: Res>, + mut commands: Commands, +) { + info!("Cleaning up intro"); + + query.iter().for_each(|e| { + commands.entity(e).remove::().remove::().insert(Visibility::Hidden); }); + + { + // Reset text colors + let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks"); + let text_hidden_hex = tweak.get::("intro_rgba_hidden").unwrap(); + let text_hidden_color = Color::hex(text_hidden_hex).unwrap(); + texts.iter_mut().for_each(|mut text| { + text.sections.iter_mut().for_each(|s| { + s.style.color = text_hidden_color; + }); + }); + } + + curr.0 = None; } +#[derive(Debug, Resource, Default)] +struct CurrentIntroParagraph(Option); + fn manage_scroll_text_animation( - roots: Query>, + roots: Query, Added)>>, texts: Query, With)>, animated_texts: Query<&ui::TextScroll>, parents: Query<&Parent>, @@ -144,9 +174,11 @@ fn manage_scroll_text_animation( time: Res