Merge branch 'master' of ctpug.org.za:koperkapel
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 13:29:39 +0000 (15:29 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 13:29:39 +0000 (15:29 +0200)
koperkapel/roaches.py
koperkapel/scenes/roach_management.py
koperkapel/serums.py
koperkapel/vehicles/base.py

index b39d189fe669c6571047973feb33f8b7b6e4eecc..95353ee18a441bdf947bb4cf07586c41e1faa18b 100644 (file)
@@ -8,6 +8,13 @@ from .actors.orientatedsurf import OrientatedSurfActor
 from .serums import roach_serum_color
 
 
+def roach_by_name(world, roach_name):
+    roaches = [r for r in world.roaches if r.name == roach_name]
+    if not roaches:
+        return None
+    return roaches[0]
+
+
 class RoachActor(OrientatedSurfActor):
     def __init__(self, frames):
         self._frames = frames
index d5fc67ffe749bcb3039778b2f7142e29c96d47ec..9a356ac918c9f8932b49e135b85abd0262fac4ea 100644 (file)
@@ -4,8 +4,8 @@ from pgzero.constants import keys, mouse
 from pgzero.actor import Actor
 from ..actors.buttons import ImageButton
 from ..constants import WIDTH, HEIGHT
-from ..roaches import big_roaches
-from ..serums import big_serums, SERUMS
+from ..roaches import big_roaches, roach_by_name
+from ..serums import big_serums, roach_is_serumless, SERUMS
 from ..vehicles.base import Vehicle
 from .base import Scene, ChangeSceneEvent
 
@@ -184,11 +184,32 @@ class RoachesScene(Scene):
         if world is None:
             self._update_calls.append(self._click_inventory_pad)
             return
+        roach_name = self._vehicle.roach_at(world, self._seat_pos)
+        if roach_name is None:
+            return
+        roach = roach_by_name(world, roach_name)
+        if roach is None:
+            return
+        serums = list(world.serums)
+        if self._inventory_pos >= len(serums):
+            return
+        serum = serums.pop(self._inventory_pos)
+        if roach_is_serumless(roach):
+            roach[serum] = True
+            world.serums = serums
+            self._update_calls.append((self._update_roach_actor, roach_name))
+
+    def _update_roach_actor(self, world, roach_name):
+        roach = roach_by_name(world, roach_name)
+        self._roach_actors[roach_name] = big_roaches.assemble(roach)
 
     def update(self, world, engine, dt):
-        while self._update_calls:
-            f = self._update_calls.pop()
-            f(world)
+        update_calls, self._update_calls = self._update_calls, []
+        while update_calls:
+            f, args = update_calls.pop(), ()
+            if type(f) is tuple:
+                f, args = f[0], f[1:]
+            f(world, *args)
         events = world.pop_events()
         self._update_inventory(world)
         self._update_roaches(world)
index c2a52bba6ff0e10525597d2b1a1760108ef95036..40ebfbac59f11950847f662e80906e6107e6c4a7 100644 (file)
@@ -27,6 +27,13 @@ def roach_serum_color(roach):
     return SERUM_OVERLAY_COLORS["none"]
 
 
+def roach_is_serumless(roach):
+    for serum_name in SERUMS:
+        if getattr(roach, serum_name):
+            return False
+    return True
+
+
 class SerumFactory:
     def __init__(self, suffix):
         self.suffix = suffix
index ba4fbb77325b0542d32d7cb35e0d0d8a302be57f..47588a59c5450aaaabd5f74ac120302c65037f50 100644 (file)
@@ -42,6 +42,12 @@ class Vehicle:
         # line below records new seating on the world proxy
         vehicle.seating = seating
 
+    def roach_at(self, world, seat_pos):
+        roach_seating = world.vehicles[self.vehicle_type].seating
+        if seat_pos >= len(roach_seating):
+            return None
+        return roach_seating[seat_pos]
+
     _vehicle_types = {}
 
     @classmethod