Mercurial > parpg-source
changeset 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 | 9e7f494cc850 |
children | c41299c7e833 |
files | entities/action.py |
diffstat | 1 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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, }