diff --git a/src/cmd.rs b/src/cmd.rs index 57dfa3a..1350b20 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -18,6 +18,10 @@ use crate::prelude::*; use regex::Regex; use std::time::SystemTime; +pub const ID_EARTH: &str = "earth"; +pub const ID_SOL: &str = "sol"; +pub const ID_JUPITER: &str = "jupiter"; + pub struct CmdPlugin; impl Plugin for CmdPlugin { fn build(&self, app: &mut App) { diff --git a/src/data/defs.txt b/src/data/defs.txt index b655278..410f7c5 100644 --- a/src/data/defs.txt +++ b/src/data/defs.txt @@ -35,6 +35,7 @@ actor 0 0 0 physics off actor 0 0 0 earth name Earth + id earth planet yes sphere yes physics off diff --git a/src/game.rs b/src/game.rs index 44548e5..c505057 100644 --- a/src/game.rs +++ b/src/game.rs @@ -49,6 +49,7 @@ pub enum AchievementEvent { RideVehicle(String), DrinkPizza, InJupitersShadow, + FindEarth, } #[derive(Event)] @@ -379,6 +380,12 @@ fn handle_achievement_event( } tracker.drink_a_pizza = true; } + AchievementEvent::FindEarth => { + if !tracker.find_earth { + ew_game.send(GameEvent::Achievement("Find Earth".into())); + } + tracker.find_earth = true; + } AchievementEvent::RideVehicle(name) => { tracker.vehicles_ridden.insert(name.clone()); let len = tracker.vehicles_ridden.len(); diff --git a/src/hud.rs b/src/hud.rs index 5db8943..d285912 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -974,7 +974,9 @@ fn handle_target_event( settings: Res, mut er_target: EventReader, mut ew_sfx: EventWriter, + mut ew_achievement: EventWriter, q_target: Query>, + q_ids: Query<&actor::Identifier>, ) { let mut play_sfx = false; @@ -986,6 +988,12 @@ fn handle_target_event( if let Some(entity) = target { commands.entity(*entity).insert(IsTargeted); play_sfx = true; + + if let Ok(id) = q_ids.get(*entity) { + if id.0 == cmd::ID_EARTH { + ew_achievement.send(game::AchievementEvent::FindEarth); + } + } } if play_sfx && !settings.mute_sfx { ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); diff --git a/src/menu.rs b/src/menu.rs index c632bd5..d13484c 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -71,6 +71,7 @@ pub enum MenuAction { pub fn setup( mut commands: Commands, asset_server: Res, + achievement_tracker: Res, settings: Res, ) { commands.spawn(( @@ -195,6 +196,7 @@ pub fn setup( color: settings.hud_color_achievement, ..default() }; + let achievement_count = achievement_tracker.to_bool_vec().len(); commands.spawn(( MenuElement, @@ -215,7 +217,7 @@ pub fn setup( let mut sections = vec![ TextSection::new("Achievements\n", style_achievement_header) ]; - sections.extend(Vec::from_iter((0..var::ACHIEVEMENT_COUNT).map(|_| + sections.extend(Vec::from_iter((0..achievement_count).map(|_| TextSection::new("", style_achievement.clone()) ))); builder.spawn(( diff --git a/src/var.rs b/src/var.rs index d3075ab..8581a60 100644 --- a/src/var.rs +++ b/src/var.rs @@ -20,7 +20,6 @@ use toml_edit::DocumentMut; use std::env; use std::fs; -pub const ACHIEVEMENT_COUNT: usize = 5; pub const SCOPE_SEPARATOR: &str = "$"; pub const TOKEN_EQUALS: &str = "=="; @@ -303,6 +302,7 @@ pub struct AchievementTracker { pub repair_suit: bool, pub drink_a_pizza: bool, pub in_jupiters_shadow: bool, + pub find_earth: bool, pub ride_every_vehicle: bool, pub vehicles_ridden: HashSet, @@ -320,6 +320,7 @@ impl AchievementTracker { self.drink_a_pizza, self.ride_every_vehicle, self.talk_to_everyone, + self.find_earth, self.in_jupiters_shadow, ] } @@ -338,6 +339,8 @@ impl AchievementTracker { format!("Talk To Everyone ({}/{})\n", self.people_talked_to.len(), self.all_people.len()), + format!("Find Earth ({})\n", + bool2string(self.find_earth)), format!("Let Jupiter Eclipse The Sun ({})\n", bool2string(self.in_jupiters_shadow)), ]