Unify behind leader update

This commit is contained in:
hodasemi 2023-01-20 17:21:24 +01:00
parent 440de381c7
commit 14030b137e

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 race_leaderboard(&mut self, vehicle_scorings: &[VehicleScoringInfoV01]) -> Result<()> { fn query_behind_leader(scoring: &VehicleScoringInfoV01) -> BehindLeader {
self.update_leaderboard(
vehicle_scorings,
|entry, scoring| {
let laps_behind = scoring.mLapsBehindLeader; let laps_behind = scoring.mLapsBehindLeader;
if laps_behind != 0 { if laps_behind != 0 {
entry.update_time_behind_leader(BehindLeader::Laps(laps_behind)) BehindLeader::Laps(laps_behind)
} else { } else {
entry.update_time_behind_leader(BehindLeader::Time(scoring.mTimeBehindLeader)) BehindLeader::Time(scoring.mTimeBehindLeader)
} }
}, }
fn race_leaderboard(&mut self, vehicle_scorings: &[VehicleScoringInfoV01]) -> Result<()> {
self.update_leaderboard(
vehicle_scorings,
|entry, scoring| entry.update_time_behind_leader(Self::query_behind_leader(scoring)),
|entry| entry.force_display_behind_leader(), |entry| entry.force_display_behind_leader(),
) )
} }