added tooltips with information about light tools
[tabakrolletjie.git] / tabakrolletjie / lights.py
index 44c93871c805b34b5fc70761e4be500f3b461957..00f4c85b6e6f767fa761f920afc31ba2db6e5fb3 100644 (file)
@@ -142,6 +142,11 @@ def seed_cost(light_config, num_colours):
     cls = BaseLight.find_cls(light_config["type"])
     return cls.BASE_COST + int(cls.find_cost(light_config) / 10) + num_colours
 
+def light_info(light_config):
+    """Generate info about a light to go in the tooltip. """
+    cls = BaseLight.find_cls(light_config["type"])
+    return cls.get_info(light_config)
+
 
 class BaseLight(object):
     """ Common light functionality. """
@@ -216,6 +221,10 @@ class BaseLight(object):
         cost = 5 * config["intensity"]
         return cost
 
+    @classmethod
+    def get_info(cls, config):
+        return ["intensity: %g" % config["intensity"]]
+
     def add(self, space):
         if self.body.space is not None:
             space.remove(self.body, *self.body.shapes)
@@ -382,6 +391,17 @@ class PulsatingLamp(BaseLight):
         cost += 5 * (ir[1] - ir[0])
         return cost
 
+    @classmethod
+    def get_info(cls, config):
+        pr = config.get("pulse_range", cls.DEFAULT_PULSE_RANGE)
+        pv = config.get("pulse_velocity", cls.DEFAULT_PULSE_VELOCITY)
+        ir = config.get("intensity_range", cls.DEFAULT_INTENSITY_RANGE)
+        iv = config.get("intensity_velocity", cls.DEFAULT_INTENSITY_VELOCITY)
+        return [
+            "intensity: %g - %g, velocity %g" % (ir[0], ir[1], iv),
+            "pulse: %d - %d, velocity %g" % (pr[0], pr[1], pv),
+        ]
+
 
 class SpotLight(BaseLight):
 
@@ -417,4 +437,18 @@ class SpotLight(BaseLight):
     def find_cost(cls, config):
         cost = super(SpotLight, cls).find_cost(config)
         cost += config.get("angular_velocity", 0)
+        cost += config["spread"] / 10
+        rl = config["radius_limits"]
+        cost += (rl[1] - rl[0]) / 10
         return cost
+
+    @classmethod
+    def get_info(cls, config):
+        info = super(SpotLight, cls).get_info(config)
+        rl = config["radius_limits"]
+        info.extend([
+            "spread: %d" % config["spread"],
+            "length: %d" % (rl[1] - rl[0]),
+            "angular velocity: %g" % config.get("angular_velocity", 0),
+        ])
+        return info