Unify behind leader update

This commit is contained in:
hodasemi 2023-01-20 17:21:24 +01:00
parent 82b01ff056
commit 544f6d765d

View file

@ -172,15 +172,7 @@ impl LeaderBoard {
vehicle_scoring.mID, vehicle_scoring.mID,
driver_name, driver_name,
vehicle_scoring.mPlace, vehicle_scoring.mPlace,
{ Self::query_behind_leader(vehicle_scoring),
let laps_behind = vehicle_scoring.mLapsBehindLeader;
if laps_behind != 0 {
BehindLeader::Laps(laps_behind)
} else {
BehindLeader::Time(vehicle_scoring.mTimeBehindLeader)
}
},
vehicle_scoring.mTimeBehindNext, vehicle_scoring.mTimeBehindNext,
vehicle_scoring.mBestLapTime, vehicle_scoring.mBestLapTime,
)?; )?;
@ -334,18 +326,20 @@ impl LeaderBoard {
Ok(()) Ok(())
} }
fn query_behind_leader(scoring: &VehicleScoringInfoV01) -> BehindLeader {
let laps_behind = scoring.mLapsBehindLeader;
if laps_behind != 0 {
BehindLeader::Laps(laps_behind)
} else {
BehindLeader::Time(scoring.mTimeBehindLeader)
}
}
fn race_leaderboard(&mut self, vehicle_scorings: &[VehicleScoringInfoV01]) -> Result<()> { fn race_leaderboard(&mut self, vehicle_scorings: &[VehicleScoringInfoV01]) -> Result<()> {
self.update_leaderboard( self.update_leaderboard(
vehicle_scorings, vehicle_scorings,
|entry, scoring| { |entry, scoring| entry.update_time_behind_leader(Self::query_behind_leader(scoring)),
let laps_behind = scoring.mLapsBehindLeader;
if laps_behind != 0 {
entry.update_time_behind_leader(BehindLeader::Laps(laps_behind))
} else {
entry.update_time_behind_leader(BehindLeader::Time(scoring.mTimeBehindLeader))
}
},
|entry| entry.force_display_behind_leader(), |entry| entry.force_display_behind_leader(),
) )
} }