Make all lamps multicoloured.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 10:34:54 +0000 (12:34 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 10:34:54 +0000 (12:34 +0200)
data/stations/station-alpha.json
data/stations/station-beta.json
tabakrolletjie/lights.py

index 6259351bee9ff8d2ce33c61dc29c7a2da52d49fe..5df98c3a54f517163090665ff9625cd30f07ca0a 100644 (file)
@@ -27,7 +27,7 @@
   "lights": [
     {
       "type": "spotlight",
-      "colour": "red",
+      "colours": ["red"],
       "position": [700, 500],
       "radius_limits": [20, 400],
       "direction": 135,
@@ -37,7 +37,7 @@
     },
     {
       "type": "lamp",
-      "colour": "yellow",
+      "colours": ["yellow"],
       "position": [500, 500],
       "intensity": 0.5
     },
@@ -49,7 +49,7 @@
     },
     {
       "type": "pulsatinglamp",
-      "colour": "cyan",
+      "colours": ["cyan"],
       "pulse_range": [20, 90],
       "pulse_velocity": 1,
       "intensity_range": [0.1, 0.8],
index f2f535b3d59cff57f8ba6c7885af09f537de9795..ae16cff5d3eb359e372783af932de1dd17e3a97b 100644 (file)
@@ -27,7 +27,7 @@
   "lights": [
     {
       "type": "spotlight",
-      "colour": "red",
+      "colours": ["red"],
       "position": [700, 500],
       "radius_limits": [20, 400],
       "intensity": 0.8
index ed18fdf9cfef629002310652fc0cd609c9969b53..03adf387cb2fb299ac57bc2942d7870532c31719 100644 (file)
@@ -108,9 +108,11 @@ class BaseLight(object):
     _surface_cache = {}
 
     def __init__(
-            self, colour, position, intensity=1.0, radius_limits=None,
+            self, colours, position, intensity=1.0, radius_limits=None,
             direction=None, spread=None):
-        self.colour = colour
+        self.colour_cycle = colours
+        self.colour_pos = 0
+        self.colour = colours[0]
         self.on = True
         self.intensity = intensity
         self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
@@ -143,9 +145,6 @@ class BaseLight(object):
         self.ray_manager.set_space(space)
         self.ray_manager.update_shapes()
 
-    def toggle(self):
-        self.on = not self.on
-
     def _cached_surface(self, name, surface):
         surf = self._surface_cache.get(name)
         if surf is None:
@@ -214,6 +213,17 @@ class BaseLight(object):
         rx, ry = self.ray_manager.pygame_position(surface)
         surface.blit(self.fitting_image(), (rx - 24, ry - 24), None, 0)
 
+    def toggle(self):
+        self.colour_pos += 1
+        if self.colour_pos >= len(self.colour_cycle):
+            self.colour = self.colour_cycle[0]
+            self.colour_pos = -1
+            self.on = False
+        else:
+            self.colour = self.colour_cycle[self.colour_pos]
+            self.on = True
+        self.invalidate_fitting_image()
+
     def tick(self):
         pass
 
@@ -226,25 +236,10 @@ class Lamp(BaseLight):
 class MultiColourLamp(BaseLight):
 
     FITTING_IMG = "lamp.png"
-    DEFAULT_COLOURS = sorted(COLOURS.keys())
 
     def __init__(self, **kw):
-        self.colour_cycle = kw.pop("colours", None)
-        self.colour_pos = 0
-        kw["colour"] = self.colour_cycle[0]
         super(MultiColourLamp, self).__init__(**kw)
 
-    def toggle(self):
-        self.colour_pos += 1
-        if self.colour_pos >= len(self.colour_cycle):
-            self.colour = self.colour_cycle[0]
-            self.colour_pos = -1
-            self.on = False
-        else:
-            self.colour = self.colour_cycle[self.colour_pos]
-            self.on = True
-        self.invalidate_fitting_image()
-
 
 class PulsatingLamp(BaseLight):