From d20dc5c60d26650f17bd6d8e72f48a77390727f1 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 14 May 2024 06:28:14 +0200 Subject: [PATCH] summarize achievements on death screen --- src/game.rs | 6 ++---- src/menu.rs | 15 ++++++++++++--- src/var.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/world.rs | 2 ++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/game.rs b/src/game.rs index c505057..28b5b46 100644 --- a/src/game.rs +++ b/src/game.rs @@ -162,7 +162,6 @@ fn handle_player_death( mut active_asteroids: ResMut, mut ew_effect: EventWriter, mut ew_deathscreen: EventWriter, - mut achievement_tracker: ResMut, mut log: ResMut, mut settings: ResMut, ) { @@ -171,7 +170,6 @@ fn handle_player_death( return; } settings.reset_player_settings(); - *achievement_tracker = var::AchievementTracker::default(); active_asteroids.0.clear(); for entity in &q_noscenes { cmd.entity(entity).despawn(); @@ -338,7 +336,7 @@ fn debug( keyboard_input: Res>, mut commands: Commands, mut extended_materials: ResMut>>, - achievement_tracker: Res, + mut achievement_tracker: ResMut, materials: Query<(Entity, Option<&Name>, &Handle)>, ) { if settings.dev_mode && keyboard_input.just_pressed(KeyCode::KeyP) { @@ -351,7 +349,7 @@ fn debug( } } if settings.dev_mode && keyboard_input.just_pressed(KeyCode::KeyN) { - dbg!(achievement_tracker); + achievement_tracker.achieve_all(); } } diff --git a/src/menu.rs b/src/menu.rs index d13484c..950aca1 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -88,7 +88,7 @@ pub fn setup( let style_death = TextStyle { font: font_handle.clone(), font_size: settings.font_size_deathtext, - color: settings.hud_color_subtitles, + color: settings.hud_color_death, ..default() }; let style_death_poem = TextStyle { @@ -100,13 +100,19 @@ pub fn setup( let style_death_subtext = TextStyle { font: font_handle.clone(), font_size: settings.font_size_deathsubtext, - color: settings.hud_color_subtitles, + color: settings.hud_color_death, ..default() }; let style_death_subsubtext = TextStyle { font: font_handle.clone(), font_size: settings.font_size_deathsubtext * 0.8, - color: settings.hud_color_subtitles, + color: settings.hud_color_death, + ..default() + }; + let style_death_achievements = TextStyle { + font: font_handle.clone(), + font_size: settings.font_size_death_achievements, + color: settings.hud_color_death_achievements, ..default() }; commands.spawn(( @@ -126,6 +132,7 @@ pub fn setup( TextSection::new("You are dead.\n", style_death), TextSection::new("Cause: ", style_death_subtext.clone()), TextSection::new("Unknown", style_death_subtext), + TextSection::new("", style_death_achievements), TextSection::new("\n\n\n\nPress E to begin anew.", style_death_subsubtext), ], justify: JustifyText::Center, @@ -247,6 +254,7 @@ pub fn show_deathscreen( mut timer: ResMut, mut menustate: ResMut, mut settings: ResMut, + achievement_tracker: Res, ) { for event in er_deathscreen.read() { let show = *event == DeathScreenEvent::Show; @@ -269,6 +277,7 @@ pub fn show_deathscreen( text.sections[0].value = poem + "\n\n\n\n"; } text.sections[3].value = settings.death_cause.clone(); + text.sections[4].value = achievement_tracker.to_summary(); } } else { ew_respawnaudiosinks.send(audio::RespawnSinksEvent); diff --git a/src/var.rs b/src/var.rs index 4403689..6f677b5 100644 --- a/src/var.rs +++ b/src/var.rs @@ -56,6 +56,7 @@ pub struct Settings { pub font_size_deathtext: f32, pub font_size_deathsubtext: f32, pub font_size_deathpoem: f32, + pub font_size_death_achievements: f32, pub font_size_achievement: f32, pub font_size_achievement_header: f32, pub hud_color: Color, @@ -71,6 +72,8 @@ pub struct Settings { pub hud_color_achievement: Color, pub hud_color_achievement_header: Color, pub hud_color_achievement_accomplished: Color, + pub hud_color_death: Color, + pub hud_color_death_achievements: Color, pub chat_speed: f32, pub flashlight_active: bool, pub hud_active: bool, @@ -174,6 +177,7 @@ impl Default for Settings { font_size_deathtext: 64.0, font_size_deathsubtext: 32.0, font_size_deathpoem: 18.0, + font_size_death_achievements: 24.0, font_size_achievement: 24.0, font_size_achievement_header: 32.0, hud_color: Color::hex("#BE1251").unwrap(), @@ -189,6 +193,8 @@ impl Default for Settings { hud_color_achievement: Color::hex("#666666").unwrap(), hud_color_achievement_accomplished: Color::hex("#F0D50C").unwrap(), hud_color_achievement_header: Color::hex("#BE1251").unwrap(), + hud_color_death: Color::hex("#CCCCCC").unwrap(), + hud_color_death_achievements: Color::hex("#CCCCCC").unwrap(), chat_speed: DEFAULT_CHAT_SPEED * if dev_mode { 2.5 } else { 1.0 }, flashlight_active: false, hud_active: true, @@ -324,6 +330,14 @@ impl AchievementTracker { self.in_jupiters_shadow, ] } + pub fn achieve_all(&mut self) { + self.repair_suit = true; + self.drink_a_pizza = true; + self.ride_every_vehicle = true; + self.talk_to_everyone = true; + self.find_earth = true; + self.in_jupiters_shadow = true; + } pub fn to_textsections(&self) -> Vec { fn collectible(current: usize, total: usize) -> String { if current < total { @@ -343,6 +357,40 @@ impl AchievementTracker { "Let Jupiter Eclipse The Sun\n".to_string(), ] } + pub fn to_overview(&self) -> Vec<(bool, String)> { + vec![ + (self.repair_suit, "repair your suit".into()), + (self.drink_a_pizza, "consume a pizza".into()), + (self.ride_every_vehicle, "ride every vehicle".into()), + (self.talk_to_everyone, "talk to everyone".into()), + (self.find_earth, "find Earth".into()), + (self.in_jupiters_shadow, "let Jupiter eclipse the Sun".into()), + ] + } + pub fn to_summary(&self) -> String { + let list = self.to_overview(); + let count = list.iter().filter(|(achieved, _)| *achieved).count(); + if count == 0 { + return "".to_string() + } + let mut summary = "\n\n\nYou managed to ".to_string(); + for (i, (_, text)) in list.iter().filter(|(achieved, _)| *achieved).enumerate() { + summary += text.as_str(); + if i + 2 == count { + summary += ", and "; + } + else if i + 1 == count { + summary += " before you perished."; + if count == list.len() { + summary += "\nA truly astounding achievement, a glimmer in the void, before it all fades, into nothingness."; + } + } + else { + summary += ", "; + } + } + summary + } } #[derive(Resource, Deserialize, Debug, Default)] diff --git a/src/world.rs b/src/world.rs index 975b431..70e85ca 100644 --- a/src/world.rs +++ b/src/world.rs @@ -346,6 +346,8 @@ fn handle_despawn( fn handle_respawn( ew_spawn: EventWriter, + mut achievement_tracker: ResMut, ) { + *achievement_tracker = var::AchievementTracker::default(); cmd::load_defs(ew_spawn); }