changeset 491:9f488671c02e engine_refactor

No more state in Item interacts.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 29 Aug 2010 19:58:35 +0200
parents 2e784f978d1a
children c1f4f9149349
files gamelib/scenes/bridge.py gamelib/scenes/crew_quarters.py gamelib/scenes/mess.py gamelib/state.py gamelib/tests/game_logic_utils.py
diffstat 5 files changed, 26 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/scenes/bridge.py	Sun Aug 29 15:15:59 2010 +0200
+++ b/gamelib/scenes/bridge.py	Sun Aug 29 19:58:35 2010 +0200
@@ -217,10 +217,10 @@
     INVENTORY_IMAGE = 'superconductor_fixed.png'
     CURSOR = CursorSprite('superconductor_fixed.png')
 
-    def interact_with_duct_tape(self, item, state):
+    def interact_with_duct_tape(self, item):
         taped_superconductor = TapedSuperconductor('taped_superconductor')
-        state.add_item(taped_superconductor)
-        state.replace_inventory_item(self.name, taped_superconductor.name)
+        self.state.add_item(taped_superconductor)
+        self.state.replace_inventory_item(self.name, taped_superconductor.name)
         return Result("You rip off a piece of duct tape and stick it on the superconductor. "
                       "It almost sticks to itself, but you successfully avoid disaster.")
 
--- a/gamelib/scenes/crew_quarters.py	Sun Aug 29 15:15:59 2010 +0200
+++ b/gamelib/scenes/crew_quarters.py	Sun Aug 29 19:58:35 2010 +0200
@@ -133,10 +133,10 @@
     CURSOR = CursorSprite('fishbowl.png')
     NAME = "fishbowl"
 
-    def interact_with_duct_tape(self, item, state):
+    def interact_with_duct_tape(self, item):
         helmet = FishbowlHelmet('helmet')
-        state.add_item(helmet)
-        state.replace_inventory_item(self.name, helmet.name)
+        self.state.add_item(helmet)
+        self.state.replace_inventory_item(self.name, helmet.name)
         return Result("You duct tape the edges of the helmet. The seal is"
                 " crude, but it will serve as a workable helmet if needed.")
 
--- a/gamelib/scenes/mess.py	Sun Aug 29 15:15:59 2010 +0200
+++ b/gamelib/scenes/mess.py	Sun Aug 29 19:58:35 2010 +0200
@@ -50,22 +50,22 @@
 class BaseCan(CloneableItem):
     """Base class for the cans"""
 
-    def interact_with_full_can(self, item, state):
+    def interact_with_full_can(self, item):
         return Result("You bang the cans together. It sounds like two cans being banged together.", soundfile="can_hit.ogg")
 
-    def interact_with_dented_can(self, item, state):
-        return self.interact_with_full_can(item, state)
+    def interact_with_dented_can(self, item):
+        return self.interact_with_full_can(item)
 
-    def interact_with_empty_can(self, item, state):
-        return self.interact_with_full_can(item, state)
+    def interact_with_empty_can(self, item):
+        return self.interact_with_full_can(item)
 
-    def interact_with_machete(self, item, state):
+    def interact_with_machete(self, item):
         return Result("You'd mangle it beyond usefulness.")
 
-    def interact_with_canopener(self, item, state):
+    def interact_with_canopener(self, item):
         empty = EmptyCan('empty_can')
-        state.add_item(empty)
-        state.replace_inventory_item(self.name, empty.name)
+        self.state.add_item(empty)
+        self.state.replace_inventory_item(self.name, empty.name)
         return Result("You open both ends of the can, discarding the hideous contents.")
 
 
@@ -75,10 +75,10 @@
     INVENTORY_IMAGE = "empty_can.png"
     CURSOR = CursorSprite('empty_can_cursor.png')
 
-    def interact_with_titanium_leg(self, item, state):
+    def interact_with_titanium_leg(self, item):
         return Result("Flattening the can doesn't look like a useful thing to do.")
 
-    def interact_with_canopener(self, item, state):
+    def interact_with_canopener(self, item):
         return Result("There's nothing left to open on this can")
 
 
@@ -88,10 +88,10 @@
     INVENTORY_IMAGE = "full_can.png"
     CURSOR = CursorSprite('full_can_cursor.png')
 
-    def interact_with_titanium_leg(self, item, state):
+    def interact_with_titanium_leg(self, item):
         dented = DentedCan("dented_can")
-        state.add_item(dented)
-        state.replace_inventory_item(self.name, dented.name)
+        self.state.add_item(dented)
+        self.state.replace_inventory_item(self.name, dented.name)
         return Result("You club the can with the femur. The can gets dented, but doesn't open.", soundfile="can_hit.ogg")
 
 
@@ -101,7 +101,7 @@
     INVENTORY_IMAGE = "dented_can.png"
     CURSOR = CursorSprite('dented_can_cursor.png')
 
-    def interact_with_titanium_leg(self, item, state):
+    def interact_with_titanium_leg(self, item):
         return Result("You club the can with the femur. The dents shift around, but it still doesn't open.", soundfile="can_hit.ogg")
 
 
--- a/gamelib/state.py	Sun Aug 29 15:15:59 2010 +0200
+++ b/gamelib/state.py	Sun Aug 29 19:58:35 2010 +0200
@@ -532,20 +532,17 @@
     def get_inventory_image(self):
         return self.inventory_image
 
-    def interact(self, tool, state):
+    def interact(self, tool):
         if tool is None:
             return self.interact_without(state)
         handler = getattr(self, 'interact_with_' + tool.name, None)
         inverse_handler = getattr(tool, 'interact_with_' + self.tool_name, None)
         if handler is not None:
-            return handler(tool, state)
+            return handler(tool)
         elif inverse_handler is not None:
-            return inverse_handler(self, state)
+            return inverse_handler(self)
         else:
-            return self.interact_default(tool, state)
-
-    def interact_default(self, tool, state):
-        return Result("That doesn't do anything useful")
+            return self.interact_default(tool)
 
 
 class CloneableItem(Item):
--- a/gamelib/tests/game_logic_utils.py	Sun Aug 29 15:15:59 2010 +0200
+++ b/gamelib/tests/game_logic_utils.py	Sun Aug 29 19:58:35 2010 +0200
@@ -81,7 +81,7 @@
         self.assert_inventory_item(target_item)
         item_obj = self.state.items[item]
         target_obj = self.state.items[target_item]
-        result = target_obj.interact(item_obj, self.state)
+        result = target_obj.interact(item_obj)
         return self.handle_result(result)
 
     def close_detail(self):