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