Example #1
0
File: Track.py Project: Pesa/forse
 def _sectorsToItems(self, sectors, nextColor):
     color = nextColor()
     items = []
     pos, angle = QPointF(), 90.0
     for sector in sectors:
         item = None
         if len(sector) == 1:
             type, = sector
             if type.text == "intermediate":
                 item = Intermediate(self, pos, angle)
                 color = nextColor()
             elif type.text == "pitlane_entrance":
                 item = PitLaneEntrance(self, pos, angle)
             elif type.text == "pitlane_exit":
                 item = PitLaneExit(self, pos, angle)
         elif len(sector) == 2:
             type, pit = sector
             if type.text == "finish_line":
                 item = FinishLine(self, pos, angle, atomToBool(pit))
                 color = nextColor()
         elif len(sector) == 3:
             type, length, pit = sector
             if type.text == "straight":
                 ctor = StraightSectorWithPitlane if atomToBool(pit) else StraightSector
                 item = ctor(self, pos, angle, length, color)
         elif len(sector) == 4:
             type, length, curv, pit = sector
             ctor = BentSectorWithPitlane if atomToBool(pit) else BentSector
             if type.text == "left":
                 item = ctor(self, pos, angle, length, color, curv)
             elif type.text == "right":
                 item = ctor(self, pos, angle, length, color, -curv)
         if item is not None:
             pos, newangle = item.finalLocation()
             angle = (angle + newangle) % 360
             items.append(item)
     # fix coloring of the last intermediate
     for item in items:
         if isinstance(item, (FinishLine, Intermediate)):
             break
         item.setColor(color)
     return items
Example #2
0
 def _moveCars(self, cars):
     for carId, pos, pit in cars:
         self._cars[carId].updatePos(pos, atomToBool(pit))
Example #3
0
 def _initCars(self, cars):
     for carId, pos, pit in cars:
         c = Car(self._track, carId, pos, atomToBool(pit))
         self._cars[carId] = c
         self.scene().addItem(c)