From 2c0ed0a3af1c96ffa24745ba4b995dec0a7549c3 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 12:34:54 +0200 Subject: [PATCH] Make all lamps multicoloured. --- data/stations/station-alpha.json | 6 +++--- data/stations/station-beta.json | 2 +- tabakrolletjie/lights.py | 35 ++++++++++++++------------------ 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/data/stations/station-alpha.json b/data/stations/station-alpha.json index 6259351..5df98c3 100644 --- a/data/stations/station-alpha.json +++ b/data/stations/station-alpha.json @@ -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], diff --git a/data/stations/station-beta.json b/data/stations/station-beta.json index f2f535b..ae16cff 100644 --- a/data/stations/station-beta.json +++ b/data/stations/station-beta.json @@ -27,7 +27,7 @@ "lights": [ { "type": "spotlight", - "colour": "red", + "colours": ["red"], "position": [700, 500], "radius_limits": [20, 400], "intensity": 0.8 diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index ed18fdf..03adf38 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -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): -- 2.34.1