Handle more states of drivers

This commit is contained in:
hodasemi 2023-01-20 17:27:09 +01:00
parent 14030b137e
commit c152132c74
2 changed files with 36 additions and 5 deletions

View file

@ -9,6 +9,9 @@ use vulkan_rs::prelude::*;
pub enum BehindLeader { pub enum BehindLeader {
Time(f64), Time(f64),
Laps(i32), Laps(i32),
DNF,
DSQ,
PITS,
} }
pub struct LeaderBoardEntry { pub struct LeaderBoardEntry {
@ -164,6 +167,15 @@ impl LeaderBoardEntry {
BehindLeader::Laps(laps_behind) => { BehindLeader::Laps(laps_behind) => {
self.time_label.set_text(format!("+{}", laps_behind))?; self.time_label.set_text(format!("+{}", laps_behind))?;
} }
BehindLeader::DNF => {
self.time_label.set_text("DNF")?;
}
BehindLeader::DSQ => {
self.time_label.set_text("DSQ")?;
}
BehindLeader::PITS => {
self.time_label.set_text("PIT")?;
}
} }
Ok(()) Ok(())

View file

@ -327,12 +327,31 @@ impl LeaderBoard {
} }
fn query_behind_leader(scoring: &VehicleScoringInfoV01) -> BehindLeader { fn query_behind_leader(scoring: &VehicleScoringInfoV01) -> BehindLeader {
let laps_behind = scoring.mLapsBehindLeader; match scoring.mFinishStatus {
0 | 1 => {
if scoring.mInPits != 0 {
BehindLeader::PITS
} else {
let laps_behind = scoring.mLapsBehindLeader;
if laps_behind != 0 { if laps_behind != 0 {
BehindLeader::Laps(laps_behind) BehindLeader::Laps(laps_behind)
} else { } else {
BehindLeader::Time(scoring.mTimeBehindLeader) BehindLeader::Time(scoring.mTimeBehindLeader)
}
}
}
2 => BehindLeader::DNF,
3 => BehindLeader::DSQ,
_ => {
write_log!(format!(
"not allowed finish state: {}",
scoring.mFinishStatus
));
BehindLeader::Time(scoring.mTimeBehindLeader)
}
} }
} }