changeset 200:67d10f7e0159

selected chickens are selected
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Fri, 04 Sep 2009 19:51:19 +0000
parents 696936621a93
children fe1e9c18d4d7
files gamelib/animal.py gamelib/equipment.py gamelib/gameboard.py
diffstat 3 files changed, 31 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Fri Sep 04 19:49:30 2009 +0000
+++ b/gamelib/animal.py	Fri Sep 04 19:51:19 2009 +0000
@@ -65,13 +65,25 @@
             self.setimage(self.image_right)
 
     def equip(self, item):
-        self.equipment.append(item)
+        if equipment.is_equipment(item):
+            self.equipment.append(item)
+        elif equipment.is_accoutrement(item):
+            self.accoutrements.append(item)
         self.redraw()
 
     def unequip(self, item):
-        self.equipment = [e for e in self.equipment if e != item]
+        if equipment.is_equipment(item):
+            self.equipment = [e for e in self.equipment if e != item]
+        elif equipment.is_accoutrement(item):
+            self.accoutrements = [e for e in self.accoutrements if e != item]
         self.redraw()
 
+    def unequip_by_name(self, item_name):
+        # only remove first match
+        matches = [item for item in self.equipment + self.accoutrements if item.NAME == item_name]
+        if matches:
+            self.unequip(matches[0])
+
     def redraw(self):
         layers = [(self._image_left.copy(), self._image_right.copy(), 0)]
         if hasattr(self, 'EQUIPMENT_IMAGE_ATTRIBUTE'):
--- a/gamelib/equipment.py	Fri Sep 04 19:49:30 2009 +0000
+++ b/gamelib/equipment.py	Fri Sep 04 19:51:19 2009 +0000
@@ -128,6 +128,7 @@
 class Accoutrement(Equipment):
     """Things which are not equipment, but are displayed in the same way"""
     IS_EQUIPMENT = False
+    IS_ACCOUTREMENT = True
     BUY_PRICE = 0
     SELL_PRICE = 0
 
@@ -157,6 +158,9 @@
 def is_armour(obj):
     return is_equipment(obj) and getattr(obj, 'IS_ARMOUR', False)
 
+def is_accoutrement(obj):
+    return not getattr(obj, "IS_EQUIPMENT", False) and hasattr(obj, "NAME") and getattr(obj, 'IS_ACCOUTREMENT', False)
+
 EQUIPMENT = []
 for name in dir():
     obj = eval(name)
--- a/gamelib/gameboard.py	Fri Sep 04 19:49:30 2009 +0000
+++ b/gamelib/gameboard.py	Fri Sep 04 19:51:19 2009 +0000
@@ -217,7 +217,7 @@
 
     def set_selected_tool(self, tool, cursor):
         self.selected_tool = tool
-        self.animal_to_place = None
+        self.select_animal_to_place(None)
         if cursor:
             pygame.mouse.set_cursor(*cursor)
         else:
@@ -321,6 +321,13 @@
         if building and building.NAME in buildings.HENHOUSES:
             self.open_building_dialog(building, do_sell)
 
+    def select_animal_to_place(self, animal):
+        if self.animal_to_place:
+            self.animal_to_place.unequip_by_name("spotlight")
+        self.animal_to_place = animal
+        if self.animal_to_place:
+            self.animal_to_place.equip(equipment.Spotlight())
+
     def place_animal(self, tile_pos):
         """Handle an TOOL_PLACE_ANIMALS click.
 
@@ -330,10 +337,10 @@
         chicken = self.get_outside_chicken(tile_pos)
         if chicken:
             if chicken is self.animal_to_place:
-                self.animal_to_place = None
+                self.select_animal_to_place(None)
                 pygame.mouse.set_cursor(*cursors.cursors['select'])
             else:
-                self.animal_to_place = chicken
+                self.select_animal_to_place(chicken)
                 pygame.mouse.set_cursor(*cursors.cursors['chicken'])
             return
         building = self.get_building(tile_pos)
@@ -342,7 +349,7 @@
                 try:
                     place = building.first_empty_place()
                     self.relocate_animal(self.animal_to_place, place=place)
-                    self.animal_to_place = None
+                    self.select_animal_to_place(None)
                     pygame.mouse.set_cursor(*cursors.cursors['select'])
                 except buildings.BuildingFullError:
                     pass
@@ -400,12 +407,12 @@
             """Select occupant in place."""
             # sell_callback should return true if we need to remove the
             # occupant
-            self.animal_to_place = place.occupant
+            self.select_animal_to_place(place.occupant)
             if not sell_callback:
                 pygame.mouse.set_cursor(*cursors.cursors['chicken'])
             else:
                 # Attempt to sell the occupant
-                self.animal_to_place = None
+                self.select_animal_to_place(None)
                 if sell_callback(place.occupant):
                     button.value = icons.EMPTY_NEST_ICON
                     button.disconnect(gui.CLICK, select_occupant)