diff src/parpg/objects/action.py @ 134:c938a828a38a

Added actions for lockable components (Open, Close, Lock and Unlock).
author KarstenBock@gmx.net
date Fri, 30 Sep 2011 14:05:16 +0200
parents 0ffebdca7ba3
children 140e5e93f026
line wrap: on
line diff
--- a/src/parpg/objects/action.py	Fri Sep 30 14:04:29 2011 +0200
+++ b/src/parpg/objects/action.py	Fri Sep 30 14:05:16 2011 +0200
@@ -21,7 +21,7 @@
 
 from parpg.gui import drag_drop_data as data_drag
 from parpg.dialoguecontroller import DialogueController
-from parpg.components import container
+from parpg.components import container, lockable
 
 
 class NoSuchQuestException(Exception):
@@ -92,8 +92,8 @@
         super(ChangeMapAction, self).execute()
 
 class OpenAction(Action):
-    """Open a container"""
-    def __init__(self, controller, container, commands=None):
+    """Open an lockable"""
+    def __init__(self, controller, lockable, commands=None):
         """
         @param controller: A reference to the GameSceneController.
         @type controller: parpg.GameSceneController
@@ -101,21 +101,27 @@
         @type commands: Dictionary 
         @type view: class derived from parpg.ViewBase
         @param view: The view
-        @param container: A reference to the container
+        @param lockable: A reference to the lockable
         """
-        super(OpenAction, self).__init__(controller, commands)
+        Action.__init__(self, controller, commands)
         self.view = controller.view
-        self.container = container
+        self.lockable = lockable
+    
     def execute(self):
-        """Open the box."""
-        self.view.hud.createBoxGUI(self.container.name, \
-                                              self.container)
-        super(OpenAction, self).execute()
-       
-       
-class OpenBoxAction(OpenAction):
-    """Open a box. Needs to be more generic, but will do for now."""
-    def __init__(self, controller, container, commands = None):
+        """Open the lockable."""
+        try:
+            lockable.open(self.lockable.lockable)
+            self.lockable.fifeagent.behaviour.animate("open")
+            self.lockable.fifeagent.behaviour.queue_animation("opened", 
+                                                              repeating=True)
+        except lockable.LockedError:
+            self.view.hud.createExamineBox(self.lockable.description.view_name,
+                                           "Locked")            
+        Action.execute(self)
+
+class CloseAction(Action):
+    """Close an lockable"""
+    def __init__(self, controller, lockable, commands=None):
         """
         @param controller: A reference to the GameSceneController.
         @type controller: parpg.GameSceneController
@@ -123,57 +129,60 @@
         @type commands: Dictionary 
         @type view: class derived from parpg.ViewBase
         @param view: The view
-        @param container: A reference to the container
+        @param lockable: A reference to the lockable
         """
-        super(OpenBoxAction, self).__init__(controller, commands)
-        self.view = controller.view
-        self.container = container
-        
+        Action.__init__(self, controller, commands)
+        self.lockable = lockable
+    
     def execute(self):
-        """Open the box."""
-        try:
-            self.container.open()
-            super(OpenBoxAction, self).execute()
-
-        except ValueError:
-            self.view.hud.createExamineBox(self.container.name, \
-                                                  "The container is locked")
+        """Close the lockable."""
+        lockable.close(self.lockable.lockable)
+        self.lockable.fifeagent.behaviour.animate("close")
+        self.lockable.fifeagent.behaviour.queue_animation("closed", 
+                                                          repeating=True)
+        Action.execute(self)
         
-class UnlockBoxAction(Action):
-    """Unlocks a box. Needs to be more generic, but will do for now."""
-    def __init__(self, controller, container, commands = None):
+class UnlockAction(Action):
+    """Unlocks a lockable."""
+    def __init__(self, controller, lockable, commands = None):
         """
         @param controller: A reference to the GameSceneController.
         @type controller: parpg.GameSceneController
         @param commands: Special commands that are executed
         @type commands: Dictionary 
-        @param container: A reference to the container
+        @param lockable: A reference to the lockable
         """
-        super(UnlockBoxAction, self).__init__(controller, commands)
-        self.container = container
+        Action.__init__(self, controller, commands)
+        self.lockable = lockable
     
     def execute(self):
         """Open the box."""
-        self.container.unlock()
-        super(UnlockBoxAction, self).execute()
+        lockable.unlock(self.lockable.lockable)
+        Action.execute(self)
         
-class LockBoxAction(Action):
-    """Locks a box. Needs to be more generic, but will do for now."""
-    def __init__(self, controller, container, commands = None):
+class LockAction(Action):
+    """Locks a lockable."""
+    def __init__(self, controller, lockable, commands = None):
         """
         @param controller: A reference to the GameSceneController.
         @type controller: parpg.GameSceneController
         @param commands: Special commands that are executed
         @type commands: Dictionary 
-        @param container: A reference to the container
+        @param lockable: A reference to the lockable
         """
-        super(LockBoxAction, self).__init__(controller, commands)
-        self.container = container
+        Action.__init__(self, controller, commands)
+        self.lockable = lockable
+        self.view = controller.view
         
     def execute(self):
         """Lock the box."""
-        self.container.lock()
-        super(LockBoxAction, self).execute()
+        try:
+            lockable.lock(self.lockable.lockable)
+        except lockable.OpenError:
+            self.view.hud.createExamineBox(self.lockable.description.view_name,
+                                           "Is open")            
+            
+        Action.execute(self)
 
 
 class ExamineAction(Action):
@@ -547,9 +556,9 @@
 
 ACTIONS = {"ChangeMap":ChangeMapAction, 
            "Open":OpenAction,
-           "OpenBox":OpenBoxAction, 
-           "Unlock":UnlockBoxAction,
-           "Lock":LockBoxAction,
+           "Close":CloseAction,
+           "Unlock":UnlockAction,
+           "Lock":LockAction,
            "ExamineItem":ExamineItemAction,
            "Examine":ExamineAction,
            "Look":ExamineItemAction,