racing: we got leaderboards
This commit is contained in:
parent
22486021aa
commit
ec12097b06
3 changed files with 12 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ whitelist/
|
||||||
*.jpg
|
*.jpg
|
||||||
.idea
|
.idea
|
||||||
*.buildings
|
*.buildings
|
||||||
|
*.trackRecords
|
||||||
|
|
|
@ -35,7 +35,11 @@ class DistributedLeaderBoardAI(DistributedObjectAI):
|
||||||
self.subscriptions.append(subscription)
|
self.subscriptions.append(subscription)
|
||||||
|
|
||||||
def handleUpdateRaceRecord(self, record):
|
def handleUpdateRaceRecord(self, record):
|
||||||
self.notify.info('handleUpdateRaceRecord TODO')
|
trackId, period = record
|
||||||
|
if trackId not in self.records:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.records[trackId][period] = [(x[0], x[3]) for x in self.air.raceMgr.getRecords(trackId, period)]
|
||||||
|
|
||||||
def updateDisplay(self):
|
def updateDisplay(self):
|
||||||
self.currentIndex += 1
|
self.currentIndex += 1
|
||||||
|
|
|
@ -323,7 +323,7 @@ class RaceManagerAI(DirectObject.DirectObject):
|
||||||
self.notify.debug('trophies %s' % trophies)
|
self.notify.debug('trophies %s' % trophies)
|
||||||
self.notify.debug('GrandTouring: already has grand touring %s' % trophies[RaceGlobals.GrandTouring])
|
self.notify.debug('GrandTouring: already has grand touring %s' % trophies[RaceGlobals.GrandTouring])
|
||||||
for i in range(1, RaceGlobals.NumTrophies // RaceGlobals.TrophiesPerCup + 1):
|
for i in range(1, RaceGlobals.NumTrophies // RaceGlobals.TrophiesPerCup + 1):
|
||||||
cupNum = (trophies[:RaceGlobals.NumTrophies].count(1) + addTrophyCount) / (i * RaceGlobals.TrophiesPerCup)
|
cupNum = (trophies[:RaceGlobals.NumTrophies].count(1) + addTrophyCount) // (i * RaceGlobals.TrophiesPerCup)
|
||||||
self.notify.debug('cupNum: %s' % cupNum)
|
self.notify.debug('cupNum: %s' % cupNum)
|
||||||
trophyIndex = RaceGlobals.TrophyCups[i - 1]
|
trophyIndex = RaceGlobals.TrophyCups[i - 1]
|
||||||
if cupNum and not trophies[trophyIndex]:
|
if cupNum and not trophies[trophyIndex]:
|
||||||
|
@ -545,8 +545,8 @@ class RaceManagerAI(DirectObject.DirectObject):
|
||||||
newTrophies.append(totalTrophyIndex)
|
newTrophies.append(totalTrophyIndex)
|
||||||
self.air.writeServerEvent('kartingTrophy', avId, '%s' % totalTrophyIndex)
|
self.air.writeServerEvent('kartingTrophy', avId, '%s' % totalTrophyIndex)
|
||||||
self.notify.debug('trophy: ' + TTLocalizer.KartTrophyDescriptions[totalTrophyIndex])
|
self.notify.debug('trophy: ' + TTLocalizer.KartTrophyDescriptions[totalTrophyIndex])
|
||||||
for i in range(1, RaceGlobals.NumTrophies / RaceGlobals.TrophiesPerCup + 1):
|
for i in range(1, RaceGlobals.NumTrophies // RaceGlobals.TrophiesPerCup + 1):
|
||||||
cupNum = trophies[:RaceGlobals.NumTrophies].count(1) / (i * RaceGlobals.TrophiesPerCup)
|
cupNum = trophies[:RaceGlobals.NumTrophies].count(1) // (i * RaceGlobals.TrophiesPerCup)
|
||||||
self.notify.debug('cupNum: %s' % cupNum)
|
self.notify.debug('cupNum: %s' % cupNum)
|
||||||
trophyIndex = RaceGlobals.TrophyCups[i - 1]
|
trophyIndex = RaceGlobals.TrophyCups[i - 1]
|
||||||
if cupNum and not trophies[trophyIndex]:
|
if cupNum and not trophies[trophyIndex]:
|
||||||
|
@ -610,7 +610,7 @@ class RaceManagerAI(DirectObject.DirectObject):
|
||||||
backup = self.filename + '.bu'
|
backup = self.filename + '.bu'
|
||||||
if os.path.exists(self.filename):
|
if os.path.exists(self.filename):
|
||||||
os.rename(self.filename, backup)
|
os.rename(self.filename, backup)
|
||||||
file = open(self.filename, 'w')
|
file = open(self.filename, 'wb')
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
pickle.dump(self.trackRecords, file)
|
pickle.dump(self.trackRecords, file)
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -624,12 +624,12 @@ class RaceManagerAI(DirectObject.DirectObject):
|
||||||
|
|
||||||
def loadRecords(self):
|
def loadRecords(self):
|
||||||
try:
|
try:
|
||||||
file = open(self.filename + '.bu', 'r')
|
file = open(self.filename + '.bu', 'rb')
|
||||||
if os.path.exists(self.filename):
|
if os.path.exists(self.filename):
|
||||||
os.remove(self.filename)
|
os.remove(self.filename)
|
||||||
except IOError:
|
except IOError:
|
||||||
try:
|
try:
|
||||||
file = open(self.filename, 'r')
|
file = open(self.filename, 'rb')
|
||||||
except IOError:
|
except IOError:
|
||||||
return self.getRecordTimes()
|
return self.getRecordTimes()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue