changeset 178:c706963ed0c3

Made the entities of the current map available in the console.
author Beliar <KarstenBock@gmx.net>
date Tue, 06 Mar 2012 15:39:14 +0100
parents 62aed6388159
children 90b2545f7459
files console.py
diffstat 1 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/console.py	Tue Mar 06 15:15:18 2012 +0100
+++ b/console.py	Tue Mar 06 15:39:14 2012 +0100
@@ -48,14 +48,6 @@
         self.view = self.app_listener.view 
         self.model = self.app_listener.model
         self.game_state = self.app_listener.view.model.game_state
-        self.console_locals = {"__name__":"__paprg_console__",\
-                               "__doc__": None,\
-                               "app_listener":self.app_listener,\
-                               "model":self.app_listener.model,\
-                               "view":self.app_listener.view,\
-                               "engine":self.app_listener.engine}
-
-        self.console = code.InteractiveConsole(self.console_locals)
 
     def handleQuit(self, command):
         """Implements the quit console command 
@@ -104,6 +96,16 @@
         return res
 
     def handlePython(self,command):
+        console_locals = {
+                        "__name__":"__paprg_console__",
+                        "__doc__": None,
+                        }
+        vals, funcs = self.game_state.getGameEnvironment()
+        console_locals.update(vals)
+        console_locals.update(funcs)
+
+        console = code.InteractiveConsole(console_locals)
+
         user_code = command[7:len(command)]
 
         codeOut = StringIO()
@@ -117,8 +119,8 @@
             user_code = ""
 
         #Process the code
-        self.console.push(user_code)
-        if len(self.console.buffer) == 0:
+        console.push(user_code)
+        if len(console.buffer) == 0:
             output = codeOut.getvalue()
         else:
             output =  "..."
@@ -127,7 +129,6 @@
         #restore stdout and stderr
         sys.stdout = sys.__stdout__
         sys.stderr = sys.__stderr__
-
         temp_output = output
         output = ""
         counter = 0