comparison entities/action.py @ 185:f4994e080d87

Added CodeAction which executes a code inside the GameEnvironment.
author Beliar <KarstenBock@gmx.net>
date Fri, 16 Mar 2012 07:16:07 +0100
parents 95461b06bac1
children
comparison
equal deleted inserted replaced
184:9e7f494cc850 185:f4994e080d87
607 self.controller.view.hud.actions_box.addDialog( 607 self.controller.view.hud.actions_box.addDialog(
608 self.entity.description.view_name, 608 self.entity.description.view_name,
609 self.text) 609 self.text)
610 Action.execute(self) 610 Action.execute(self)
611 611
612 class CodeAction(Action):
613 """Executes a code inside the GameEnvironment"""
614 def __init__(self, controller, code, commands=None):
615 """
616 @param controller: A reference to the GameSceneController.
617 @type controller: parpg.GameSceneController
618 @param commands: Special commands that are executed
619 @type commands: Dictionary
620 @type view: class derived from parpg.ViewBase
621 @param view: The view
622 @param lockable: The code to execute
623 """
624 Action.__init__(self, controller, commands)
625 self.view = controller.view
626 self.code = code
627
628 def execute(self):
629 """Executes the code."""
630 globals, locals = self.controller.model.game_state.getGameEnvironment()
631 exec self.code in globals, locals
632 Action.execute(self)
633
612 ACTIONS = {"ChangeMap":ChangeMapAction, 634 ACTIONS = {"ChangeMap":ChangeMapAction,
613 "Open":OpenAction, 635 "Open":OpenAction,
614 "Close":CloseAction, 636 "Close":CloseAction,
615 "Unlock":UnlockAction, 637 "Unlock":UnlockAction,
616 "Lock":LockAction, 638 "Lock":LockAction,
624 "DropFromInventory":DropItemFromContainerAction, 646 "DropFromInventory":DropItemFromContainerAction,
625 "BrewBeer":BrewBeerAction, 647 "BrewBeer":BrewBeerAction,
626 "ExamineContents": ExamineContentsAction, 648 "ExamineContents": ExamineContentsAction,
627 "RunScript": RunScriptAction, 649 "RunScript": RunScriptAction,
628 "Say" : SayAction, 650 "Say" : SayAction,
651 "Code": CodeAction,
629 "None": Action, 652 "None": Action,
630 } 653 }