added trigger for new first position

Sat, 15 Dec 2012 15:51:08 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Sat, 15 Dec 2012 15:51:08 +0100
changeset 117
534e5c4b82c3
parent 116
c2fc650cc48f
child 118
9d5456cf6dad

added trigger for new first position

slotUI/slotCli.py file | annotate | diff | comparison | revisions
--- a/slotUI/slotCli.py	Sun Dec 02 19:54:14 2012 +0100
+++ b/slotUI/slotCli.py	Sat Dec 15 15:51:08 2012 +0100
@@ -36,6 +36,7 @@
         "race_start":      os.path.abspath(SOUNDPREFIX + "sound/racestart.mp3"),
         "race_prepare":    os.path.abspath(SOUNDPREFIX + "sound/prepare.mp3"),
         "lap_record":      os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"),
+#        "first_position":  os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"),
         "fuel_warning1":   os.path.abspath(SOUNDPREFIX + "sound/fuel1.mp3"),
         "fuel_warning2":   os.path.abspath(SOUNDPREFIX + "sound/fuel2.mp3"),
         "fuel_full":       os.path.abspath(SOUNDPREFIX + "sound/fuel_full.mp3"),
@@ -111,10 +112,12 @@
         self.reset_slots()
         self.sysclk = 0.00
         self.sysclk_last = 0.00
-        self.bestlap = 9999999.00
+        self.bestlap = 9999999.00 # best lap time
         self.test = test
-        self.laplimit = 999;
-        self.timelimit = 0;
+        self.laplimit = 999 # race laplimit
+        self.timelimit = 0 # race timelimit
+        self.firstpos = -1 # first position slot
+        self.freerun = True # freerun mode = sort order by best lap
 
     def reset_slots(self):
         idx = 0
@@ -130,7 +133,6 @@
             slt["status"] = self.slot_dummy["status"]
             slt["clk"] = 0
             slt["limit"] = slt["profile"].getint("Settings", "Limit")
-            #slt["limit"] = 15
             idx += 1
         self.bestlap = 99999.00
         self.raceactive = False
@@ -138,11 +140,19 @@
     def update_positions(self):
         order1 = sorted(self.slot, key=itemgetter(
             "clk"))
-        order2 = sorted(self.slot, key=itemgetter(
-            "laps"), reverse=True)
+        if self.freerun:
+            order2 = sorted(self.slot, key=itemgetter(
+                "best"))
+        else:
+            order2 = sorted(self.slot, key=itemgetter(
+                "laps"), reverse=True)
         idx = 1
         for tst in order2:
             self.slot[tst["car"]]["position"] = idx
+            # check if first position changed
+            if self.firstpos != tst["car"]:
+                self.firstpos = tst["car"]
+                trigger_event("first_position", tst["car"] + 1)
             idx += 1
 
     def render_slots(self):

mercurial