Mercurial > parpg-source
comparison 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 |
comparison
equal
deleted
inserted
replaced
160:75c0b728ccf3 | 161:d224bbce512a |
---|---|
351 agents = yaml.load_all(agents_data) | 351 agents = yaml.load_all(agents_data) |
352 self.agents[map_name] = {} | 352 self.agents[map_name] = {} |
353 for agent in agents: | 353 for agent in agents: |
354 if not agent == None: | 354 if not agent == None: |
355 self.addAgent(map_name, agent) | 355 self.addAgent(map_name, agent) |
356 | 356 |
357 def readScriptsOfMap(self, map_name, world): | |
358 """Read the scripts of the map | |
359 @param map_name: Name of the map | |
360 @type map_name: str | |
361 @param world: The current active world | |
362 @type world: parpg.world.World""" | |
363 map_scripts_file = ( | |
364 self.map_files[map_name].replace(".xml", "_scripts.yaml") | |
365 ) | |
366 if vfs.VFS.exists(map_scripts_file): | |
367 scripts_file = vfs.VFS.open(map_scripts_file) | |
368 scripts_data = yaml.load(scripts_file) | |
369 scripts = (scripts_data["Scripts"]) | |
370 conditions = ( | |
371 scripts_data["Conditions"] if | |
372 scripts_data.has_key("Conditions") else () | |
373 ) | |
374 scripting = world.systems.scripting | |
375 for name, actions in scripts.iteritems(): | |
376 scripting.setScript(name, actions) | |
377 for condition in conditions: | |
378 scripting.addCondition(*condition) | |
379 | |
357 def readAllAgents(self): | 380 def readAllAgents(self): |
358 """Read the agents of the all_agents_file and store them""" | 381 """Read the agents of the all_agents_file and store them""" |
359 agents_file = vfs.VFS.open(self.all_agents_file) | 382 agents_file = vfs.VFS.open(self.all_agents_file) |
360 agents = yaml.load_all(agents_file) | 383 agents = yaml.load_all(agents_file) |
361 for agent in agents: | 384 for agent in agents: |
599 self.engine.getModel().deleteMaps() | 622 self.engine.getModel().deleteMaps() |
600 self.engine.getModel().deleteObjects() | 623 self.engine.getModel().deleteObjects() |
601 self.game_state.clearObjects() | 624 self.game_state.clearObjects() |
602 self.game_state.maps = {} | 625 self.game_state.maps = {} |
603 | 626 |
604 def setActiveMap(self, map_name): | 627 def setActiveMap(self, map_name, world): |
605 """Sets the active map that is to be rendered. | 628 """Sets the active map that is to be rendered. |
606 @type map_name: String | 629 @type map_name: String |
607 @param map_name: The name of the map to load | 630 @param map_name: The name of the map to load |
631 @param world: The active world | |
632 @type world: parpg.world.World | |
608 @return: None""" | 633 @return: None""" |
609 # Turn off the camera on the old map before we turn on the camera | 634 # Turn off the camera on the old map before we turn on the camera |
610 # on the new map. | 635 # on the new map. |
611 self.active_map.cameras[self.active_map.my_cam_id].setEnabled(False) | 636 self.active_map.cameras[self.active_map.my_cam_id].setEnabled(False) |
612 # Make the new map active. | 637 # Make the new map active. |