Skip to content
This repository has been archived by the owner on Jul 24, 2022. It is now read-only.

Commit

Permalink
fixed qualifying/practice bug for online races
Browse files Browse the repository at this point in the history
  • Loading branch information
3ximus committed Jun 20, 2020
1 parent 75bdc37 commit af75591
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
65 changes: 37 additions & 28 deletions apps/python/F12020Leaderboard/F12020Leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from FastestLapBanner import FastestLapBanner


MAX_LAP_TIME = 999999999
MAX_LAP_TIME = 99999999
OVER_MAX_TIME = 999999999

# TIMERS
timer0, timer1, timer2 = 0, 0, 0
Expand Down Expand Up @@ -346,9 +347,9 @@ def acUpdate(deltaT):


# ================================================================
# QUALIFY
# QUALIFY / PRACTICE
# ================================================================
elif info.graphics.session == 1:
elif info.graphics.session == 1 or (info.graphics.session == 0 and info.graphics.status != 0):

# 3 times per second
if timer1 > 0.3:
Expand All @@ -361,6 +362,8 @@ def acUpdate(deltaT):
# QUALIFY START
if not quali_started:
ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_QUALI)
if (info.graphics.session == 0 and info.graphics.status != 0):
ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_PRACTICE)
ac.setFontColor(lapCountTimerLabel, 0.86, 0.86, 0.86, 1)
qualify_session_time = info.graphics.sessionTimeLeft
fastest_lap = MAX_LAP_TIME
Expand All @@ -378,31 +381,36 @@ def acUpdate(deltaT):
fastest_lap = lap
fastest_lap_banner.show(lap, ac.getDriverName(i))

# =============================================
# MANAGE LEADERBOARD
dPosition = sorted(drivers, key=lambda x: x.best_lap)
for i in range(totalDrivers):
# MARK IN/OUT DRIVERS
connected = ac.isConnected(i)
if connected == 0: # mark unconnected drivers
drivers[i].out = True
else:
drivers[i].out = False

# =============================================
# MANAGE LEADERBOARD

# Sorting: sort drivers by this order 1. in or out drivers, 2. best lap, 3. driver id
dPosition = sorted(drivers, key=lambda d: (d.out, d.best_lap, d.id))

for i in range(totalDrivers):
if dPosition[i].out:
leaderboard[i].mark_out()
dPosition[i].out = True
dPosition[i].best_lap += 1 # checky hack to put unconnected drivers at the bottom of the leaderboard
else:
leaderboard[i].mark_in()
dPosition[i].out = False

leaderboard[i].update_name(dPosition[i].id)
if dPosition[i].best_lap == MAX_LAP_TIME:
leaderboard[i].update_time("NO TIME")
elif i == 0:
leaderboard[i].update_time(time_to_string(dPosition[i].best_lap))
leaderboard[i].update_name(dPosition[i].id)
if dPosition[i].best_lap == MAX_LAP_TIME:
leaderboard[i].update_time("NO TIME")
elif i == 0:
leaderboard[i].update_time(time_to_string(dPosition[i].best_lap))
else:
timeDiff = dPosition[i].best_lap - dPosition[0].best_lap
if timeDiff > 60000:
leaderboard[i].update_time("+1 MIN")
else:
timeDiff = dPosition[i].best_lap - dPosition[0].best_lap
if timeDiff > 60000:
leaderboard[i].update_time("+1 MIN")
else:
leaderboard[i].update_time("+" + time_to_string(timeDiff))
leaderboard[i].update_time("+" + time_to_string(timeDiff))

# OVERTAKES
if i != dPosition[i].position: # there was an overtake on this driver
Expand Down Expand Up @@ -536,14 +544,15 @@ def acUpdate(deltaT):
# DRIVER WIDGET UPDATE
if replay_started:
id = ac.getFocusedCar()
driverWidget.show(id, drivers[id].position, drivers[id].starting_position, drivers[id].tyre, drivers[id].pits)
if drivers[id].position == 0:
driverComparisonWidget.hide()
else:
for d in drivers: # find driver ahead
if d.position == drivers[id].position - 1:
driverComparisonWidget.show(d.id, d.position, id, drivers[id].position, drivers[id].timeDiff*1000)
break
if drivers[id].position <= totalDrivers: # in case it wasnt updated yet
driverWidget.show(id, drivers[id].position, drivers[id].starting_position, drivers[id].tyre, drivers[id].pits)
if drivers[id].position == 0:
driverComparisonWidget.hide()
else:
for d in drivers: # find driver ahead
if d.position == drivers[id].position - 1:
driverComparisonWidget.show(d.id, d.position, id, drivers[id].position, drivers[id].timeDiff*1000)
break
else:
driverWidget.hide()
driverComparisonWidget.hide()
Expand Down
1 change: 1 addition & 0 deletions apps/python/F12020Leaderboard/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FC:
LEADERBOARD_BACKGROUND = "apps/python/%s/ui/background.png" % APP_NAME
LEADERBOARD_BASE_RACE = "apps/python/%s/ui/race_base.png" % APP_NAME
LEADERBOARD_BASE_QUALI = "apps/python/%s/ui/quali_base.png" % APP_NAME
LEADERBOARD_BASE_PRACTICE = "apps/python/%s/ui/practice_base.png" % APP_NAME
LEADERBOARD_FINAL_LAP = "apps/python/%s/ui/final_lap.png" % APP_NAME
LEADERBOARD_INFO_BACKGROUNG = "apps/python/%s/ui/background_info.png" % APP_NAME
LEADERBOARD_PLAYER_HIGHLIGHT = "apps/python/%s/ui/highlight.png" % APP_NAME
Expand Down
4 changes: 2 additions & 2 deletions apps/python/F12020Leaderboard/teams.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ McLaren:mclaren:04:Speedster Marinho
Mercedes:mercedes:44:David Dias
Racing Point:racing_point:11:Dani Wizzardo
Red Bull:red_bull:33:Max Vermemes
Renault:renault:03:Idris Nitrol De Miranda
Rokit Williams:rokit_williams:06:Manel
Renault:renault:03:Idris Nitrol de Miranda
Rokit Williams:rokit_williams:06:Manel Gloria
Alfa Romeo:alfa_romeo:07:Tomas Martins
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit af75591

Please sign in to comment.