示例#1
0
文件: acinfo.py 项目: prunn/ACTV
 def getSector(self):
     splits=ac.getCurrentSplits(self.currentVehicule.value)
     i=0 
     sector=0  
     for c in splits: 
         i+=1
         if c > 0: 
             sector=i
     return sector
示例#2
0
文件: acinfo.py 项目: prunn/ACTV
 def onUpdate(self, sim_info, fl):
     self.session.setValue(sim_info.graphics.session)
     self.manageWindow()
     self.animate()
     if self.carsCount==0:
         self.carsCount = ac.getCarsCount()
     sessionTimeLeft=sim_info.graphics.sessionTimeLeft
     sim_info_status=sim_info.graphics.status
     self.currentVehicule.setValue(ac.getFocusedCar())        
     backupLaptime=0
     backupLastLapInPits=0
     if len(self.lapTimesArray) < self.carsCount:
         for x in range(self.carsCount):
             c = ac.getCarState(x,acsys.CS.LapCount)
             self.driversLap.append(Value(c))
             self.lapTimesArray.append(lapTimeStart(c,sessionTimeLeft,0)) 
     else:
         for x in range(self.carsCount):
             c = ac.getCarState(x,acsys.CS.LapCount)
             self.driversLap[x].setValue(c)
             if self.driversLap[x].hasChanged():
                 self.lapTimesArray[x].lap=self.driversLap[x].value
                 self.lapTimesArray[x].time=sessionTimeLeft
             if bool(ac.isCarInPitline(x)) or bool(ac.isCarInPit(x)):
                 self.lapTimesArray[x].lastpit=c
             if x == self.currentVehicule.value:
                 backupLaptime=self.lapTimesArray[x].time-sessionTimeLeft
                 self.lastLapStart = self.lapTimesArray[x].time
                 backupLastLapInPits = self.lapTimesArray[x].lastpit
     
                         
     currentVehiculeChanged=self.currentVehicule.hasChanged()
                 
     if currentVehiculeChanged or (self.fastestLapBorderActive and sessionTimeLeft < self.visible_end-2000):
         self.fastestLapBorderActive = False
         car = ac.getCarName(self.currentVehicule.value)        
         self.lbl_border.setBgColor(Colors.colorFromCar(car))           
         
     if sim_info_status == 2:
         #LIVE
         strOffset = "  "
         #self.nameOffset=14
         if self.session.value != 2 :
             #NOT RACE
             #qtime 
             self.fastestLap.setValue(fl)         
             bestlap = ac.getCarState(self.currentVehicule.value,acsys.CS.BestLap)
             isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value)))
             LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount)
             if self.lastLap != LapCount:
                 self.lastLap = LapCount
                 self.firstLapStarted=False
                 if self.currentVehicule.value==0:
                     self.lastLapStart = sessionTimeLeft
             curLapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
             if curLapTime == 0 and backupLaptime > 0 and self.minLapCount > 0:
                 curLapTime = backupLaptime
             if curLapTime > 0:
                 self.firstLapStarted=True
             #if self.minLapCount == 0 and self.firstLapStarted and ((self.lastLapTime > curLapTime and curLapTime < 1000) or self.lastLapStart==10000):
             #    self.lastLapStart = sessionTimeLeft                  
             self.lastLapTime = curLapTime
                               
             if isInPit :
                 self.lastLapInPit = LapCount
                 self.lastTimeInPit = sessionTimeLeft
             if self.currentVehicule.value==0 and sim_info.physics.numberOfTyresOut >= 4 and self.lapCanBeInvalidated:
                 self.lastLapInvalidated = LapCount
             if isInPit and self.minLapCount == 0:
                 self.lastLapInvalidated = -1
             if self.sectorCount < 0:
                 self.sectorCount = sim_info.static.sectorCount    
             
             if self.fastestLap.value > 0:
                 for x in range(self.carsCount): 
                     c = ac.getCarState(x,acsys.CS.BestLap)
                     if self.fastestLap2.value == 0 or (c > 0 and c < self.fastestLap2.value):               
                         self.fastestLap2.setValue(c)
                         self.fastestLapSectors = ac.getLastSplits(x)
             else:
                 self.fastestLapSectors = [0,0,0,0,0,0]
                         
             #lapInvalidated = bool(ac.getCarState(0, acsys.CS.LapInvalidated))
             lapInvalidated = bool(self.lastLapInvalidated==LapCount)
             if currentVehiculeChanged or self.lbl_driver_name_text.value=="":
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
             #sector_delay = 5000
             # live or info      
             #ac.console("("+str(self.lastLapInPit)+" < "+str(LapCount)+" or "+str(self.minLapCount)+"==0) and not "+str(lapInvalidated)+" and ("+str(self.lastTimeInPit)+"==0 or "+str(self.lastTimeInPit)+" > "+str(self.lastLapStart)+")")            
             if ((self.lastLapStart < 0 and self.minLapCount > 0) or (self.minLapCount == 0 and lapInvalidated)) and self.session.value != 0:                    
                 self.lbl_driver_name_visible.setValue(0)
                 self.lbl_timing_visible.setValue(0)  
                 self.lbl_split.hideText()  
                 self.info_position.hide()
                 self.info_position_lead.hide()          
             elif (self.lastLapInPit < LapCount or self.minLapCount==0) and not lapInvalidated and (self.lastTimeInPit==0 or self.lastTimeInPit > self.lastLapStart or self.minLapCount==0) :
                 
                 if self.currentVehicule.value == 0:
                     sector = sim_info.graphics.currentSectorIndex
                 else:
                     sector = self.getSector()
                 
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_timing_visible.setValue(1)  
                 
                 #lapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
                 if self.currentVehicule.value == 0:
                     lastLap = sim_info.graphics.iLastTime
                 else: 
                     lastLap=0                       
                     lastSplits = ac.getLastSplits(self.currentVehicule.value)
                     for c in lastSplits:
                         lastLap+=c
                     if lastLap==0:
                         lastLap=ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap)
                         
                 
                 traite=False
                 cur_splits = ac.getCurrentSplits(self.currentVehicule.value)
                 timeSplit=0
                 fastestSplit=0
                 i=0
                 showSplit=False
                 for c in cur_splits: 
                     if c > 0:
                         timeSplit+=c 
                         fastestSplit+=self.fastestLapSectors[i]
                         i+=1
                 fastestSplit_fin=fastestSplit
                 if i < self.sectorCount:
                     fastestSplit_fin+=self.fastestLapSectors[i]
                      
                 #Situation
                 for s in range(0,self.sectorCount):                    
                     if self.fastestLap.value > 0 and curLapTime > fastestSplit_fin - self.sector_delay:
                         #LAST_SECONDS_OF_SECTOR_X, sector == s and
                         self.info_position.hide() 
                         self.nameOffset=self.rowHeight*14/36 #14
                         if self.sectorCount-1 == sector:
                             #LAST_SECONDS_OF_SECTOR_LAP,
                             self.lbl_split.setText(self.time_splitting(self.fastestLap.value,"yes")).setColor(Colors.white()).showText()
                             self.info_position_lead.show() 
                             
                             showSplit=True
                         elif fastestSplit_fin > 0:
                             self.lbl_split.setText(self.time_splitting(fastestSplit_fin,"yes")).setColor(Colors.white()).showText()
                             self.info_position_lead.show() 
                             showSplit=True
                         break
                     if sector == s + 1 and s + 1 <= self.sectorCount and curLapTime - timeSplit <= self.sector_delay and fastestSplit > 0 :
                         #SECTOR_X_FINISHED_BEGIN_SECTOR_Y    
                         self.nameOffset=self.rowHeight*14/36 #14            
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(timeSplit,"yes")) 
                         if fastestSplit < timeSplit:
                             self.lbl_split.setText("+"+self.time_splitting(timeSplit-fastestSplit,"yes")).setColor(Colors.yellow()).showText()
                         else:
                             self.lbl_split.setText("-"+self.time_splitting(fastestSplit-timeSplit,"yes")).setColor(Colors.green()).showText()
                         self.info_position_lead.show() 
                         self.info_position.hide()
                         traite=True
                         break
                 
                 if not traite:
                     if self.sectorCount-1 == sector and self.fastestLap.value > 0 and curLapTime > self.fastestLap.value - self.sector_delay:
                         #LAST_SECONDS_OF_SECTOR_LAP,
                         self.nameOffset=self.rowHeight*14/36 #14
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime)) 
                         self.info_position.hide()
                         #self.lbl_split.setText(self.time_splitting(self.fastestLap,"yes") + strOffset).setVisible(1)
                     elif self.lastLapInvalidated!=LapCount-1 and ((self.lastLapInPit!=LapCount-1 and sector == 0) or (self.minLapCount==0)) and curLapTime <= self.sector_delay and lastLap > 0:
                         #LAP_FINISHED_BEGIN_NEW_LAP,                       
                         pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                         if pos == -1:
                             pos = self.getStandingsPosition(self.currentVehicule.value)                                
             
                         if pos > 1:
                             self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(0.8)
                         else:
                             self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(0.8)
                         self.info_position.setText(str(pos))
                         self.info_position.show()
                         
                         self.nameOffset=self.rowHeight*49/36 #49
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(lastLap,"yes")) 
                         if self.fastestLap.value < lastLap:
                             self.lbl_split.setText("+"+self.time_splitting(lastLap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()
                         else:                            
                             self.lbl_split.setText("-"+self.time_splitting(self.getBestLap()-lastLap,"yes")).setColor(Colors.green()).showText()
                         self.info_position_lead.show() 
                         
                     else:
                         #OTHER
                         self.nameOffset=self.rowHeight*14/36 #14
                         self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime))  
                         self.info_position.hide()
                         if not showSplit:
                             self.lbl_split.hideText()
                             self.info_position_lead.hide()
                 self.fastestLap.changed=False
             else :                    
                 self.info_position_lead.hide()                     
                 normalizedSplinePosition = ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition)
                 if normalizedSplinePosition <= 0.001:
                     normalizedSplinePosition=1
                 if sessionTimeLeft > 0 and self.minLapCount==1 and normalizedSplinePosition > 0.95 and not isInPit :          
                     self.lbl_driver_name_visible.setValue(1)
                     self.nameOffset=self.rowHeight*14/36 #14
                     self.lbl_timing_visible.setValue(1)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()
                     self.lbl_timing_text.setValue(strOffset + "0.0") 
                     
                 elif lapInvalidated and self.lastLapInPit < LapCount and self.minLapCount > 0 :
                     self.lbl_driver_name_visible.setValue(0)
                     self.lbl_timing_visible.setValue(0)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()  
                 elif bestlap > 0 :             
                     self.lbl_driver_name_visible.setValue(1)
                     self.lbl_timing_visible.setValue(1)  
                      
                     if self.fastestLap.value < bestlap:
                         self.lbl_split.setText("+"+self.time_splitting(bestlap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()                           
                     else:                            
                         self.lbl_split.hideText()
                     
                     self.lbl_timing_text.setValue(strOffset + self.time_splitting(bestlap,"yes")) 
                                         
                     self.nameOffset=self.rowHeight*49/36 #49
                     #pos = sim_info.graphics.position
                     pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                     if pos == -1:
                         pos = self.getStandingsPosition(self.currentVehicule.value) 
                     if pos > 1:
                         self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
                     else:
                         self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
                     self.info_position.setText(str(pos)).show()   
                     self.lbl_position_text.setValue(str(pos))                
                         
                 elif isInPit :     
                     self.lbl_driver_name_visible.setValue(0)
                     self.lbl_timing_visible.setValue(0)  
                     self.lbl_split.hideText()  
                     self.info_position.hide()
                 else :
                     self.nameOffset=self.rowHeight*14/36 #14
                     self.lbl_driver_name_visible.setValue(1)
                     self.lbl_timing_visible.setValue(1)
                     if self.currentVehicule.value==0:
                         self.lbl_timing_text.setValue(strOffset + self.format_tire(sim_info.graphics.tyreCompound))
                     else:
                         self.lbl_timing_text.setValue(strOffset + "Out Lap")
                     self.lbl_split.hideText()
                     self.info_position.hide() 
                  
             if curLapTime <= self.sector_delay and ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap) > 0 and backupLastLapInPits + 1 < ac.getCarState(x,acsys.CS.LapCount) and sessionTimeLeft < 0:
                 self.nameOffset=self.rowHeight*49/36 #49
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_timing_visible.setValue(1)
                 self.lbl_split.showText()
                 self.info_position.show() 
                 #time vis
             self.visibilityQualif()
                 
         else:
             ################ Race ################
             self.info_position_lead.hide() 
             self.lbl_split.hideText()
             #fastest lap
             completed=0
             for x in range(self.carsCount): 
                 c = ac.getCarState(x,acsys.CS.LapCount)
                 if c > completed:
                     completed=c
             if completed <=1:
                 self.race_fastest_lap.setValue(0)
             else:
                 for i in range(self.carsCount): 
                     bl=ac.getCarState(i,acsys.CS.BestLap)
                     l = ac.getCarState(i,acsys.CS.LapCount)
                     if bl > 0 and l > self.minLapCount and (self.race_fastest_lap.value == 0 or bl < self.race_fastest_lap.value):
                         self.race_fastest_lap.setValue(bl)
                         self.race_fastest_lap_driver.setValue(i)
                     
             if self.race_fastest_lap.hasChanged() and self.race_fastest_lap.value > 0:
                 self.fastestLapBorderActive = True
                 car = ac.getCarName(self.race_fastest_lap_driver.value)        
                 self.lbl_border.setBgColor(Colors.colorFromCar(car))            
                 self.visible_end = sessionTimeLeft - 8000
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.race_fastest_lap_driver.value)))
                 self.nameOffset=self.rowHeight*14/36 #14
                 self.lbl_timing_text.setValue(strOffset + "Fastest Lap")
                 self.lbl_timing_visible.setValue(1)
                 self.info_position.hide() 
                 self.lbl_fastest_split.setText(self.time_splitting(self.race_fastest_lap.value,"yes")).showText()
                 
             elif currentVehiculeChanged:  
                 #driver info                  
                 self.visible_end = sessionTimeLeft - 8000
                 self.lbl_driver_name_visible.setValue(1)
                 self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
                 self.nameOffset=self.rowHeight*49/36 #49
                 #pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
                 pos = ac.getCarRealTimeLeaderboardPosition(self.currentVehicule.value) + 1
                 if pos > 1:
                     self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
                 else:
                     self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
                 self.info_position.setText(str(pos)).show() 
                 self.lbl_timing_visible.setValue(0)
                 self.lbl_fastest_split.hideText()
             elif self.visible_end == 0 or sessionTimeLeft < self.visible_end or sessionTimeLeft > 1800000:
                 self.lbl_driver_name_visible.setValue(0)
                 self.info_position.hide()
                 self.lbl_timing_visible.setValue(0)
                 self.lbl_fastest_split.hideText()
                 
             self.visibilityRace()
                 
     elif sim_info_status == 1 and self.session.value != 2:
         #Replay Qualif
         strOffset = "  "
         showSplit=False
         LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount)
         curLapTime = ac.getCarState(self.currentVehicule.value, acsys.CS.LapTime)
         isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value)))
         if currentVehiculeChanged or self.lbl_driver_name_text.value=="":
             self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
         if isInPit:
             self.lbl_driver_name_visible.setValue(0)
             self.lbl_timing_visible.setValue(0)  
             self.lbl_split.hideText()  
             self.info_position.hide()
         elif curLapTime <= self.sector_delay and LapCount > 1:
             #show last lap
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             if self.currentVehicule.value == 0:
                 lastLap = sim_info.graphics.iLastTime
             else: 
                 lastLap=0                       
                 lastSplits = ac.getLastSplits(self.currentVehicule.value)
                 for c in lastSplits:
                     lastLap+=c
                 if lastLap==0:
                     lastLap=ac.getCarState(self.currentVehicule.value, acsys.CS.LastLap)
             pos = ac.getCarLeaderboardPosition(self.currentVehicule.value)
             if pos == -1:
                 pos = self.getStandingsPosition(self.currentVehicule.value)                                
 
             if pos > 1:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(0.8)
             else:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(0.8)
             self.info_position.setText(str(pos))
             self.info_position.show()
             self.nameOffset=self.rowHeight*49/36 #49
             self.lbl_timing_text.setValue(strOffset + self.time_splitting(lastLap,"yes")) 
             if self.fastestLap.value < lastLap:
                 self.lbl_split.setText("+"+self.time_splitting(lastLap-self.fastestLap.value,"yes")).setColor(Colors.yellow()).showText()
             else:                            
                 self.lbl_split.setText("-"+self.time_splitting(self.fastestLap.old-lastLap,"yes")).setColor(Colors.green()).showText()
             self.info_position_lead.show()
             self.fastestLap.changed=False
         elif LapCount > self.minLapCount:
             #showTiming
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             self.info_position_lead.hide() 
             self.nameOffset=self.rowHeight*14/36 #14
             self.lbl_timing_text.setValue(strOffset + self.time_splitting(curLapTime))  
             self.info_position.hide()
             if not showSplit:
                 self.lbl_split.hideText()
                 self.info_position_lead.hide()
         else:
             #showTireInfo
             self.info_position_lead.hide() 
             self.nameOffset=self.rowHeight*14/36 #14
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_timing_visible.setValue(1)
             if self.currentVehicule.value==0:
                 self.lbl_timing_text.setValue(strOffset + self.format_tire(sim_info.graphics.tyreCompound))
             else:
                 self.lbl_timing_text.setValue(strOffset + "Out Lap")
             self.lbl_split.hideText()
             self.info_position.hide()            
         
         self.visibilityQualif()
             
             
         
     elif sim_info_status == 1 and self.session.value == 2:
         #Replay Race
         todo=1
         '''
         if currentVehiculeChanged:
             self.visible_end = sessionTimeLeft - 8000
             self.lbl_driver_name_visible.setValue(1)
             self.lbl_driver_name_text.setValue(self.format_name(ac.getDriverName(self.currentVehicule.value)))
             self.nameOffset=self.rowHeight*49/36 #49
             pos = ac.getCarRealTimeLeaderboardPosition(self.currentVehicule.value) + 1
             if pos > 1:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.grey(bg = True)).setBgOpacity(1)
             else:
                 self.info_position.setColor(Colors.white()).setBgColor(Colors.red(bg = True)).setBgOpacity(1)
             self.info_position.setText(str(pos)).show() 
             self.lbl_timing_visible.setValue(0)
             self.lbl_fastest_split.hideText()
             
             if self.lbl_driver_name_visible.hasChanged():         
                 if self.lbl_driver_name_visible.value == 0:
                     self.lbl_driver_name.hide()
                     self.lbl_border.hide()
                 else:
                     self.lbl_driver_name.show()
                     self.lbl_border.show()
                 
             if self.lbl_timing_visible.hasChanged():         
                 if self.lbl_timing_visible.value == 0:
                     self.lbl_timing.hide()
                 else:
                     self.lbl_timing.show()
                     
             if self.lbl_driver_name_text.hasChanged():
                 self.lbl_driver_name.setText(self.lbl_driver_name_text.value)  
             if self.lbl_timing_text.hasChanged():
                 self.lbl_timing.setText(self.lbl_timing_text.value,hidden=bool(self.lbl_timing_height < 30)) 
         '''
     else:
         #REPLAY
         self.resetVisibility()