def updateSharedMemory(): global sharedMem sharedmem = sharedMem.getsharedmem() sharedmem.numVehicles = ac.getCarsCount() sharedmem.focusVehicle = ac.getFocusedCar() #now we'll build the slots, so we later know every single (possible) car carIds = range(0, ac.getCarsCount(), 1) for carId in carIds: #first we'll check wether there is a car for this id; as soon it returns -1 #it's over if str(ac.getCarName(carId)) == '-1': break else: sharedmem.vehicleInfo[carId].carId = carId sharedmem.vehicleInfo[carId].driverName = ac.getDriverName(carId).encode('utf-8') sharedmem.vehicleInfo[carId].carModel = ac.getCarName(carId).encode('utf-8') sharedmem.vehicleInfo[carId].speedMS = ac.getCarState(carId, acsys.CS.SpeedMS) sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState(carId, acsys.CS.BestLap) sharedmem.vehicleInfo[carId].lapCount = ac.getCarState(carId, acsys.CS.LapCount) sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState(carId, acsys.CS.LapInvalidated) sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState(carId, acsys.CS.LapTime) sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState(carId, acsys.CS.LastLap) sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState(carId, acsys.CS.WorldPosition) sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline(carId) sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId) sharedmem.vehicleInfo[carId].carLeaderboardPosition = ac.getCarLeaderboardPosition(carId) sharedmem.vehicleInfo[carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition(carId) sharedmem.vehicleInfo[carId].spLineLength= ac.getCarState(carId, acsys.CS.NormalizedSplinePosition) sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId)
def getDriverInformation(detectionArea): global labelStorage, appPosX, appPosY, spinner_y_offset, fov_setting triangle = Triangle(detectionArea[0], detectionArea[1], detectionArea[2]) setLabel = 0 for x in range(ac.getCarsCount()): posX, posZ, posY = ac.getCarState(x, acsys.CS.WorldPosition) if triangle.isInside((posX, posY)) and x != 0: vect_x = posX - detectionArea[0][0] vect_y = posY - detectionArea[0][1] distance = math.sqrt(math.pow(vect_x, 2) + math.pow(vect_y, 2)) newPosition = getRenderPosition(x, detectionArea, (posX, posY)) ac.setText(labelStorage[setLabel], ac.getDriverName(x)) fov_angle = ac.getValue(fov_setting) xPos = (((newPosition * windowSizeX) / fov_angle) - appPosX) yOffset = ac.getValue(spinner_y_offset) yPos = (((windowSizeY / 2) - 20) - appPosY) + int(yOffset) fontSize = (10 * (1 / (distance / 100))) * (ac.getValue(scale_factor) / 10) ac.setPosition(labelStorage[setLabel], xPos, yPos) ac.setFontSize(labelStorage[setLabel], fontSize) setLabel += 1 for z in range(ac.getCarsCount() - setLabel): ac.setText(labelStorage[setLabel + z], "")
def onRender(*args): global prev_p, k, f_loc, started, passed_half, finished, n track_name = ac.getTrackName(0) basename = "%s_%i.csv"%(track_name, n) f_loc = os.path.join(os.path.dirname(os.path.realpath(__file__)), basename) if (k == 20): x,y,z = ac.getCarState(ac.getCarsCount() - 1,acsys.CS.WorldPosition) p = ac.getCarState(ac.getCarsCount() - 1,acsys.CS.NormalizedSplinePosition) if not started: if prev_p > 0.5 and p < 0.5: started = True prev_p = p else: if prev_p > 0.5 and p < 0.5: n += 1 prev_p = p return prev_p = p uiElements.update(x,y,z) f = open(f_loc, "a") f.write("{0:.5f}, {1:.5f}, {2:.5f}, {3: .5f}\n".format(x,y,z,p)) f.close() k=0 k +=1
def getLeaderCarId(): global raceTotalSessionTime, raceCrossedStartLine if raceTotalSessionTime != -1 and raceCrossedStartLine: numberOfCars = ac.getCarsCount() carIds = range(0, ac.getCarsCount(), 1) for carId in carIds: if str(ac.getCarName(carId)) == '-1': break else: carPosition = ac.getCarRealTimeLeaderboardPosition(carId) if carPosition == 0: return carId return -1
def updateToMemory(self, stop=True): car_positions = [] car_velocities = [] car_npos = [] for i in range(ac.getCarsCount()): x, y, z = ac.getCarState(i, acsys.CS.WorldPosition) pos = {"X": x, "Y": y, "Z": z} car_positions.append(pos) x, y, z = ac.getCarState(i, acsys.CS.Velocity) vel = {"X": x, "Y": y, "Z": z} car_velocities.append(vel) pos = ac.getCarState(i, acsys.CS.NormalizedSplinePosition) car_npos.append(pos) #heading = info.physics.heading #pitch = info.physics.pitch #roll = info.physics.roll dict = { "car_positions": car_positions, "car_velocities": car_velocities, "normalized_car_positions": car_npos, "stop": stop #"heading" : heading, #"pitch" : pitch, #"roll" : roll } memoryMap = self._getMemoryMap() memoryMap.seek(0) memoryMap.write(1024 * b"\0") memoryMap.seek(0) memoryMap.write(json.dumps(dict).encode()) memoryMap.close()
def updateSharedMemory(): global sharedMem sharedmem = sharedMem.getsharedmem() sharedmem.numVehicles = ac.getCarsCount() sharedmem.focusVehicle = ac.getFocusedCar() #now we'll build the slots, so we later know every single (possible) car carIds = range(0, ac.getCarsCount(), 1) for carId in carIds: #first we'll check wether there is a car for this id; as soon it returns -1 #it's over if str(ac.getCarName(carId)) == '-1': break else: sharedmem.vehicleInfo[carId].carId = carId sharedmem.vehicleInfo[carId].driverName = ac.getDriverName( carId).encode('utf-8') sharedmem.vehicleInfo[carId].carModel = ac.getCarName( carId).encode('utf-8') sharedmem.vehicleInfo[carId].speedMS = ac.getCarState( carId, acsys.CS.SpeedMS) sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState( carId, acsys.CS.BestLap) sharedmem.vehicleInfo[carId].lapCount = ac.getCarState( carId, acsys.CS.LapCount) sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState( carId, acsys.CS.LapInvalidated) sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState( carId, acsys.CS.LapTime) sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState( carId, acsys.CS.LastLap) sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState( carId, acsys.CS.WorldPosition) sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline( carId) sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId) sharedmem.vehicleInfo[ carId].carLeaderboardPosition = ac.getCarLeaderboardPosition( carId) sharedmem.vehicleInfo[ carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition( carId) sharedmem.vehicleInfo[carId].spLineLength = ac.getCarState( carId, acsys.CS.NormalizedSplinePosition) sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId) sharedmem.vehicleInfo[carId].finishStatus = ac.getCarState( carId, acsys.CS.RaceFinished)
def acUpdate(deltaT): global appWindow, windowOpacity, appPosX, appPosY, labelStorage, show_name if show_name == 1: appPosX, appPosY = ac.getPosition(appWindow) ac.setBackgroundOpacity(appWindow, windowOpacity) detectionArea = getDetectionArea() #ac.console(detectionArea) getDriverInformation(detectionArea) else: for x in range(ac.getCarsCount()): ac.setPosition(labelStorage[x], 0, 0) ac.setText(labelStorage[x], "")
def __init__(self): self.lastLapInvalidated = 0 self.lastLapShown = 0 self.SpeedKMH = Value(0) self.SpeedMPH = Value(0) self.topSpeed = Value(0) self.topSpeedMPH = Value(0) self.theme = Value(-1) self.userTopSpeed = Value(0) self.userTopSpeedMPH = Value(0) self.curTopSpeed = Value(0) self.curTopSpeedMPH = Value(0) self.current_vehicle = Value(0) self.session = Value(-1) self.font = Value(0) self.trap = 0 self.userTrap = 0 self.time_start = 0 self.time_end = 0 self.carsCount = ac.getCarsCount() self.relyOnEveryOne = True self.widget_visible = Value(0) self.cursor = Value(False) self.row_height = Value(-1) self.window = Window(name="ACTV Speed Trap", width=250, height=60) self.lbl_title = Label(self.window.app)\ .set(w=36, h=36, x=0, y=0, font_size=26, align="center") self.lbl_title_txt = Label(self.window.app, "Speed Trap")\ .set(w=36, h=36, x=0, y=0, font_size=26, opacity=0, align="center") self.lbl_time = Label(self.window.app)\ .set(w=172, h=36, x=38, y=0, font_size=26, align="center") self.lbl_time_txt = Label(self.window.app)\ .set(w=172, h=36, x=38, y=0, opacity=0, font_size=26, align="center") self.lbl_border = Label(self.window.app)\ .set(w=210, h=2, x=0, y=39) self.useMPH = False self.check_mph() self.load_cfg()
def __init__(self): self.carList = [] self.slotCount = ac.getServerSlotsCount() self.carsCount = ac.getCarsCount() postLogMessage('getServerSlotsCount: ' + str(self.slotCount)) postLogMessage('getCarsCount: ' + str(self.carsCount)) for i in range(0, self.MAX_CARS): self.carList.append(None) self.session = -1 self.session_time = 0 # оставшееся время self.sessionLapCount = 0 self.jsonfile = open("leaderboard.json", "w+") self.sessionLapCount = 0 self.flag = AC_NO_FLAG
def updateSession(self): # Вернёт True, если сессия сменилась. Кроме того, обновляет саму информацию о сессии. newSession = info.graphics.session newSessionTime = info.graphics.sessionTimeLeft isUpdated = False if newSession != self.session or newSessionTime > self.session_time: isUpdated = True self.session = newSession self.session_time = newSessionTime self.sessionLapCount = info.graphics.numberOfLaps # число кругов в гонке / TODO Учесть гонки с ограничением по времени self.carsCount = ac.getCarsCount() self.flag = info.graphics.flag self.isTimedRace = info.static.isTimedRace self.hasExtraLap = info.static.hasExtraLap return isUpdated
def prepare(self): self.track = ac.getTrackName(0) #now we'll build the slots, so we later know every single (possible) car carIds = range(0, ac.getCarsCount(), 1) for carId in carIds: #first we'll check wether there is a car for this id; as soon it returns -1 #it's over carModel = str(ac.getCarName(carId)) if carModel == '-1': break else: maxSlotId = carId driverName = ac.getDriverName(carId) self.cars.append(helipicapewcar.HeliPicaPewCar(carId, driverName, carModel))
def __init__(self): self.driversCount = ac.getCarsCount() appWindow = ac.newApp('ACTelemetry') ac.setSize(appWindow, 200, 87) self.driverLabel = ac.addLabel(appWindow, self.getDriverString()) ac.setPosition(self.driverLabel, 10, 35) nextButton = ac.addButton(appWindow, 'Next') ac.setPosition(nextButton, 5, 60) ac.setSize(nextButton, 92, 22) ac.addOnClickedListener(nextButton, clickNext) startButton = ac.addButton(appWindow, 'Start') ac.setPosition(startButton, 103, 60) ac.setSize(startButton, 92, 22) ac.addOnClickedListener(startButton, clickStart)
def acMain(ac_version): global appWindow, labelStorage, spinner_y_offset, scale_factor, fov_setting appWindow = ac.newApp("VR-Names") ac.setTitle(appWindow, "VR-names") ac.setSize(appWindow, 200, 200) ac.drawBorder(appWindow, 0) ac.setBackgroundOpacity(appWindow, 0) # ac.setIconPosition(appWindow, -9000, 0) spinner_y_offset = ac.addSpinner(appWindow, "Name Height Offset") ac.setRange(spinner_y_offset, -100, 100) ac.setValue(spinner_y_offset, 0) ac.setStep(spinner_y_offset, 1) ac.setPosition(spinner_y_offset, 10, 90) ac.setSize(spinner_y_offset, 180, 20) scale_factor = ac.addSpinner(appWindow, "scale text factor") ac.setRange(scale_factor, 1, 30) ac.setValue(scale_factor, 10) ac.setStep(scale_factor, 1) ac.setPosition(scale_factor, 10, 135) ac.setSize(scale_factor, 180, 20) fov_setting = ac.addSpinner(appWindow, "scale text factor") ac.setRange(fov_setting, 0, 360) ac.setValue(fov_setting, 110) ac.setStep(fov_setting, 1) ac.setPosition(fov_setting, 10, 180) ac.setSize(fov_setting, 180, 20) button_toggle_name = ac.addButton(appWindow, "Toggle name") ac.addOnClickedListener(button_toggle_name, toggle_name) ac.setSize(button_toggle_name, 180, 20) ac.setPosition(button_toggle_name, 10, 40) for x in range(ac.getCarsCount()): label = ac.addLabel(appWindow, "") ac.setPosition(label, 10, 0 + (20 * x)) labelStorage.append(label) setInitialLabel() return "vrnames"
def build_driver_list(): """Builds list of cars that drove through joker""" global driver_list, polygon # Get number of cars car_amount = ac.getCarsCount() # Iterate through cars for i in range(0, car_amount): driver_name = ac.getDriverName(i) if driver_name not in driver_list: inpitbox = ac.isCarInPit(i) isconnected = ac.isConnected(i) if not inpitbox and isconnected: crds = ac.getCarState(i, acsys.CS.WorldPosition) inside_joker = inside_polygon(crds[0], crds[2], polygon) if inside_joker: driver_list.append(driver_name) lap = ac.getCarState(i, acsys.CS.LapCount) send_chat_message(driver_name, lap)
def cars(self): return ac.getCarsCount()
def getCarsCount(): return ac.getCarsCount()
def onUpdate(self, sim_info): self.session_draw.setValue(sim_info.graphics.session) self.manageWindow() sim_info_status=sim_info.graphics.status if sim_info_status == 2: #LIVE if self.replay_initialised: self.lbl_session_single.setColor(rgb([255,255,255])) self.session.setValue(self.session_draw.value) sessionTimeLeft = sim_info.graphics.sessionTimeLeft if self.session.value < 2 : #0 to -5000 show finish if sessionTimeLeft < 0 and sessionTimeLeft > -5000: if not self.finish_initialised: self.init_finish() else: if sessionTimeLeft < 0: sessionTimeLeft = 0 if self.finish_initialised: self.destoy_finish() self.lbl_session_info.setVisible(1) self.lbl_session_title.setVisible(1) self.lbl_session_single.setVisible(0) self.lbl_session_border.setVisible(1) if self.session.hasChanged(): self.lbl_session_title.setSize(self.rowHeight, self.rowHeight) self.lbl_session_info.setSize(self.rowHeight*4, self.rowHeight).setPos(self.rowHeight, 0) if self.session.value == 1 : self.lbl_session_title.setText("Q") else: self.lbl_session_title.setText("P") self.lbl_session_info.setText(self.time_splitting(sessionTimeLeft)) if not self.finish_initialised: if sim_info.graphics.flag == 2: self.lbl_session_info.setBgColor(Colors.yellow(True)) self.lbl_session_info.setColor(Colors.black(),True) self.lbl_session_border.setBgColor(Colors.black(bg = True),True) self.lbl_session_title.setBgColor(Colors.black(bg = True),True) else: self.lbl_session_info.setBgColor(rgb([55, 55, 55], bg = True)) self.lbl_session_info.setColor(Colors.white(),True) self.lbl_session_border.setBgColor(Colors.red(bg = True),True) self.lbl_session_title.setBgColor(Colors.red(bg = True),True) self.lbl_session_border.animate() self.lbl_session_info.animate() self.lbl_session_title.animate() elif self.session.value == 2 : completed=0 for x in range(ac.getCarsCount()): c = ac.getCarState(x,acsys.CS.LapCount) if c > completed: completed=c completed+=1 if self.numberOfLaps==0: self.numberOfLaps=sim_info.graphics.numberOfLaps if sessionTimeLeft > 1800000 or (sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0): if self.finish_initialised: self.destoy_finish() self.lbl_session_info.setVisible(0) self.lbl_session_title.setVisible(0) self.lbl_session_single.setVisible(1) self.lbl_session_border.setVisible(1) self.lbl_session_single.setText(self.trackName) elif completed > self.numberOfLaps: if not self.finish_initialised: self.init_finish() elif completed == self.numberOfLaps: if self.finish_initialised: self.destoy_finish() self.lbl_session_info.setVisible(0) self.lbl_session_title.setVisible(0) self.lbl_session_single.setVisible(1) self.lbl_session_border.setVisible(1) self.lbl_session_single.setText("Final lap") else: if self.finish_initialised: self.destoy_finish() self.lbl_session_info.setVisible(0) self.lbl_session_title.setVisible(0) self.lbl_session_single.setVisible(1) self.lbl_session_border.setVisible(1) if self.session.hasChanged(): self.lbl_session_info.setSize(self.rowHeight*4, self.rowHeight).setPos(self.rowHeight, 0) self.lbl_session_title.setSize(self.rowHeight, self.rowHeight) self.lbl_session_title.setText("Lap") self.lbl_session_single.setText("{0} / {1}".format(completed,self.numberOfLaps)) if not self.finish_initialised: if sim_info.graphics.flag == 2: self.lbl_session_single.setBgColor(Colors.yellow(True),True) self.lbl_session_single.setColor(Colors.black(),True) self.lbl_session_border.setBgColor(Colors.black(bg = True),True) else: self.lbl_session_single.setBgColor(rgb([55, 55, 55], bg = True),True) self.lbl_session_single.setColor(Colors.white(),True) self.lbl_session_border.setBgColor(Colors.red(bg = True),True) self.lbl_session_border.animate() self.lbl_session_single.animate() else: self.lbl_session_info.setVisible(0) self.lbl_session_title.setVisible(0) self.lbl_session_single.setVisible(0) self.lbl_session_border.setVisible(0) elif sim_info_status == 1: replayTimeMultiplier=sim_info.graphics.replayTimeMultiplier if self.finish_initialised: self.destoy_finish() self.lbl_session_info.setVisible(0) self.lbl_session_title.setVisible(0) self.lbl_session_border.setVisible(1) self.lbl_session_single.setVisible(1) self.replay_initialised=True self.lbl_session_single.setColor(rgb([self.replay_rgb,self.replay_rgb,self.replay_rgb])) if self.replay_asc and replayTimeMultiplier > 0: self.replay_rgb += 2 elif replayTimeMultiplier > 0: self.replay_rgb -= 2 if self.replay_rgb < 100: self.replay_asc=True elif self.replay_rgb >= 246: self.replay_rgb=246 self.replay_asc=False self.lbl_session_single.setText("REPLAY")
def acMain(ac_version): # VARIABLES global totalDrivers global drivers global leaderboardWindow, driverWidget, driverComparisonWidget, fastest_lap_banner # LABELS global leaderboard global lapCountTimerLabel, leaderboardBaseLabel, leaderboardInfoBackgroundLabel, leaderboardBackgroundLabel global flagLabel totalDrivers = ac.getCarsCount() n_splits = ac.getTrackLength(0) / FC.TRACK_SECTION_LENGTH drivers = [Driver(i, n_splits) for i in range(totalDrivers)] # driver positions and update times ac.initFont(0, FC.FONT_NAME, 0, 0) leaderboardWindow = ac.newApp(FC.APP_NAME) ac.setTitle(leaderboardWindow, "") ac.drawBorder(leaderboardWindow, 0) ac.setIconPosition(leaderboardWindow, 0, -10000) ac.setSize(leaderboardWindow, 200, 200) ac.setBackgroundOpacity(leaderboardWindow, 0) # =============================== # Leaderboard Background leaderboardBaseLabel = ac.addLabel(leaderboardWindow, "") ac.setPosition(leaderboardBaseLabel, 0, 0) w, h = get_image_size(FC.LEADERBOARD_BASE_RACE) ac.setSize(leaderboardBaseLabel, w, h) ac.setBackgroundTexture(leaderboardBaseLabel, FC.LEADERBOARD_BASE_RACE) leaderboardBackgroundLabel = ac.addLabel(leaderboardWindow, "") ac.setPosition(leaderboardBackgroundLabel, 0, h) ac.setSize(leaderboardBackgroundLabel, w, totalDrivers*LeaderboardRow.ROW_HEIGHT + 2) ac.setBackgroundTexture(leaderboardBackgroundLabel, FC.LEADERBOARD_BACKGROUND); # =============================== # Lap Counter / Time lapCountTimerLabel = ac.addLabel(leaderboardWindow, "") ac.setPosition(lapCountTimerLabel, 74, 52) ac.setFontSize(lapCountTimerLabel, 22) ac.setCustomFont(lapCountTimerLabel, FC.FONT_NAME, 0, 1) ac.setFontAlignment(lapCountTimerLabel, "center") ac.setFontColor(lapCountTimerLabel, 0.86, 0.86, 0.86, 1) # =============================== # Flags flagLabel = ac.addLabel(leaderboardWindow, "") ac.setPosition(flagLabel, w, 8) ac.setSize(flagLabel, 110, h-8) ac.setVisible(flagLabel, 0) # =============================== # Info Background leaderboardInfoBackgroundLabel = ac.addLabel(leaderboardWindow, "") ac.setPosition(leaderboardInfoBackgroundLabel, w, h) ac.setSize(leaderboardInfoBackgroundLabel, 110, totalDrivers*LeaderboardRow.ROW_HEIGHT + 2) ac.setBackgroundTexture(leaderboardInfoBackgroundLabel, FC.LEADERBOARD_INFO_BACKGROUNG) info_button = ac.addButton(leaderboardWindow, "") ac.setPosition(info_button, w, h) ac.setSize(info_button, 110, totalDrivers*LeaderboardRow.ROW_HEIGHT + 2) ac.addOnClickedListener(info_button, on_click_info) ac.setBackgroundOpacity(info_button, 0) ac.drawBorder(info_button, 0) # =============================== # Driver Widget driverWidget = DriverWidget(FC.APP_NAME+" Driver") # =============================== # Driver Comparison Widget driverComparisonWidget = DriverComparisonWidget(FC.APP_NAME+" Driver Comparison") # =============================== # FastestLap Banner fastest_lap_banner = FastestLapBanner(FC.APP_NAME+" Top Banner") fastest_lap_banner.hide() leaderboard = [None] * totalDrivers for i in range(totalDrivers): leaderboard[i] = LeaderboardRow(leaderboardWindow, i) return FC.APP_NAME
def getGeneralData(): res = dict() res['trackName'] = ac.getTrackName(0) res['trackConfiguration'] = ac.getTrackConfiguration(0) res['carCount'] = ac.getCarsCount() return res
def __init__(self, sim_info): self.replay_initialised = False self.replay_asc = False self.replay_rgb = 255 self.session = Value(-1) self.theme = Value(-1) self.cursor = Value(False) self.row_height = Value(-1) self.font = Value(0) self.numberOfLaps = -1 self.corner_width=0 self.hasExtraLap = sim_info.static.hasExtraLap self.numberOfLapsTimedRace = -1 self.sessionMaxTime = -1 self.pitWindowVisibleEnd = 0 self.pitWindowStart = sim_info.static.PitWindowStart self.pitWindowEnd = sim_info.static.PitWindowEnd self.pitWindowActive = False self.numberOfLapsCompleted = Value(0) self.cars_count = ac.getCarsCount() self.window = Window(name="ACTV CP Timer", width=228, height=42) # background corners self.lbl_left_corner = Label(self.window.app)\ .set(w=27, h=42, x=0, y=-80, opacity=0, background=Colors.timer_left_corner()) self.lbl_right_corner = Label(self.window.app)\ .set(w=27, h=42, x=0, y=-80, opacity=0, background=Colors.timer_right_corner()) # background self.lbl_session_info = Label(self.window.app)\ .set(w=331, h=36, x=self.row_height.value, y=-80) # Timer / lap self.lbl_session_info_txt = Label(self.window.app, "00:00")\ .set(w=0, h=36, x=self.row_height.value, y=-76, opacity=0, font_size=26, align="right") # Time self.lbl_time_of_day_txt = Label(self.window.app, "12:00")\ .set(w=0, h=36, x=self.row_height.value, y=-76, opacity=0, font_size=26, align="left") self.lbl_am_pm_txt = Label(self.window.app, "PM")\ .set(w=0, h=36, x=self.row_height.value, y=-76, opacity=0, font_size=26, align="left") self.lbl_extra_lap_txt = Label(self.window.app, "+1 LAP")\ .set(w=0, h=36, x=self.row_height.value, y=-76, opacity=0, font_size=26, align="right") # background pit window self.lbl_session_title = Label(self.window.app)\ .set(w=36, h=36, x=0, y=-74, opacity=1) # Race, Qual, Practice self.lbl_session_title_txt = Label(self.window.app, "FREE PRACTICE")\ .set(w=0, h=36, x=114, y=-76, opacity=0, font_size=26, align="center") # Status self.lbl_session_border = Label(self.window.app)\ .set(w=154 + 36, h=2, x=0, y=-74) self.lbl_session_border_2 = Label(self.window.app)\ .set(w=154 + 36, h=2, x=200, y=-74) # Open race.ini conf = Config(Config.get_user_documents_path() + "cfg/", "race.ini") start = conf.get("LIGHTING", "SUN_ANGLE") self.time_multiplier = float(conf.get("LIGHTING", "TIME_MULT")) session_0=session_1=session_2=session_3=session_4=session_5=session_6=0 for i in range(6): session_name = conf.get("SESSION_" + str(i), "NAME") if session_name == "Practice": session_0 = conf.get("SESSION_" + str(i), "DURATION_MINUTES") elif session_name == "Qualifying": session_1 = conf.get("SESSION_" + str(i), "DURATION_MINUTES") elif session_name == "Race": session_2 = conf.get("SESSION_" + str(i), "DURATION_MINUTES") elif session_name == "Hotlap": session_3 = conf.get("SESSION_" + str(i), "DURATION_MINUTES") elif session_name == "Time Attack": session_4 = conf.get("SESSION_" + str(i), "DURATION_MINUTES") elif session_name == "Drift": session_5 = conf.get("SESSION_" + str(i), "DURATION_MINUTES") elif session_name == "Drag": session_6 = conf.get("SESSION_" + str(i), "DURATION_MINUTES") self.sessions_duration = [float(session_0)*60000, float(session_1)*60000, float(session_2)*60000, float(session_3)*60000, float(session_4)*60000, float(session_5)*60000, float(session_6)*60000 ] self.start_time_of_day_original = self.start_time_of_day=(780 + 3.75 * float(start)) * 60000 - (4000 * self.time_multiplier) #ac.console("ini:" + str(self.start_time_of_day) + " = " + self.time_of_day(self.start_time_of_day)) self.last_start_time_offset=-1 self.session_time_left=0 self.session_info_imported=False self.is_multiplayer = ac.getServerIP() != '' self.lbl_time_of_day_txt.setText(self.time_of_day(self.start_time_of_day)) self.load_cfg()
def on_update(self, sim_info): self.session.setValue(sim_info.graphics.session) self.manage_window() sim_info_status = sim_info.graphics.status self.animate() if sim_info_status == 2: # LIVE if self.replay_initialised: self.lbl_session_single_txt.setColor(Colors.timer_time_txt(), animated=True) session_time_left = sim_info.graphics.sessionTimeLeft if self.session.value < 2: self.lbl_pit_window.hide() self.lbl_pit_window_txt.hide() self.lbl_session_single_txt.hide() # 0 to -5000 show finish if 0 > session_time_left > -5000: if not self.finish_initialised: self.init_finish() else: if session_time_left < 0: session_time_left = 0 if self.finish_initialised: self.destroy_finish() self.lbl_session_title.show() self.lbl_session_title_txt.show() self.lbl_session_single.hide() self.lbl_session_border.show() self.lbl_session_info.show() self.lbl_session_info_txt.setText( self.time_splitting(session_time_left)).show() if not self.finish_initialised: if sim_info.graphics.flag == 2: # Yellow Flag self.lbl_session_info.set( background=Colors.timer_time_yellow_flag_bg(), animated=True) self.lbl_session_info_txt.set( color=Colors.timer_time_yellow_flag_txt(), animated=True) self.lbl_session_title.set( background=Colors.timer_title_yellow_flag_bg(), animated=True) self.lbl_session_title_txt.set( color=Colors.timer_title_yellow_flag_txt(), animated=True) self.lbl_session_border.set( background=Colors.timer_border_yellow_flag_bg( ), animated=True) else: self.lbl_session_info.set( background=Colors.timer_time_bg(), animated=True) self.lbl_session_info_txt.set( color=Colors.timer_time_txt(), animated=True) self.lbl_session_title.set( background=Colors.timer_title_bg(), animated=True) self.lbl_session_title_txt.set( color=Colors.timer_title_txt(), animated=True) self.lbl_session_border.set( background=Colors.timer_border_bg(), animated=True) elif self.session.value == 2: # Race completed = 0 race_finished = 0 for x in range(ac.getCarsCount()): c = ac.getCarState(x, acsys.CS.LapCount) if c > completed: completed = c if ac.getCarState(x, acsys.CS.RaceFinished): race_finished = 1 completed += 1 if self.numberOfLaps < 0: self.numberOfLaps = sim_info.graphics.numberOfLaps if self.hasExtraLap < 0: self.hasExtraLap = sim_info.static.hasExtraLap if self.hasExtraLap == 1 and session_time_left < 0 and self.numberOfLapsTimedRace < 0: self.numberOfLapsTimedRace = completed + 1 # PitWindow pit_window_remain = "" if self.pitWindowStart < 0: self.pitWindowStart = sim_info.static.PitWindowStart self.pitWindowEnd = sim_info.static.PitWindowEnd if self.numberOfLaps > 0: self.numberOfLapsCompleted.setValue(completed) if self.numberOfLapsCompleted.hasChanged(): if self.numberOfLapsCompleted.value == self.pitWindowStart: self.pitWindowVisibleEnd = session_time_left - 8000 self.pitWindowActive = True elif self.numberOfLapsCompleted.value == self.pitWindowEnd: self.pitWindowVisibleEnd = session_time_left - 8000 self.pitWindowActive = False if self.pitWindowActive: if self.pitWindowEnd - completed > 1: pit_window_remain = " {0} Laps".format( self.pitWindowEnd - completed) else: pit_window_remain = " {0} Lap".format( self.pitWindowEnd - completed) else: if self.sessionMaxTime < 0: self.sessionMaxTime = round(session_time_left, -3) if not self.pitWindowActive and session_time_left <= self.sessionMaxTime - self.pitWindowStart * 60 * 1000 and session_time_left >= self.sessionMaxTime - self.pitWindowEnd * 60 * 1000: self.pitWindowVisibleEnd = session_time_left - 8000 self.pitWindowActive = True elif self.pitWindowActive and session_time_left < self.sessionMaxTime - self.pitWindowEnd * 60 * 1000: self.pitWindowVisibleEnd = session_time_left - 8000 self.pitWindowActive = False if self.pitWindowActive: pit_window_remain = " " + self.time_splitting( session_time_left - (self.sessionMaxTime - self.pitWindowEnd * 60 * 1000)) if self.pitWindowActive: self.lbl_pit_window.show() self.lbl_pit_window_txt.show() if self.pitWindowVisibleEnd != 0 and self.pitWindowVisibleEnd < session_time_left: self.lbl_pit_window_txt.setColor( Colors.timer_pit_window_open_txt()) elif sim_info.graphics.MandatoryPitDone: self.lbl_pit_window_txt.setColor( Colors.timer_pit_window_done_txt(), True) else: self.lbl_pit_window_txt.setColor( Colors.timer_pit_window_txt(), True) self.lbl_pit_window_txt.setText("Pits open" + pit_window_remain) elif self.pitWindowVisibleEnd != 0 and self.pitWindowVisibleEnd < session_time_left: self.lbl_pit_window.show() self.lbl_pit_window_txt.setText("Pits closed").setColor( Colors.timer_pit_window_close_txt(), True) self.lbl_pit_window_txt.show() else: self.lbl_pit_window.hide() self.lbl_pit_window_txt.hide() if sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0: self.pitWindowVisibleEnd = 0 self.pitWindowActive = False self.sessionMaxTime = round(session_time_left, -3) if self.finish_initialised: self.destroy_finish() self.lbl_session_info.hide() self.lbl_session_info_txt.hide() self.lbl_session_title.hide() self.lbl_session_title_txt.hide() self.lbl_session_single.show() self.lbl_session_border.show() self.lbl_session_single_txt.setText(self.trackName).show() elif race_finished > 0: if not self.finish_initialised: self.init_finish() elif completed == self.numberOfLaps or ( self.numberOfLaps == 0 and self.hasExtraLap == 0 and session_time_left < 0) or ( self.hasExtraLap == 1 and completed == self.numberOfLapsTimedRace): if self.finish_initialised: self.destroy_finish() self.lbl_session_info.hide() self.lbl_session_info_txt.hide() self.lbl_session_title.hide() self.lbl_session_title_txt.hide() self.lbl_session_single.show() self.lbl_session_border.show() self.lbl_session_single_txt.setText("Final lap").show() else: if self.finish_initialised: self.destroy_finish() self.lbl_session_info.hide() self.lbl_session_info_txt.hide() self.lbl_session_title.hide() self.lbl_session_title_txt.hide() self.lbl_session_single.show() self.lbl_session_single_txt.show() self.lbl_session_border.show() if self.hasExtraLap > 0: txt_extra_lap = " +1 Lap" else: txt_extra_lap = "" if self.numberOfLaps > 0: self.lbl_session_single_txt.setText("{0} / {1}".format( completed, self.numberOfLaps)) elif session_time_left > 0: self.lbl_session_single_txt.setText( self.time_splitting(session_time_left) + txt_extra_lap) else: self.lbl_session_single_txt.setText("0:00" + txt_extra_lap) if not self.finish_initialised: if sim_info.graphics.flag == 2: # Yellow flag self.lbl_session_single.set( background=Colors.timer_time_yellow_flag_bg(), animated=True) self.lbl_session_single_txt.set( color=Colors.timer_time_yellow_flag_txt(), animated=True) self.lbl_session_border.set( background=Colors.timer_border_yellow_flag_bg(), animated=True) else: self.lbl_session_single.set( background=Colors.timer_time_bg(), animated=True) self.lbl_session_single_txt.set( color=Colors.timer_time_txt(), animated=True) self.lbl_session_border.set( background=Colors.timer_border_bg(), animated=True) else: self.lbl_session_info.hide() self.lbl_session_info_txt.hide() self.lbl_session_title.hide() self.lbl_session_title_txt.hide() self.lbl_session_single.hide() self.lbl_session_single_txt.hide() self.lbl_session_border.hide() self.lbl_pit_window.hide() self.lbl_pit_window_txt.hide() elif sim_info_status == 1: replay_time_multiplier = sim_info.graphics.replayTimeMultiplier if self.finish_initialised: self.destroy_finish() self.lbl_session_info.hide() self.lbl_session_info_txt.hide() self.lbl_session_title.hide() self.lbl_session_title_txt.hide() self.lbl_session_border.show() self.lbl_session_single.show() self.lbl_pit_window.hide() self.lbl_pit_window_txt.hide() self.replay_initialised = True self.lbl_session_single_txt.setText("REPLAY")\ .setColor(rgb([self.replay_rgb, self.replay_rgb, self.replay_rgb]))\ .show() if self.replay_asc and replay_time_multiplier > 0: self.replay_rgb += 2 elif replay_time_multiplier > 0: self.replay_rgb -= 2 if Colors.general_theme == 1: if self.replay_rgb <= 2: self.replay_asc = True elif self.replay_rgb > 168: self.replay_rgb = 168 self.replay_asc = False else: if self.replay_rgb < 100: self.replay_asc = True elif self.replay_rgb >= 246: self.replay_rgb = 246 self.replay_asc = False
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()
def onUpdate(self, sim_info): self.session.setValue(sim_info.graphics.session) sessionTimeLeft=sim_info.graphics.sessionTimeLeft sim_info_status=sim_info.graphics.status if (sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0) or sessionTimeLeft >= 1800000: self.resetVisibility() self.time_end = 0 self.manageWindow() if self.carsCount==0: self.carsCount = ac.getCarsCount() for x in range(self.carsCount): c = ac.getCarState(x,acsys.CS.SpeedKMH) if x==0 and self.topSpeed.value < c: self.userTopSpeed.setValue(c) self.userTrap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition) if self.relyOnEveryOne and self.topSpeed.value < c and ac.getCarState(x,acsys.CS.DriveTrainSpeed) > c/10 and ac.getCarState(x,acsys.CS.Gas) > 0.9 and ac.getCarState(x,acsys.CS.RPM) > 2000: if c > 500: self.relyOnEveryOne=False self.topSpeed.setValue(self.userTopSpeed.value) self.trap = self.userTrap #ac.console("stop rely") #ac.log("stop rely") else: self.topSpeed.setValue(c) #ac.console(str(c) + "-"+str(x)+"-rpm:"+str(ac.getCarState(x,acsys.CS.RPM))+"-Gas:"+str(ac.getCarState(x,acsys.CS.Gas))+"-Gear:"+str(ac.getCarState(x,acsys.CS.Gear))+"-DriveTrainSpeed:"+str(ac.getCarState(x,acsys.CS.DriveTrainSpeed))) self.trap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition) elif not self.relyOnEveryOne and x == 0 and self.topSpeed.value < c: self.topSpeed.setValue(c) self.trap = ac.getCarState(x,acsys.CS.NormalizedSplinePosition) self.currentVehicule.setValue(ac.getFocusedCar()) self.SpeedKMH.setValue(ac.getCarState(self.currentVehicule.value,acsys.CS.SpeedKMH)) self.SpeedMPH.setValue(ac.getCarState(self.currentVehicule.value,acsys.CS.SpeedMPH)) LapCount = ac.getCarState(self.currentVehicule.value,acsys.CS.LapCount) if self.curTopSpeed.value < self.SpeedKMH.value: self.curTopSpeed.setValue(self.SpeedKMH.value) self.curTopSpeedMPH.setValue(self.SpeedMPH.value) if self.currentVehicule.value==0 and sim_info.physics.numberOfTyresOut >= 4 and self.lapCanBeInvalidated: self.lastLapInvalidated = LapCount self.animate() if sim_info_status == 2: if self.session.value <= 2 : #Qual-Practise every time #isInPit = self.currentVehicule.value==0 and bool(sim_info.physics.pitLimiterOn) isInPit = (bool(ac.isCarInPitline(self.currentVehicule.value)) or bool(ac.isCarInPit(self.currentVehicule.value))) if isInPit : self.lastLapInPit = LapCount if self.lastLapInPit < LapCount and self.curTopSpeed.value < 500 and self.lastLapShown < LapCount and self.lastLapInvalidated < LapCount and self.widget_visible.value == 0 and self.trap < ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition) + 0.06 and self.trap > ac.getCarState(self.currentVehicule.value,acsys.CS.NormalizedSplinePosition) - 0.08 and self.SpeedKMH.value < self.SpeedKMH.old - 0.6: #show and set timer 0.3 self.lastLapShown=LapCount self.widget_visible.setValue(1) if self.useMPH: self.speedText="%.1f mph"%(self.curTopSpeedMPH.value) else: self.speedText="%.1f kph"%(self.curTopSpeed.value) self.time_end = sessionTimeLeft - 9000 self.lbl_title.setText("S",hidden=True) self.lbl_time.setText(self.speedText,hidden=True) self.lbl_time.show() self.lbl_border.show() self.lbl_title.show() elif self.time_end == 0 or sessionTimeLeft < self.time_end: self.lbl_time.hide() self.lbl_border.hide() self.lbl_title.hide() self.widget_visible.setValue(0) self.time_end=0 if self.widget_visible.hasChanged(): self.curTopSpeed.setValue(0) self.curTopSpeedMPH.setValue(0) else: self.resetVisibility() elif sim_info_status == 1: self.resetVisibility()
def __init__(self): self.window = Window(name="ACTV CP Delta", width=180, height=300) self.cursor = Value(False) self.session = Value(-1) self.performance = Value(0) self.spline = Value(0) self.currentVehicle = Value(-1) self.laptime = Value(0) self.TimeLeftUpdate = Value(0) self.referenceLap = [] self.referenceLapTime = Value(0) self.lastLapTime = Value(0) self.lapCount = 0 self.performance_display = 0 self.current_car_class = Value("") self.lastLapIsValid = True self.best_lap_time = 0 self.visual_timeout = -1 self.currentLap = [] self.drivers_info = [] self.deltaLoaded = False self.thread_save = False self.last_yellow_flag_end = False self.standings = None self.rowHeight = Value(-1) self.is_multiplayer = ac.getServerIP() != '' self.numCars = self.cars_count = ac.getCarsCount() self.font_size = 16 self.is_touristenfahrten = False track = ac.getTrackName(0) config = ac.getTrackConfiguration(0) if track.find("ks_nordschleife") >= 0 and config.find( "touristenfahrten") >= 0: self.is_touristenfahrten = True self.current_lap_others = [] self.spline_others = [] self.drivers_lap_count = [] self.reference_lap_time_others = [] for i in range(self.cars_count): self.drivers_lap_count.append(Value(0)) self.spline_others.append(Value(0)) self.current_lap_others.append([]) self.reference_lap_time_others.append([]) self.last_lap_start = [-1] * self.cars_count self.lbl_flag = Label(self.window.app)\ .set(w=77, h=50, x=1, y=-80, background=Colors.white(bg=True), opacity=1) self.lbl_number_bg = Label(self.window.app)\ .set(w=77, h=0, x=0, y=0, background=Colors.white(bg=True), opacity=1, visible=1) self.lbl_number_text = Label(self.window.app, "000")\ .set(w=77, h=0, x=0, y=0, opacity=0, color=Colors.black_txt(), font_size=26, align="center", visible=1) self.lbl_name_bg = Label(self.window.app)\ .set(w=77, h=0, x=0, y=0, opacity=1, visible=1) self.lbl_name_text = Label(self.window.app, "PLY")\ .set(w=77, h=0, x=0, y=0, opacity=0, font_size=26, align="center", visible=1) self.lbl_position_text_shadow = Label(self.window.app, "0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_position_text = Label(self.window.app, "0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_position_text_multi_shadow = Label(self.window.app, "0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_position_text_multi = Label(self.window.app, "0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_position_total_text_shadow = Label(self.window.app, "/0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_position_total_text = Label(self.window.app, "/0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_position_total_text_multi_shadow = Label(self.window.app, "/0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_position_total_text_multi = Label(self.window.app, "/0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_delta_bg = Label(self.window.app)\ .set(w=77, h=0, x=0, y=0, opacity=0, background=Colors.delta_neutral(), visible=1) self.lbl_current_time_bg = Label(self.window.app)\ .set(w=77, h=0, x=0, y=0, opacity=1, visible=1) self.lbl_current_time_text = Label(self.window.app, "--:--.---")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_best_time_title_bg = Label(self.window.app)\ .set(w=0, h=0, x=0, y=0, opacity=1, visible=1) self.lbl_best_title_text = Label(self.window.app, "BEST")\ .set(w=77, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_best_time_text = Label(self.window.app, "--:--.---")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_last_title_bg = Label(self.window.app)\ .set(w=0, h=0, x=0, y=0, opacity=1, visible=1) self.lbl_last_title_text = Label(self.window.app, "LAST")\ .set(w=77, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_last_time_text = Label(self.window.app, "--:--.---")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_prediction_title_bg = Label(self.window.app)\ .set(w=0, h=0, x=0, y=0, opacity=1, visible=1) self.lbl_prediction_title_text = Label(self.window.app, "PRED")\ .set(w=77, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_prediction_time_text = Label(self.window.app, "--:--.---")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_delta_text = Label(self.window.app, "+0.00")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, color=Colors.black_txt(), align="center", visible=1) self.lbl_laps_completed_text_shadow = Label(self.window.app, "0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_laps_completed_text = Label(self.window.app, "0")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="right", visible=1) self.lbl_laps_text_shadow = Label(self.window.app, "LAPS")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.lbl_laps_text = Label(self.window.app, "LAPS")\ .set(w=0, h=0, x=0, y=0, opacity=0, font_size=26, align="left", visible=1) self.btn_reset = Button(self.window.app, self.on_reset_press)\ .setPos(90, 68).setSize(120, 20)\ .setText("Reset saved lap")\ .setAlign("center")\ .setBgColor(rgb([255, 12, 12], bg=True))\ .setVisible(0) self.btn_import_from = Button(self.window.app, self.on_import_from_press)\ .setPos(90, 68).setSize(120, 20)\ .setText("Import Delta")\ .setAlign("center")\ .setBgColor(rgb([255, 12, 12], bg=True))\ .setVisible(0) self.load_cfg()
def on_update(self, sim_info): self.session.setValue(sim_info.graphics.session) session_time_left = sim_info.graphics.sessionTimeLeft sim_info_status = sim_info.graphics.status if sim_info.graphics.iCurrentTime == 0 and sim_info.graphics.completedLaps == 0: self.session.setValue(-1) self.session.setValue(sim_info.graphics.session) self.manage_window() if self.carsCount == 0: self.carsCount = ac.getCarsCount() for x in range(self.carsCount): c = ac.getCarState(x, acsys.CS.SpeedKMH) if self.useMPH: mph = ac.getCarState(x, acsys.CS.SpeedMPH) if x == 0 and self.topSpeed.value < c: self.userTopSpeed.setValue(c) if self.useMPH: self.userTopSpeedMPH.setValue(mph) self.userTrap = ac.getCarState( x, acsys.CS.NormalizedSplinePosition) if self.relyOnEveryOne and self.topSpeed.value < c \ and ac.getCarState(x, acsys.CS.DriveTrainSpeed) > c / 10 \ and ac.getCarState(x, acsys.CS.Gas) > 0.9 \ and ac.getCarState(x, acsys.CS.RPM) > 2000: if c > 500: self.relyOnEveryOne = False self.topSpeed.setValue(self.userTopSpeed.value) if self.useMPH: self.topSpeedMPH.setValue(self.userTopSpeedMPH.value) self.trap = self.userTrap # ac.console("stop rely") else: self.topSpeed.setValue(c) if self.useMPH: self.topSpeedMPH.setValue(mph) self.trap = ac.getCarState( x, acsys.CS.NormalizedSplinePosition) elif not self.relyOnEveryOne and x == 0 and self.topSpeed.value < c: self.topSpeed.setValue(c) if self.useMPH: self.topSpeedMPH.setValue(mph) self.trap = ac.getCarState(x, acsys.CS.NormalizedSplinePosition) self.current_vehicle.setValue(ac.getFocusedCar()) self.SpeedKMH.setValue( ac.getCarState(self.current_vehicle.value, acsys.CS.SpeedKMH)) if self.useMPH: self.SpeedMPH.setValue( ac.getCarState(self.current_vehicle.value, acsys.CS.SpeedMPH)) lap_count = ac.getCarState(self.current_vehicle.value, acsys.CS.LapCount) if self.curTopSpeed.value < self.SpeedKMH.value: self.curTopSpeed.setValue(self.SpeedKMH.value) if self.useMPH: self.curTopSpeedMPH.setValue(self.SpeedMPH.value) if self.current_vehicle.value == 0 and sim_info.physics.numberOfTyresOut >= 4: self.lastLapInvalidated = lap_count self.animate() if sim_info_status == 2: # Live is_in_pit = (bool(ac.isCarInPitline(self.current_vehicle.value)) or bool(ac.isCarInPit(self.current_vehicle.value))) if is_in_pit: self.lastLapInvalidated = lap_count position = ac.getCarState(self.current_vehicle.value, acsys.CS.NormalizedSplinePosition) if self.curTopSpeed.value < 500 and self.lastLapShown < lap_count \ and self.lastLapInvalidated < lap_count and self.widget_visible.value == 0 \ and position + 0.06 > self.trap > position - 0.08 \ and self.SpeedKMH.value < self.SpeedKMH.old - 0.6: # show and set timer 0.3 self.lastLapShown = lap_count self.widget_visible.setValue(1) if self.useMPH: speed_text = "%.1f mph | %.1f mph" % ( self.curTopSpeedMPH.value, self.topSpeedMPH.value) else: speed_text = "%.1f kph | %.1f kph" % ( self.curTopSpeed.value, self.topSpeed.value) self.time_start = session_time_left - 800 self.time_end = session_time_left - 14800 self.lbl_time_txt.setText(speed_text) # , hidden=True) self.lbl_title.set(y=self.row_height.value).show() self.lbl_title_txt.set(y=self.row_height.value + Font.get_font_x_offset()).show() elif self.time_start != 0 and self.time_start > session_time_left > self.time_end: self.lbl_title.set(y=0, animated=True).show() self.lbl_title_txt.set(y=0 + Font.get_font_x_offset(), animated=True).show() self.lbl_time.show() self.lbl_time_txt.show() self.lbl_border.show() elif self.time_end == 0 or session_time_left < self.time_end: self.reset_visibility() self.widget_visible.setValue(0) self.time_start = 0 self.time_end = 0 if self.widget_visible.hasChanged(): self.curTopSpeed.setValue(0) self.curTopSpeedMPH.setValue(0) # else: # self.reset_visibility() elif sim_info_status == 1: self.reset_visibility()
def updateSharedMemory(): global sharedMem global packetID sharedmem = sharedMem.getsharedmem() sharedmem.packetID = -1 sharedmem.numVehicles = ac.getCarsCount() sharedmem.focusVehicle = ac.getFocusedCar() carIds = range(0, ac.getCarsCount(), 1) for carId in carIds: if str(ac.getCarName(carId)) == '-1': break else: sharedmem.vehicleInfo[carId].carId = carId sharedmem.vehicleInfo[carId].driverName = ac.getDriverName( carId).encode('utf-8') sharedmem.vehicleInfo[carId].carModel = ac.getCarName( carId).encode('utf-8') sharedmem.vehicleInfo[carId].speedMS = ac.getCarState( carId, acsys.CS.SpeedMS) sharedmem.vehicleInfo[carId].bestLapMS = ac.getCarState( carId, acsys.CS.BestLap) sharedmem.vehicleInfo[carId].lapCount = ac.getCarState( carId, acsys.CS.LapCount) sharedmem.vehicleInfo[carId].currentLapInvalid = ac.getCarState( carId, acsys.CS.LapInvalidated) sharedmem.vehicleInfo[carId].currentLapTimeMS = ac.getCarState( carId, acsys.CS.LapTime) sharedmem.vehicleInfo[carId].lastLapTimeMS = ac.getCarState( carId, acsys.CS.LastLap) sharedmem.vehicleInfo[carId].worldPosition = ac.getCarState( carId, acsys.CS.WorldPosition) sharedmem.vehicleInfo[carId].isCarInPitline = ac.isCarInPitline( carId) sharedmem.vehicleInfo[carId].isCarInPit = ac.isCarInPit(carId) sharedmem.vehicleInfo[ carId].carLeaderboardPosition = ac.getCarLeaderboardPosition( carId) sharedmem.vehicleInfo[ carId].carRealTimeLeaderboardPosition = ac.getCarRealTimeLeaderboardPosition( carId) sharedmem.vehicleInfo[carId].splinePosition = ac.getCarState( carId, acsys.CS.NormalizedSplinePosition) sharedmem.vehicleInfo[carId].isConnected = ac.isConnected(carId) if libInit == 1 and carId == 0: sharedmem.vehicleInfo[carId].suspensionDamage[ 0] = funcGetSuspensionDamage(carId, 0) sharedmem.vehicleInfo[carId].suspensionDamage[ 1] = funcGetSuspensionDamage(carId, 1) sharedmem.vehicleInfo[carId].suspensionDamage[ 2] = funcGetSuspensionDamage(carId, 2) sharedmem.vehicleInfo[carId].suspensionDamage[ 3] = funcGetSuspensionDamage(carId, 3) sharedmem.vehicleInfo[ carId].engineLifeLeft = funcGetEngineLifeLeft(carId) sharedmem.vehicleInfo[carId].tyreInflation[ 0] = funcGetTyreInflation(carId, 0) sharedmem.vehicleInfo[carId].tyreInflation[ 1] = funcGetTyreInflation(carId, 1) sharedmem.vehicleInfo[carId].tyreInflation[ 2] = funcGetTyreInflation(carId, 2) sharedmem.vehicleInfo[carId].tyreInflation[ 3] = funcGetTyreInflation(carId, 3) packetID = packetID + 1 sharedmem.packetID = packetID
def acMain(ac_version): global DRS_ALLOWED_CARS, SOUND_ON, SERVERS global tyreLabels, tyrePressureLabels global drsLabel, ersLabel, ersModeLabel, ersRecoveryLabel, fuelLabel, drsPenaltyLabel, drsPenaltyBackgroundLabel global drsZones, totalDrivers, trackLength, drsAvailableZones, driversList global carValue, trackConfigValue, trackValue global compounds, modCompounds carValue = ac.getCarName(0) trackValue = ac.getTrackName(0) trackConfigValue = ac.getTrackConfiguration(0) settings = configparser.ConfigParser() settings.read("apps/python/%s/config.ini" % APP_NAME) if settings.has_section('CARS'): DRS_ALLOWED_CARS.extend( [c for c in settings['CARS'] if settings['CARS'][c] == '1']) if settings.has_section('SETTINGS'): SOUND_ON = True if 'sound' in settings['SETTINGS'] and settings[ 'SETTINGS']['sound'] == '1' else False if settings.has_section('SERVERS'): SERVERS = list(settings['SERVERS'].values()) drsZones = loadDRSZones() totalDrivers = ac.getCarsCount() trackLength = getTrackLength() driversList = [Driver(i, len(drsZones)) for i in range(totalDrivers)] drsAvailableZones = [False] * len(drsZones) compounds = configparser.ConfigParser() compounds.read(COMPOUNDSPATH + "compounds.ini") modCompounds = configparser.ConfigParser() modCompounds.read(COMPOUNDSPATH + carValue + ".ini") ac.initFont(0, FONT_NAME, 0, 0) appWindow = ac.newApp(APP_NAME) ac.setTitle(appWindow, "") ac.drawBorder(appWindow, 0) ac.setIconPosition(appWindow, 0, -10000) ac.setSize(appWindow, 280, 70) ac.setBackgroundOpacity(appWindow, 0.2) # ================================================================================================================= # TYRE LABELS # ================================================================================================================= tyreLabelFL = ac.addLabel(appWindow, "") tyreLabelFR = ac.addLabel(appWindow, "") tyreLabelRL = ac.addLabel(appWindow, "") tyreLabelRR = ac.addLabel(appWindow, "") tyreLabels = [tyreLabelFL, tyreLabelFR, tyreLabelRL, tyreLabelRR] for label in tyreLabels: ac.setFontSize(label, 15) ac.setFontColor(label, 0, 0, 0, 1) ac.setFontAlignment(label, "center") ac.setSize(label, 15, 23) tyrePressureLabelFL = ac.addLabel(appWindow, "PFL") tyrePressureLabelFR = ac.addLabel(appWindow, "PFR") tyrePressureLabelRL = ac.addLabel(appWindow, "PRL") tyrePressureLabelRR = ac.addLabel(appWindow, "PRR") tyrePressureLabels = [ tyrePressureLabelFL, tyrePressureLabelFR, tyrePressureLabelRL, tyrePressureLabelRR ] for label in tyrePressureLabels: ac.setFontSize(label, 15) ac.setFontColor(label, 0.86, 0.86, 0.86, 1) ac.setCustomFont(label, FONT_NAME, 0, 0) ac.setFontAlignment(tyrePressureLabels[0], "right") ac.setFontAlignment(tyrePressureLabels[1], "left") ac.setFontAlignment(tyrePressureLabels[2], "right") ac.setFontAlignment(tyrePressureLabels[3], "left") #position all the labels tlpx = 180 tlpy = 10 ac.setPosition(tyreLabels[0], tlpx + 5, tlpy + 0) ac.setPosition(tyreLabels[1], tlpx + 25, tlpy + 0) ac.setPosition(tyreLabels[2], tlpx + 5, tlpy + 28) ac.setPosition(tyreLabels[3], tlpx + 25, tlpy + 28) ac.setPosition(tyrePressureLabels[0], tlpx, tlpy + 2) ac.setPosition(tyrePressureLabels[1], tlpx + 43, tlpy + 2) ac.setPosition(tyrePressureLabels[2], tlpx, tlpy + 30) ac.setPosition(tyrePressureLabels[3], tlpx + 43, tlpy + 30) # ================================================================================================================= # ERS MODES LABELS # ================================================================================================================= elpx = 15 elpy = 10 ersModeLabel = ac.addLabel(appWindow, "🗲0") ac.setPosition(ersModeLabel, elpx + 50, elpy) ac.setFontSize(ersModeLabel, 18) ac.setCustomFont(ersModeLabel, FONT_NAME, 0, 0) ac.setFontColor(ersModeLabel, 1.0, 1.0, 0.2, 1) ac.setFontAlignment(ersModeLabel, "left") ersRecoveryLabel = ac.addLabel(appWindow, "") ac.setPosition(ersRecoveryLabel, elpx + 85, elpy) ac.setFontSize(ersRecoveryLabel, 18) ac.setCustomFont(ersRecoveryLabel, FONT_NAME, 0, 0) ac.setFontColor(ersRecoveryLabel, 1.0, 1.0, 0.2, 1) ac.setFontAlignment(ersRecoveryLabel, "left") ersLabel = ac.addLabel(appWindow, "ERS:") ac.setPosition(ersLabel, elpx, elpy) ac.setFontSize(ersLabel, 18) ac.setCustomFont(ersLabel, FONT_NAME, 0, 0) ac.setFontColor(ersLabel, 1.0, 1.0, 0.2, 1) ac.setFontAlignment(ersLabel, "left") # ================================================================================================================= # FUEL LABEL # ================================================================================================================= fuelLabel = ac.addLabel(appWindow, "💧 --.- Laps") ac.setPosition(fuelLabel, 15, 36) ac.setFontSize(fuelLabel, 18) ac.setCustomFont(fuelLabel, FONT_NAME, 0, 0) ac.setFontColor(fuelLabel, 0.86, 0.86, 0.86, 1) ac.setFontAlignment(fuelLabel, "left") # ================================================================================================================= # DRS LABELS # ================================================================================================================= drsLabel = ac.addLabel(appWindow, "") ac.setPosition(drsLabel, -70, 0) ac.setSize(drsLabel, 70, 70) ac.setVisible(drsLabel, 0) drsPenaltyBackgroundLabel = ac.addLabel(appWindow, "") ac.setPosition(drsPenaltyBackgroundLabel, 0, 70) ac.setSize(drsPenaltyBackgroundLabel, 280, 25) ac.setBackgroundTexture(drsPenaltyBackgroundLabel, DRS_PENALTY_TEXTURE) ac.setVisible(drsPenaltyBackgroundLabel, 0) drsPenaltyLabel = ac.addLabel(appWindow, "") ac.setPosition(drsPenaltyLabel, 150, 70) ac.setFontSize(drsPenaltyLabel, 18) ac.setCustomFont(drsPenaltyLabel, FONT_NAME, 0, 1) ac.setFontColor(drsPenaltyLabel, 0.86, 0.86, 0.86, 1) ac.setFontAlignment(drsPenaltyLabel, "center") ac.setVisible(drsPenaltyLabel, 0) # Announce Start timer = threading.Timer(10, announceStart) timer.start() return APP_NAME
import sys import ac import acsys import time from config import GRID_IDS, ADMIN_PW from itertools import cycle appName = "Dynamic Ballast" WIDTH, HEIGHT = 400, 700 # width and height of the app's window USE_GRID_ID_CONVERSION = True # Lookup table needed in config.py if True NCARS = ac.getCarsCount() DRIVER_NAMES = [ac.getDriverName(i) for i in range(NCARS)] def msg_turn_generator(n_players): for a in cycle(["ballast", "restrictor"]): for b in range(n_players): yield (a, b) def acMain(ac_version): global appWindow, last_calculated, last_posted, turn_gen appWindow = ac.newApp(appName) ac.setTitle(appWindow, appName) ac.setSize(appWindow, WIDTH, HEIGHT) last_calculated = time.clock() last_posted = time.clock()