changeset 187:ab6a0fd1668a

Added help, moveObject, deleteObject, putItemIntoContainer, equipItem, createItemByID and createItemByType functions to the GameEnvironment.
author Beliar <KarstenBock@gmx.net>
date Sat, 24 Mar 2012 09:59:46 +0100
parents c41299c7e833
children 2a12e2843984
files gamemodel.py gamescenecontroller.py gamestate.py
diffstat 3 files changed, 39 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/gamemodel.py	Tue Mar 20 14:31:02 2012 +0100
+++ b/gamemodel.py	Sat Mar 24 09:59:46 2012 +0100
@@ -60,7 +60,7 @@
         """Initialize the instance.
         @param engine: A fife.Engine object
         @type emgome: fife.Engine 
-        @param setting: The applications settigns
+        @param setting: The applications settings
         @type setting: parpg.settings.Settings object
         @return: None"""
         self.settings = settings
@@ -69,9 +69,15 @@
         self.load_saver = False
         self.savegame = None
         quests_directory = settings.get("parpg", "QuestsPath")
+        #setup functions for the GameEnvironment        
         self.game_state = GameState(quests_dir=quests_directory)
-        #self.game_state.quest_engine = 
-        #self.game_state.quest_engine.readQuests()
+        funcs = {
+                 "moveObject":self.moveObject, 
+                 "deleteObject":self.deleteObject, 
+                 "putItemIntoContainer":container.put_item,
+                 "equipItem":equip.equip, 
+                 }
+        self.game_state.funcs.update(funcs)
         self.pc_run = 1
         self.target_position = None
         self.target_map_name = None
--- a/gamescenecontroller.py	Tue Mar 20 14:31:02 2012 +0100
+++ b/gamescenecontroller.py	Sat Mar 24 09:59:46 2012 +0100
@@ -74,6 +74,24 @@
                                 model,
                                 application)
         World.__init__(self)
+
+        #setup functions for the GameEnvironment        
+        createItemByID = lambda identifier : (
+                self.model.createItemByID(
+                                    identifier=identifier, 
+                                    world=self)
+            )
+        createItemByType = lambda item_type, identifier: (
+                self.model.createItemByType(
+                                      item_type=item_type, 
+                                      identifier=identifier, 
+                                      world=self)
+            )
+        funcs = {
+         "createItemByID": createItemByID, 
+         "createItemByType": createItemByType, 
+         }
+        self.model.game_state.funcs.update(funcs)
         self.systems.scripting.game_state = self.model.game_state
         
         #this can be helpful for IDEs code analysis
--- a/gamestate.py	Tue Mar 20 14:31:02 2012 +0100
+++ b/gamestate.py	Sat Mar 24 09:59:46 2012 +0100
@@ -12,11 +12,14 @@
 
 #   You should have received a copy of the GNU General Public License
 #   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
-
 import math
 
 from parpg.quest_engine import QuestEngine
 
+def script_help(object):
+    """Python's help() function with the no-parameters path disabled"""
+    help(object)
+    
 class GameState(object):
     """This class holds the current state of the game."""
     def __init__(self, quests_dir = None):
@@ -29,13 +32,14 @@
         self.maps = {}
         self.npcs_met = set()
         self.funcs = {
-            "__builtins__":None,
-            "meet":self.meet,
-            "met":self.met,
-            "sqrt":math.sqrt,
-            "log":math.log, 
-            "str":str, 
-            }
+                "__builtins__":None,
+                "help":script_help, 
+                "sqrt":math.sqrt,
+                "log":math.log, 
+                "str":str, 
+                "meet":self.meet,
+                "met":self.met,
+                }                
         self.locals = {}