changeset 190:30f2308c1efc

Fix tests and add a (currently unhooked) laser welder.
author Jeremy Thurgood <firxen@gmail.com>
date Wed, 25 Aug 2010 20:09:19 +0200
parents c18ef647ffe6
children 278774b31d3c
files gamelib/scenes/machine.py gamelib/tests/game_logic_utils.py gamelib/tests/test_scene_interactions_cryo.py
diffstat 3 files changed, 83 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/scenes/machine.py	Wed Aug 25 18:04:00 2010 +0200
+++ b/gamelib/scenes/machine.py	Wed Aug 25 20:09:19 2010 +0200
@@ -37,4 +37,55 @@
         self.state.set_current_scene("map")
 
 
+class LaserWelder(Thing):
+
+    NAME = "machine.laser_welder"
+
+    INTERACTS = {
+        "weld": InteractText(200, 200, "Laser welder"),
+    }
+
+    INITIAL = "weld"
+
+    INITIAL_DATA = {
+        'cans_in_place': 0,
+    }
+
+    def interact_without(self):
+        if self.get_data('cans_in_place') < 1:
+            return Result("The laser welder doesn't currently contain anything weldable.")
+        elif self.get_data('cans_in_place') < 3:
+            return Result("You'll need more cans than that.")
+        else:
+            self.set_data('cans_in_place', 0)
+            self.state.add_inventory_item('tube_fragments')
+            return Result("With high-precision spitzensparken, the cans are welded into a replacement tube.")
+
+    def interact_with_dented_can(self, item):
+        return self.interact_with_empty_can(item)
+
+    def interact_with_empty_can(self, item):
+        starting_cans = self.get_data('cans_in_place')
+        if starting_cans < 3:
+            self.state.remove_inventory_item(item.name)
+            self.set_data('cans_in_place', starting_cans + 1)
+            return Result({
+                    0: "You carefully place the empty can in the area marked 'to weld'.",
+                    1: "You carefully place the empty can next to the other.",
+                    2: "You carefully place the empty can next to its mates.",
+                    }[starting_cans])
+        else:
+            return Result("The machine has enough cans to weld for the moment.")
+
+    def get_description(self):
+        msg = "This is a Smith and Wesson 'zOMG' class high-precision laser welder."
+        if self.get_data('cans_in_place') == 1:
+            msg += " It currently contains an empty can."
+        elif self.get_data('cans_in_place') == 2:
+            msg += " It currently contains two empty cans."
+        elif self.get_data('cans_in_place') == 3:
+            msg += " It currently contains three empty cans."
+        return msg
+
+
 SCENES = [Machine]
--- a/gamelib/tests/game_logic_utils.py	Wed Aug 25 18:04:00 2010 +0200
+++ b/gamelib/tests/game_logic_utils.py	Wed Aug 25 20:09:19 2010 +0200
@@ -10,6 +10,7 @@
 
 # We need this stuff set up so we can load images and whatnot.
 pygame.display.init()
+pygame.font.init()
 pygame.display.set_mode(SCREEN, SWSURFACE)
 
 
@@ -39,8 +40,17 @@
     def assert_inventory_item(self, item, in_inventory=True):
         self.assertEquals(in_inventory, self.state.items[item] in self.state.inventory)
 
-    def interact_thing(self, thing, item=None):
+    def assert_scene_thing(self, thing, in_scene=True):
+        self.assertEquals(in_scene, thing in self.state.current_scene.things)
+
+    def assert_detail_thing(self, thing, in_detail=True):
+        self.assertEquals(in_detail, thing in self.state.current_detail.things)
+
+    def interact_thing(self, thing, item=None, detail=False):
         item_obj = None
         if item is not None:
             item_obj = self.state.items[item]
-        self.state.scenes[self.CURRENT_SCENE].things[thing].interact(item_obj)
+        thing_container = self.state.current_scene
+        if detail:
+            thing_container = self.state.current_detail
+        return thing_container.things[thing].interact(item_obj)
--- a/gamelib/tests/test_scene_interactions_cryo.py	Wed Aug 25 18:04:00 2010 +0200
+++ b/gamelib/tests/test_scene_interactions_cryo.py	Wed Aug 25 20:09:19 2010 +0200
@@ -8,28 +8,20 @@
     def test_cryo_door_closed_hand(self):
         "The door is closed and we touch it with the hand. It becomes ajar."
 
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', False, scene='bridge')
         self.assert_game_data('door', 'shut', 'cryo.door')
 
         self.interact_thing('cryo.door')
 
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', False, scene='bridge')
         self.assert_game_data('door', 'ajar', 'cryo.door')
 
     def test_cryo_door_closed_titanium_leg(self):
         "The door is closed and we touch it with the titanium leg. It opens."
 
         self.state.add_inventory_item('titanium_leg')
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', False, scene='bridge')
         self.assert_game_data('door', 'shut', 'cryo.door')
 
         self.interact_thing('cryo.door', 'titanium_leg')
 
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', False, scene='bridge')
         self.assert_game_data('door', 'shut', 'cryo.door')
         self.assert_inventory_item('titanium_leg', True)
 
@@ -37,13 +29,9 @@
         "The door is ajar and we touch it with the hand. No change."
 
         self.set_game_data('door', 'ajar', 'cryo.door')
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', False, scene='bridge')
 
         self.interact_thing('cryo.door')
 
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', False, scene='bridge')
         self.assert_game_data('door', 'ajar', 'cryo.door')
 
     def test_cryo_door_ajar_titanium_leg(self):
@@ -51,47 +39,50 @@
 
         self.state.add_inventory_item('titanium_leg')
         self.set_game_data('door', 'ajar', 'cryo.door')
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', False, scene='bridge')
 
         self.interact_thing('cryo.door', 'titanium_leg')
 
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', True, scene='bridge')
         self.assert_game_data('door', 'open', 'cryo.door')
-        self.assert_inventory_item('titanium_leg', False)
+        self.assert_inventory_item('titanium_leg', True)
 
     def test_cryo_door_open_hand(self):
-        "The door is open and we touch it with the hand. No change."
+        "The door is open and we touch it with the hand. We go to the map."
 
-        self.set_game_data('accessible', True, scene='bridge')
-        self.set_game_data('open', True, 'cryo.door')
+        self.set_game_data('door', 'open', 'cryo.door')
 
         self.interact_thing('cryo.door')
 
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', True, scene='bridge')
-        self.assert_game_data('open', True, 'cryo.door')
+        self.assert_game_data('door', 'open', 'cryo.door')
+        self.assertEquals('map', self.state.current_scene.name)
 
     def test_cryo_door_open_titanium_leg(self):
         "The door is open and we touch it with the titanium leg. No change."
 
-        self.set_game_data('accessible', True, scene='bridge')
-        self.set_game_data('open', True, 'cryo.door')
+        self.set_game_data('door', 'open', 'cryo.door')
 
         self.interact_thing('cryo.door', 'titanium_leg')
 
-        self.assert_game_data('accessible', True)
-        self.assert_game_data('accessible', True, scene='bridge')
-        self.assert_game_data('open', True, 'cryo.door')
+        self.assert_game_data('door', 'open', 'cryo.door')
+        self.assertEquals('cryo', self.state.current_scene.name)
 
     def test_cryo_unit_alpha_full_hand(self):
         "The cryo unit has the leg in it and we touch it. We get the leg."
 
+        self.state.set_current_detail('cryo_detail')
         self.assert_game_data('contains_titanium_leg', True, 'cryo.unit.1')
         self.assert_inventory_item('titanium_leg', False)
+        self.assert_detail_thing('cryo.titanium_leg', True)
 
-        self.interact_thing('cryo.unit.1')
+        self.interact_thing('cryo.titanium_leg', detail='cryo_detail')
 
         self.assert_game_data('contains_titanium_leg', False, 'cryo.unit.1')
         self.assert_inventory_item('titanium_leg', True)
+        self.assert_detail_thing('cryo.titanium_leg', False)
+
+    def test_cryo_unit_detail(self):
+        "The cryo unit thing opens a detail window."
+
+        resp = self.interact_thing('cryo.unit.1')
+
+        self.assertEquals('cryo_detail', resp.detail_view)
+