diff gamelib/scenes/crew_quarters.py @ 853:f95830b58336

Merge pyntnclick
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 21 Jun 2014 22:04:35 +0200
parents bdebe693453f
children
line wrap: on
line diff
--- a/gamelib/scenes/crew_quarters.py	Sat Jun 21 17:38:39 2014 +0000
+++ b/gamelib/scenes/crew_quarters.py	Sat Jun 21 22:04:35 2014 +0200
@@ -1,12 +1,15 @@
 """Crew quarters."""
 
-from gamelib.cursor import CursorSprite
-from gamelib.state import Scene, Item, Thing, Result
-from gamelib.scenewidgets import (InteractNoImage, InteractImage,
-                                  InteractAnimated, GenericDescThing)
+from pyntnclick.i18n import _
+from pyntnclick.cursor import CursorSprite
+from pyntnclick.state import Scene, Item, Thing, Result
+from pyntnclick.scenewidgets import (
+    InteractNoImage, InteractImage, InteractAnimated, GenericDescThing,
+    TakeableThing)
 
 from gamelib.scenes.game_constants import PLAYER_ID
-from gamelib.scenes.game_widgets import Door, BaseCamera, make_jim_dialog
+from gamelib.scenes.game_widgets import (Door, BaseCamera, make_jim_dialog,
+        make_sentence_dialog)
 
 
 class CrewQuarters(Scene):
@@ -16,21 +19,21 @@
 
     OFFSET = (0, -50)
 
-    def __init__(self, state):
-        super(CrewQuarters, self).__init__(state)
+    def setup(self):
         self.add_thing(ToMap())
         self.add_thing(Safe())
         self.add_thing(FishbowlThing())
-        self.add_item(Fishbowl('fishbowl'))
-        self.add_item(DuctTape('duct_tape'))
-        self.add_item(EscherPoster('escher_poster'))
+        self.add_item_factory(Fishbowl)
+        self.add_item_factory(DuctTape)
+        self.add_item_factory(EscherPoster)
+        self.add_item_factory(FishbowlHelmet)
         self.add_thing(PosterThing())
         self.add_thing(MonitorCamera())
         self.add_thing(GenericDescThing('crew.plant', 1,
-            "The plant is doing surprisingly well for centuries of neglect",
+            _("The plant is doing surprisingly well for centuries of neglect"),
             ((624, 215, 61, 108),)))
         self.add_thing(GenericDescThing('crew.cat', 2,
-            "A picture of a cat labelled 'Clementine'",
+            _("A picture of a cat labelled 'Clementine'"),
             ((722, 382, 66, 72),)))
 
 
@@ -63,39 +66,48 @@
         'has_tape': True,
         }
 
+    def select_interact(self):
+        if self.get_data('is_cracked'):
+            if self.get_data('has_tape'):
+                return 'full_safe'
+            return 'empty_safe'
+        return self.INITIAL
+
     def interact_without(self):
         if self.get_data('is_cracked'):
             if self.get_data('has_tape'):
                 self.set_data('has_tape', False)
-                self.state.add_inventory_item('duct_tape')
-                self.set_interact('empty_safe')
-                return Result("Duct tape. It'll stick to everything except "
-                              "ducts, apparently.")
-            return Result("The perfectly balanced door swings frictionlessly "
-                          "to and fro. What craftsmanship!")
-        return Result("The safe is locked. This might be an interesting "
-                      "challenge, if suitable equipment can be found.")
+                self.game.add_inventory_item('duct_tape')
+                self.set_interact()
+                return Result(_("Duct tape. It'll stick to everything except "
+                                "ducts, apparently."))
+            return Result(_("The perfectly balanced door swings "
+                            "frictionlessly to and fro. What craftsmanship!"))
+        return Result(_("The safe is locked. This might be an interesting "
+                        "challenge, if suitable equipment can be found."))
 
     def interact_with_stethoscope(self, item):
         if self.get_data('is_cracked'):
-            return Result("It's already unlocked. There's no more challenge.")
-        # TODO: Add years to the sentence for safecracking.
+            return Result(_("It's already unlocked. "
+                            "There's no more challenge."))
         # TODO: Wax lyrical some more about safecracking.
         self.set_data('is_cracked', True)
-        self.set_interact('full_safe')
-        return (Result("Even after centuries of neglect, the tumblers slide"
-                      " almost silently into place. Turns out the combination"
-                      " was '1 2 3 4 5'. An idiot must keep his luggage in"
-                      " here."),
-                      make_jim_dialog("Prisoner %s, you have been observed"
-                          " committing a felony violation. This will go onto"
-                          " your permanent record, and your sentence may be"
-                          " extended by up to twenty years."
-                          % PLAYER_ID, self.state))
+        self.set_interact()
+        self.state.increase_sentence(20)
+        return (Result(_("Even after centuries of neglect, the tumblers slide"
+                         " almost silently into place. Turns out the"
+                         " combination was '1 2 3 4 5'. An idiot must keep his"
+                         " luggage in here.")),
+                make_jim_dialog(_("Prisoner %s, you have been observed"
+                                  " committing a felony violation. This will"
+                                  " go onto your permanent record, and your"
+                                  " sentence will be extended by twenty"
+                                  " years.") % PLAYER_ID, self.game),
+                make_sentence_dialog(PLAYER_ID, self.game))
 
     def get_description(self):
-        return "Ah, a vintage Knoxx & Co. model QR3. Quaint, but" \
-                " reasonably secure."
+        return _("Ah, a vintage Knoxx & Co. model QR3. Quaint, but"
+                 " reasonably secure.")
 
 
 class FishbowlThing(Thing):
@@ -114,22 +126,27 @@
         'has_bowl': True,
         }
 
+    def select_interact(self):
+        if not self.get_data('has_bowl'):
+            return 'fish_no_bowl'
+        return self.INITIAL
+
     def interact_without(self):
         if not self.get_data('has_bowl'):
-            return Result("What's the point of lugging around a very dead"
-                    " fish and a kilogram or so of sand?")
-        self.set_interact('fish_no_bowl')
+            return Result(_("What's the point of lugging around a very dead"
+                            " fish and a kilogram or so of sand?"))
         self.set_data('has_bowl', False)
-        self.state.add_inventory_item('fishbowl')
-        return Result("The fishbowl is useful, but its contents aren't.")
+        self.set_interact()
+        self.game.add_inventory_item('fishbowl')
+        return Result(_("The fishbowl is useful, but its contents aren't."))
 
     def get_description(self):
         if self.get_data('has_bowl'):
-            return "This fishbowl looks exactly like an old science fiction" \
-                    " space helmet."
+            return _("This fishbowl looks exactly like an old science fiction"
+                     " space helmet.")
         else:
-            return "An evicted dead fish and some sand lie forlornly on the" \
-                    " table"
+            return _("An evicted dead fish and some sand lie forlornly on the"
+                     " table")
 
 
 class Fishbowl(Item):
@@ -140,11 +157,10 @@
     NAME = "fishbowl"
 
     def interact_with_duct_tape(self, item):
-        helmet = FishbowlHelmet('helmet')
-        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.")
+        self.game.replace_inventory_item(self.name, 'helmet')
+        return Result(_("You duct tape the edges of the helmet. The seal is"
+                        " crude, but it will serve as a workable helmet if"
+                        " needed."))
 
 
 class FishbowlHelmet(Item):
@@ -158,6 +174,7 @@
 class DuctTape(Item):
     "A bowl. Sans fish."
 
+    NAME = 'duct_tape'
     INVENTORY_IMAGE = 'duct_tape.png'
     CURSOR = CursorSprite('duct_tape.png')
 
@@ -176,7 +193,7 @@
     }
 
 
-class PosterThing(Thing):
+class PosterThing(TakeableThing):
     "A innocent poster on the wall"
 
     NAME = 'crew.poster'
@@ -186,14 +203,14 @@
     }
 
     INITIAL = 'poster'
+    ITEM = 'escher_poster'
 
     def interact_without(self):
-        self.state.add_inventory_item('escher_poster')
-        self.scene.remove_thing(self)
-        return Result("This poster will go nicely on your bedroom wall.")
+        self.take()
+        return Result(_("This poster will go nicely on your bedroom wall."))
 
     def get_description(self):
-        return "A paradoxical poster hangs below the security camera."
+        return _("A paradoxical poster hangs below the security camera.")
 
 
 class EscherPoster(Item):