From 1f84f3a96c133674e0b36cbf4bbe2d07175ef123 Mon Sep 17 00:00:00 2001 From: John Cote Date: Thu, 5 Dec 2019 22:17:10 -0500 Subject: [PATCH] racing: more progress on leaderboards --- toontown/ai/ToontownAIRepository.py | 5 ++++ toontown/racing/DistributedLeaderBoardAI.py | 30 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/toontown/ai/ToontownAIRepository.py b/toontown/ai/ToontownAIRepository.py index 4ce9d8c..748ac41 100644 --- a/toontown/ai/ToontownAIRepository.py +++ b/toontown/ai/ToontownAIRepository.py @@ -25,6 +25,7 @@ from toontown.hood.TTHoodDataAI import TTHoodDataAI from toontown.pets.PetManagerAI import PetManagerAI from toontown.quest.QuestManagerAI import QuestManagerAI from toontown.racing.DistributedLeaderBoardAI import DistributedLeaderBoardAI +from toontown.racing.RaceManagerAI import RaceManagerAI from toontown.shtiker.CogPageManagerAI import CogPageManagerAI from toontown.suit.SuitInvasionManagerAI import SuitInvasionManagerAI from toontown.toon import NPCToons @@ -50,6 +51,7 @@ class ToontownAIRepository(ToontownInternalRepository): self.questManager = None self.promotionMgr = None self.cogPageManager = None + self.raceMgr = None self.timeManager = None self.newsManager = None self.welcomeValleyManager = None @@ -114,6 +116,9 @@ class ToontownAIRepository(ToontownInternalRepository): # Create our Cog page manager... self.cogPageManager = CogPageManagerAI(self) + # Create our race manager... + self.raceMgr = RaceManagerAI(self) + def createGlobals(self): """ Creates "global" (distributed) objects. diff --git a/toontown/racing/DistributedLeaderBoardAI.py b/toontown/racing/DistributedLeaderBoardAI.py index 05ef4a4..9b4cb0c 100644 --- a/toontown/racing/DistributedLeaderBoardAI.py +++ b/toontown/racing/DistributedLeaderBoardAI.py @@ -1,6 +1,10 @@ +import cPickle + from direct.directnotify import DirectNotifyGlobal from direct.distributed.DistributedObjectAI import DistributedObjectAI +from toontown.toonbase import TTLocalizer + class DistributedLeaderBoardAI(DistributedObjectAI): notify = DirectNotifyGlobal.directNotify.newCategory('DistributedLeaderBoardAI') @@ -9,6 +13,14 @@ class DistributedLeaderBoardAI(DistributedObjectAI): DistributedObjectAI.__init__(self, air) self.name = name self.posHpr = (x, y, z, h, p, r) + self.records = {} + self.subscriptions = [] + self.currentIndex = -1 + + def announceGenerate(self): + DistributedObjectAI.announceGenerate(self) + self.accept('UpdateRaceRecord', self.handleUpdateRaceRecord) + self.accept('GS_LeaderBoardSwap' + str(self.zoneId), self.updateDisplay) def getName(self): return self.name @@ -17,4 +29,20 @@ class DistributedLeaderBoardAI(DistributedObjectAI): return self.posHpr def subscribeTo(self, subscription): - pass # TODO + self.records.setdefault(subscription[0], {})[subscription[1]] = [(x[0], x[3]) for x in + self.air.raceMgr.getRecords(subscription[0], + subscription[1])] + self.subscriptions.append(subscription) + + def handleUpdateRaceRecord(self, record): + self.notify.info('handleUpdateRaceRecord TODO') + + def updateDisplay(self): + self.currentIndex += 1 + if self.currentIndex >= len(self.subscriptions): + self.currentIndex = 0 + + trackName = TTLocalizer.KartRace_TrackNames[self.subscriptions[self.currentIndex][0]] + periodName = TTLocalizer.RecordPeriodStrings[self.subscriptions[self.currentIndex][1]] + leaderList = self.records[self.subscriptions[self.currentIndex][0]][self.subscriptions[self.currentIndex][1]] + self.sendUpdate('setDisplay', [cPickle.dumps((trackName, periodName, leaderList))])