Mercurial > parpg-source
diff gamemodel.py @ 161:d224bbce512a
Implemented loading scripts from files.
author | KarstenBock@gmx.net |
---|---|
date | Thu, 17 Nov 2011 20:36:08 +0100 |
parents | 0655f2f0f3cd |
children | b3b82c2aebee |
line wrap: on
line diff
--- a/gamemodel.py Sun Nov 13 17:19:14 2011 +0100 +++ b/gamemodel.py Thu Nov 17 20:36:08 2011 +0100 @@ -353,7 +353,30 @@ for agent in agents: if not agent == None: self.addAgent(map_name, agent) - + + def readScriptsOfMap(self, map_name, world): + """Read the scripts of the map + @param map_name: Name of the map + @type map_name: str + @param world: The current active world + @type world: parpg.world.World""" + map_scripts_file = ( + self.map_files[map_name].replace(".xml", "_scripts.yaml") + ) + if vfs.VFS.exists(map_scripts_file): + scripts_file = vfs.VFS.open(map_scripts_file) + scripts_data = yaml.load(scripts_file) + scripts = (scripts_data["Scripts"]) + conditions = ( + scripts_data["Conditions"] if + scripts_data.has_key("Conditions") else () + ) + scripting = world.systems.scripting + for name, actions in scripts.iteritems(): + scripting.setScript(name, actions) + for condition in conditions: + scripting.addCondition(*condition) + def readAllAgents(self): """Read the agents of the all_agents_file and store them""" agents_file = vfs.VFS.open(self.all_agents_file) @@ -601,10 +624,12 @@ self.game_state.clearObjects() self.game_state.maps = {} - def setActiveMap(self, map_name): + def setActiveMap(self, map_name, world): """Sets the active map that is to be rendered. @type map_name: String @param map_name: The name of the map to load + @param world: The active world + @type world: parpg.world.World @return: None""" # Turn off the camera on the old map before we turn on the camera # on the new map.