Add proper reset function

This commit is contained in:
hodasemi 2023-01-20 05:49:57 +01:00
parent 790fc00aaa
commit a8bf3e85d7
2 changed files with 16 additions and 10 deletions

View file

@ -126,6 +126,14 @@ impl LeaderBoardEntry {
self.place_label.set_text(self.place) self.place_label.set_text(self.place)
} }
pub fn reset_time(&mut self) -> Result<()> {
self.behind = BehindLeader::Time(f64::MIN);
self.best_lap = f64::MIN;
self.time_behind_next = f64::MIN;
self.time_label.set_text("---")
}
pub fn update_time_behind_leader(&mut self, behind: BehindLeader) -> Result<()> { pub fn update_time_behind_leader(&mut self, behind: BehindLeader) -> Result<()> {
if self.behind != behind { if self.behind != behind {
self.behind = behind; self.behind = behind;
@ -149,13 +157,7 @@ impl LeaderBoardEntry {
} }
} }
BehindLeader::Laps(laps_behind) => { BehindLeader::Laps(laps_behind) => {
let text = if laps_behind == 1 { self.time_label.set_text(format!("+{}", laps_behind))?;
format!("+{} Lap", laps_behind)
} else {
format!("+{} Laps", laps_behind)
};
self.time_label.set_text(text)?;
} }
} }
} }
@ -167,7 +169,7 @@ impl LeaderBoardEntry {
if self.best_lap != time { if self.best_lap != time {
self.best_lap = time; self.best_lap = time;
if self.best_lap < 0.0 { if self.best_lap <= 0.0 {
self.time_label.set_text("---")?; self.time_label.set_text("---")?;
} else { } else {
let text = if self.best_lap > 60.0 { let text = if self.best_lap > 60.0 {

View file

@ -276,7 +276,7 @@ impl DataReceiver for LeaderBoard {
match phase { match phase {
GamePhase::Practice | GamePhase::Qualifying | GamePhase::TestDay => { GamePhase::Practice | GamePhase::Qualifying | GamePhase::TestDay => {
for entry in self.leaderboard_entries.iter_mut() { for entry in self.leaderboard_entries.iter_mut() {
entry.update_best_lap(-1.0)?; entry.reset_time()?;
} }
self.leaderboard.enable()?; self.leaderboard.enable()?;
@ -284,7 +284,11 @@ impl DataReceiver for LeaderBoard {
GamePhase::Race => { GamePhase::Race => {
for entry in self.leaderboard_entries.iter_mut() { for entry in self.leaderboard_entries.iter_mut() {
entry.update_time_behind_leader(BehindLeader::Time(0.0))?; entry.reset_time()?;
}
for entry in self.deltaboard_entries.iter_mut() {
entry.reset_time()?;
} }
self.leaderboard.enable()?; self.leaderboard.enable()?;