# HG changeset patch # User Beliar # Date 1331878567 -3600 # Node ID f4994e080d87405777974f050be1124e22586673 # Parent 9e7f494cc8509d8cb6d7285c870d4014d0631d0d Added CodeAction which executes a code inside the GameEnvironment. diff -r 9e7f494cc850 -r f4994e080d87 entities/action.py --- a/entities/action.py Fri Mar 16 07:15:08 2012 +0100 +++ b/entities/action.py Fri Mar 16 07:16:07 2012 +0100 @@ -609,6 +609,28 @@ self.text) Action.execute(self) +class CodeAction(Action): + """Executes a code inside the GameEnvironment""" + def __init__(self, controller, code, commands=None): + """ + @param controller: A reference to the GameSceneController. + @type controller: parpg.GameSceneController + @param commands: Special commands that are executed + @type commands: Dictionary + @type view: class derived from parpg.ViewBase + @param view: The view + @param lockable: The code to execute + """ + Action.__init__(self, controller, commands) + self.view = controller.view + self.code = code + + def execute(self): + """Executes the code.""" + globals, locals = self.controller.model.game_state.getGameEnvironment() + exec self.code in globals, locals + Action.execute(self) + ACTIONS = {"ChangeMap":ChangeMapAction, "Open":OpenAction, "Close":CloseAction, @@ -626,5 +648,6 @@ "ExamineContents": ExamineContentsAction, "RunScript": RunScriptAction, "Say" : SayAction, + "Code": CodeAction, "None": Action, }