Changeset 559
- Timestamp:
- 06/22/10 17:37:37 (9 years ago)
- Location:
- branches/map_loading_change
- Files:
-
- 3 added
- 13 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/map_loading_change/game/local_loaders/__init__.py
r553 r559 26 26 from traceback import print_exc 27 27 28 __all__ = ('E T', 'SerializerError', 'InvalidFormat', 'WrongFileType',28 __all__ = ('ElementTree', 'SerializerError', 'InvalidFormat', 'WrongFileType', 29 29 'NameClash', 'NotFound', 'displayWarning', 'getRootSubfile', 30 30 'reverseRootSubfile') 31 31 32 32 try: 33 import xml.etree.cElementTree as E T33 import xml.etree.cElementTree as ElementTree 34 34 except(ImportError): 35 import xml.etree.ElementTree as E T#@Reimport35 import xml.etree.ElementTree as ElementTree #@Reimport 36 36 37 37 class SerializerError(Exception): -
branches/map_loading_change/game/local_loaders/xmlmap.py
r553 r559 23 23 from fife import fife 24 24 try: 25 import xml.etree.cElementTree as E T25 import xml.etree.cElementTree as ElementTree 26 26 except ImportError: 27 import xml.etree.ElementTree as E T27 import xml.etree.ElementTree as ElementTree 28 28 29 29 from fife.extensions import loaders … … 131 131 f = self.vfs.open(self.source) 132 132 f.thisown = 1 133 tree = E T.parse(f)133 tree = ElementTree.parse(f) 134 134 root = tree.getroot() 135 135 … … 183 183 for item in map_elt.findall('import'): 184 184 imp_file = item.get('file') 185 directory = item.get('dir') 185 186 if imp_file: 186 187 imp_file = reverseRootSubfile(self.source, imp_file) 187 directory = item.get('dir')188 188 if directory: 189 189 directory = reverseRootSubfile(self.source, directory) … … 192 192 if (directory,imp_file) in parsedImports: 193 193 print "Duplicate import:" ,(directory,imp_file) 194 continue194 #TODO return 195 195 parsedImports[(directory,imp_file)] = 1 196 196 -
branches/map_loading_change/game/maps/map.xml
r556 r559 3 3 <import file="../objects/ground/snow/snow0/snow02.xml" /> 4 4 <import file="../objects/ground/gravel/gravel.xml" /> 5 <import file="../objects/agents/npcs/long_coat_female/long_coat_female.xml" />6 <import file="../objects/agents/npcs/long_coat_male/long_coat_male.xml" />7 <import file="../objects/agents/npcs/male_farmer_1/male_farmer_1.xml" />8 <import file="../objects/agents/npcs/male_traveler_1/male_traveler_1.xml" />9 <import file="../objects/agents/npcs/npc_woman/npc_woman.xml" />10 5 <import file="../objects/scenery/crate/crate.xml" /> 11 6 <import file="../objects/buildings/guard_tower/guard_tower.xml" /> 12 <import file="../objects/agents/player/player.xml" />13 <import file="../objects/buildings/shanty/shanty-door.xml" />14 7 <import file="../objects/buildings/container_house/container_house01.xml" /> 15 8 <import file="../objects/buildings/container_house/container_house02.xml" /> 16 9 <import file="../objects/ground/block/block.xml" /> 17 10 <import file="../objects/scenery/burning_barrel/burning_barrel.xml" /> 18 <import file="../objects/scenery/lock_box_metal/lock_box_metal.xml" />19 11 <import file="../objects/buildings/gate/pillar1/p1_s0.xml" /> 20 12 <import file="../objects/buildings/gate/pillar1/p1_s1.xml" /> -
branches/map_loading_change/game/maps/map2.xml
r556 r559 2 2 <map format="1.0" id="Farm"> 3 3 <import file="../objects/ground/grass/grass-a.xml" /> 4 <import file="../objects/buildings/shanty/shanty-door.xml" />5 <import file="../objects/agents/npcs/long_coat_male/long_coat_male.xml" />6 <import file="../objects/agents/npcs/male_farmer_1/male_farmer_1.xml" />7 4 <layer grid_type="square" id="GroundLayer" pathing="cell_edges_only" rotation="0.0" transparency="0" x_offset="0.0" x_scale="1.0" y_offset="0.0" y_scale="1.0"> 8 5 <instances> -
branches/map_loading_change/game/maps/map2_agents.yaml
r555 r559 19 19 ObjectType: "ShantyDoor" 20 20 Position: [-2.0, 6.0, 0.0] 21 TargetMap: " main-map"21 TargetMap: "Mall" 22 22 TargetPosition: [5.0, 5.0] -
branches/map_loading_change/game/maps/map_agents.yaml
r555 r559 26 26 ObjectType: "ShantyDoor" 27 27 Position: [-6.0, -13.0, 0.0] 28 TargetMap: " map2"28 TargetMap: "Farm" 29 29 TargetPosition: [10.0, 10.0] 30 30 --- -
branches/map_loading_change/game/run.py
r553 r559 15 15 16 16 import os 17 18 17 from scripts.common import utils 19 18 -
branches/map_loading_change/game/scripts/common/utils.py
r530 r559 14 14 # Miscellaneous game functions 15 15 16 import os, sys 17 18 # TODO: Having a file like this just looks cheap and 'hackish'. Fix if possible 16 import os, sys, fnmatch 19 17 20 18 def addPaths (*paths): … … 36 34 return value.lower()[0] == "t" 37 35 return False 36 37 def locateFiles(pattern, root=os.curdir): 38 """Locate all files matching supplied filename pattern in and below 39 supplied root directory.""" 40 for path, _, files in os.walk(os.path.abspath(root)): 41 for filename in fnmatch.filter(files, pattern): 42 yield os.path.join(path, filename) -
branches/map_loading_change/game/scripts/controllerbase.py
r553 r559 24 24 model, 25 25 application, 26 settings,27 26 reg_mouse = True, 28 27 reg_keys = True): … … 49 48 50 49 self.application = application 51 self.settings = settings -
branches/map_loading_change/game/scripts/gamemap.py
r557 r559 24 24 settings_gui_xml="") 25 25 26 class Map(fife.MapChangeListener):26 class GameMap(fife.MapChangeListener): 27 27 """Map class used to flag changes in the map""" 28 28 def __init__(self, engine, data): -
branches/map_loading_change/game/scripts/gamemodel.py
r558 r559 19 19 import pickle 20 20 import sys 21 import os.path 21 22 from gamestate import GameState 22 23 from objects import createObject 23 from map importMap24 from gamemap import GameMap 24 25 from fife import fife 26 from common.utils import locateFiles 27 try: 28 import xml.etree.cElementTree as ElementTree 29 except ImportError: 30 import xml.etree.ElementTree as ElementTree 31 25 32 import yaml 26 33 … … 31 38 the fife view here. This also prevents us from just having a 32 39 function heavy controller.""" 33 def __init__(self, engine): 40 41 def __init__(self, engine, settings): 34 42 """Initialize the instance. 35 43 @param engine: A fife.Engine object 36 44 @type emgome: fife.Engine 45 @param setting: The applications settigns 46 @type setting: fife_settings.Setting 37 47 @return: None""" 38 # a World object (the fife stuff, essentially)39 48 self.map_change = False 40 49 self.load_saver = False … … 45 54 self.target_map_name = None 46 55 self.object_db = {} 47 # self.map is a Map object, set to none here48 56 self.active_map = None 49 57 self.maps = {} … … 51 59 self.agents = {} 52 60 self.agents["all"] = {} 53 self.engine = engine 61 self.engine = engine 54 62 self.maps_file = "maps/maps.yaml" 55 63 self.all_agents_file = "maps/all_agents.yaml" 64 self.object_db_file = "objects/ObjectDatabase.yaml" 65 self.agents_directory = "objects/" 66 self.agent_import_files = {} 67 self.settings = settings 56 68 57 69 def checkAttributes(self, attributes): … … 223 235 self.map_files = yaml.load(maps_data)["Maps"] 224 236 237 def addAgent(self, namespace, agent): 238 """Adds an agent to the agents dictionary 239 @param namespace: the namespace where the agent is to be added to 240 @type namespace: str 241 @param agent: The agent to be added 242 @type agent: dict 243 """ 244 from local_loaders.loaders import loadImportFile 245 if not self.agents.has_key(namespace): 246 self.agents[namespace] = {} 247 248 self.agents[namespace].update(agent) 249 ObjectModel = "" 250 agent_values = agent.values()[0] 251 if agent_values.has_key("ObjectModel"): 252 ObjectModel = agent_values["ObjectModel"] 253 else: 254 ObjectModel = self.object_db[agent_values["ObjectType"]]["gfx"] 255 import_file = self.agent_import_files[ObjectModel] 256 loadImportFile(import_file, self.engine) 257 225 258 def readAllAgents(self): 226 259 """Read the agents of the all_agents_file and store them""" … … 229 262 for agent in agents: 230 263 if not agent == None: 231 self.a gents["all"].update(agent)264 self.addAgent("all", agent) 232 265 233 266 def getAgentsOfMap(self, map_name): … … 241 274 ret_dict = self.agents[map_name] 242 275 for agent_name, agent_value in self.agents["all"].iteritems(): 243 if agent_value[" Map"] == map_name:276 if agent_value["GameMap"] == map_name: 244 277 ret_dict[agent_name] = agent_value 245 278 return ret_dict … … 263 296 map_file = self.map_files[map_name] 264 297 map_agents_file = map_file.replace(".xml", "_agents.yaml") 265 new_map = Map(self.engine, self)298 new_map = GameMap(self.engine, self) 266 299 self.maps[map_name] = new_map 267 new_map.load(self.map_files[map_name])268 300 #Get the agents of the map 269 self.agents[map_name] = {}270 301 agents_data = file(map_agents_file) 271 302 agents = yaml.load_all(agents_data) 272 303 for agent in agents: 273 304 if not agent == None: 274 self.agents[map_name].update(agent) 305 self.addAgent(map_name, agent) 306 new_map.load(self.map_files[map_name]) 275 307 else: 276 308 self.setActiveMap(map_name) … … 419 451 self.game_state.PlayerCharacter.teleport(position) 420 452 421 def readObjectDB(self , db_file):453 def readObjectDB(self): 422 454 """Reads the Object Information Database from a file. 423 @type db_file: String424 @param db_file: The file to load from425 455 """ 426 database_file = file( db_file, "r")456 database_file = file(self.object_db_file, "r") 427 457 database = yaml.load_all(database_file) 428 458 for object_info in database: 429 459 self.object_db.update(object_info) 460 461 def getAgentImportFiles(self): 462 """Searches the agents directory for import files 463 """ 464 files = locateFiles("*.xml", self.agents_directory) 465 for xml_file in files: 466 xml_file = os.path.relpath(xml_file).replace("\\", "/") 467 root = ElementTree.parse(xml_file).getroot() 468 if root.tag == "object": 469 self.agent_import_files[root.attrib["id"]] = xml_file -
branches/map_loading_change/game/scripts/gamescenecontroller.py
r556 r559 34 34 35 35 36 def __init__(self, engine, view, model, application , settings):36 def __init__(self, engine, view, model, application): 37 37 ''' 38 38 Constructor … … 52 52 model, 53 53 application, 54 settings,55 54 reg_mouse=True, 56 55 reg_keys=True) … … 60 59 self.mouse_callback = None 61 60 62 # don't force restart if skipping to new section 63 if settings.get("FIFE", "PlaySounds"): 61 if model.settings.get("FIFE", "PlaySounds"): 64 62 if not self.view.sounds.music_init: 65 63 music_file = random.choice(glob.glob(os.path.join( … … 78 76 } 79 77 self.view.hud = Hud(self.engine, 80 self. settings,78 self.model.settings, 81 79 self.model, 82 80 hud_callbacks) -
branches/map_loading_change/game/scripts/parpg.py
r558 r559 96 96 super(PARPGApplication, self).__init__(setting) 97 97 #self.engine.getModel(self) 98 self.model = gamemodel.GameModel(self.engine )98 self.model = gamemodel.GameModel(self.engine, setting) 99 99 self.model.maps_file = self._setting.get("PARPG", "MapsFile") 100 100 self.model.readMapFiles() 101 self.model.object_db_file = self._setting.get("PARPG", 102 "ObjectDatabaseFile") 103 self.model.readObjectDB() 104 self.model.agents_directory = self._setting.get("PARPG", 105 "AgentsDirectory") 106 self.model.getAgentImportFiles() 101 107 self.model.all_agents_file = self._setting.get("PARPG", "AllAgentsFile") 102 108 self.model.readAllAgents() … … 105 111 self.view, 106 112 self.model, 107 self, 108 setting) 109 self.model.readObjectDB(self._setting.get("PARPG", 110 "ObjectDatabaseFile")) 113 self) 111 114 self.controller.initHud() 112 115 self.listener = ApplicationListener(self.engine, -
branches/map_loading_change/game/settings-dist.xml
r558 r559 1 <?xml version='1.0' encoding='UTF-8'?> 2 <Settings> 3 <Module name="FIFE"> 1 <?xml version='1.0' encoding='UTF-8'?><!DOCTYPE Settings PUBLIC "FIFE.SettingsFile" "Settings.dtd"> 2 <Settings>"E:/projekte/FIFE/engine/python/fife/extensions/fife_settings.py" 3 <Module name="FIFE"> 4 4 <Setting name="FullScreen" type="bool">False</Setting> 5 5 <Setting name="PlaySounds" type="bool">True</Setting> … … 26 26 <Setting name="ObjectDatabaseFile" type="str">objects/ObjectDatabase.yaml</Setting> 27 27 <Setting name="MapsFile" type = "str">maps/maps.yaml</Setting> 28 <Setting name="AllAgentsFile" type = "str">maps/all_agents.yaml</Setting> 28 <Setting name="AllAgentsFile" type = "str">maps/all_agents.yaml</Setting> 29 <Setting name="AgentsDirectory" type="str">objects/</Setting> 29 30 <Setting name="PCSpeed" type="int">3</Setting> 30 31 </Module>
Note: See TracChangeset
for help on using the changeset viewer.