Changeset 559


Ignore:
Timestamp:
06/22/10 17:37:37 (9 years ago)
Author:
beliar
Message:

Patch by Beliar.

  • Imports for the Agents are now loaded by using the information from the *_agents.yaml files. The Agents themselves are still loaded from the map file.
  • Removed the import-definition for the Agents from the map files.
  • Renamed Map to GameMap? to avoid confusion with the built-in map
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  
    2626from traceback import print_exc 
    2727 
    28 __all__ = ('ET', 'SerializerError', 'InvalidFormat', 'WrongFileType', 
     28__all__ = ('ElementTree', 'SerializerError', 'InvalidFormat', 'WrongFileType', 
    2929           'NameClash', 'NotFound', 'displayWarning', 'getRootSubfile', 
    3030           'reverseRootSubfile') 
    3131 
    3232try: 
    33     import xml.etree.cElementTree as ET 
     33    import xml.etree.cElementTree as ElementTree 
    3434except(ImportError): 
    35     import xml.etree.ElementTree as ET #@Reimport 
     35    import xml.etree.ElementTree as ElementTree #@Reimport 
    3636 
    3737class SerializerError(Exception): 
  • branches/map_loading_change/game/local_loaders/xmlmap.py

    r553 r559  
    2323from fife import fife  
    2424try: 
    25     import xml.etree.cElementTree as ET  
     25    import xml.etree.cElementTree as ElementTree  
    2626except ImportError: 
    27     import xml.etree.ElementTree as ET 
     27    import xml.etree.ElementTree as ElementTree 
    2828 
    2929from fife.extensions import loaders 
     
    131131        f = self.vfs.open(self.source) 
    132132        f.thisown = 1 
    133         tree = ET.parse(f) 
     133        tree = ElementTree.parse(f) 
    134134        root = tree.getroot() 
    135135             
     
    183183        for item in map_elt.findall('import'): 
    184184            imp_file = item.get('file') 
     185            directory = item.get('dir') 
    185186            if imp_file: 
    186187                imp_file = reverseRootSubfile(self.source, imp_file) 
    187             directory = item.get('dir') 
    188188            if directory: 
    189189                directory = reverseRootSubfile(self.source, directory) 
     
    192192            if (directory,imp_file) in parsedImports: 
    193193                print "Duplicate import:" ,(directory,imp_file) 
    194                 continue 
     194                #TODO return 
    195195            parsedImports[(directory,imp_file)] = 1 
    196196 
  • branches/map_loading_change/game/maps/map.xml

    r556 r559  
    33        <import file="../objects/ground/snow/snow0/snow02.xml" /> 
    44        <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" /> 
    105        <import file="../objects/scenery/crate/crate.xml" /> 
    116        <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" /> 
    147        <import file="../objects/buildings/container_house/container_house01.xml" /> 
    158        <import file="../objects/buildings/container_house/container_house02.xml" /> 
    169        <import file="../objects/ground/block/block.xml" /> 
    1710        <import file="../objects/scenery/burning_barrel/burning_barrel.xml" /> 
    18         <import file="../objects/scenery/lock_box_metal/lock_box_metal.xml" /> 
    1911        <import file="../objects/buildings/gate/pillar1/p1_s0.xml" /> 
    2012        <import file="../objects/buildings/gate/pillar1/p1_s1.xml" /> 
  • branches/map_loading_change/game/maps/map2.xml

    r556 r559  
    22<map format="1.0" id="Farm"> 
    33        <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" /> 
    74        <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"> 
    85                <instances> 
  • branches/map_loading_change/game/maps/map2_agents.yaml

    r555 r559  
    1919    ObjectType: "ShantyDoor" 
    2020    Position: [-2.0, 6.0, 0.0] 
    21     TargetMap: "main-map" 
     21    TargetMap: "Mall" 
    2222    TargetPosition: [5.0, 5.0] 
  • branches/map_loading_change/game/maps/map_agents.yaml

    r555 r559  
    2626    ObjectType: "ShantyDoor" 
    2727    Position: [-6.0, -13.0, 0.0] 
    28     TargetMap: "map2" 
     28    TargetMap: "Farm" 
    2929    TargetPosition: [10.0, 10.0] 
    3030--- 
  • branches/map_loading_change/game/run.py

    r553 r559  
    1515 
    1616import os 
    17  
    1817from scripts.common import utils 
    1918 
  • branches/map_loading_change/game/scripts/common/utils.py

    r530 r559  
    1414# Miscellaneous game functions 
    1515 
    16 import os, sys 
    17  
    18 # TODO: Having a file like this just looks cheap and 'hackish'. Fix if possible 
     16import os, sys, fnmatch 
    1917 
    2018def addPaths (*paths): 
     
    3634        return value.lower()[0] == "t" 
    3735    return False 
     36 
     37def 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  
    2424                 model,  
    2525                 application,  
    26                  settings,  
    2726                 reg_mouse = True,  
    2827                 reg_keys = True): 
     
    4948         
    5049        self.application = application 
    51         self.settings = settings 
  • branches/map_loading_change/game/scripts/gamemap.py

    r557 r559  
    2424              settings_gui_xml="") 
    2525 
    26 class Map(fife.MapChangeListener): 
     26class GameMap(fife.MapChangeListener): 
    2727    """Map class used to flag changes in the map""" 
    2828    def __init__(self, engine, data): 
  • branches/map_loading_change/game/scripts/gamemodel.py

    r558 r559  
    1919import pickle 
    2020import sys 
     21import os.path 
    2122from gamestate import GameState 
    2223from objects import createObject 
    23 from map import Map 
     24from gamemap import GameMap 
    2425from fife import fife 
     26from common.utils import locateFiles 
     27try: 
     28    import xml.etree.cElementTree as ElementTree 
     29except ImportError: 
     30    import xml.etree.ElementTree as ElementTree 
     31 
    2532import yaml 
    2633 
     
    3138       the fife view here. This also prevents us from just having a 
    3239       function heavy controller.""" 
    33     def __init__(self, engine): 
     40        
     41    def __init__(self, engine, settings): 
    3442        """Initialize the instance. 
    3543        @param engine: A fife.Engine object 
    3644        @type emgome: fife.Engine  
     45        @param setting: The applications settigns 
     46        @type setting: fife_settings.Setting  
    3747        @return: None""" 
    38         # a World object (the fife stuff, essentially) 
    3948        self.map_change = False 
    4049        self.load_saver = False 
     
    4554        self.target_map_name = None 
    4655        self.object_db = {} 
    47         # self.map is a Map object, set to none here 
    4856        self.active_map = None 
    4957        self.maps = {} 
     
    5159        self.agents = {} 
    5260        self.agents["all"] = {} 
    53         self.engine = engine       
     61        self.engine = engine 
    5462        self.maps_file = "maps/maps.yaml" 
    5563        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 
    5668 
    5769    def checkAttributes(self, attributes): 
     
    223235        self.map_files = yaml.load(maps_data)["Maps"] 
    224236     
     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         
    225258    def readAllAgents(self): 
    226259        """Read the agents of the all_agents_file and store them""" 
     
    229262        for agent in agents: 
    230263            if not agent == None: 
    231                 self.agents["all"].update(agent)   
     264                self.addAgent("all", agent)   
    232265                 
    233266    def getAgentsOfMap(self, map_name): 
     
    241274        ret_dict = self.agents[map_name] 
    242275        for agent_name, agent_value in self.agents["all"].iteritems(): 
    243             if agent_value["Map"] == map_name: 
     276            if agent_value["GameMap"] == map_name: 
    244277                ret_dict[agent_name] = agent_value 
    245278        return ret_dict 
     
    263296            map_file = self.map_files[map_name] 
    264297            map_agents_file = map_file.replace(".xml", "_agents.yaml")    
    265             new_map = Map(self.engine, self) 
     298            new_map = GameMap(self.engine, self) 
    266299            self.maps[map_name] = new_map 
    267             new_map.load(self.map_files[map_name]) 
    268300            #Get the agents of the map 
    269             self.agents[map_name] = {} 
    270301            agents_data = file(map_agents_file) 
    271302            agents = yaml.load_all(agents_data) 
    272303            for agent in agents: 
    273304                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]) 
    275307        else: 
    276308            self.setActiveMap(map_name) 
     
    419451        self.game_state.PlayerCharacter.teleport(position) 
    420452 
    421     def readObjectDB(self, db_file): 
     453    def readObjectDB(self): 
    422454        """Reads the Object Information Database from a file. 
    423         @type db_file: String 
    424         @param db_file: The file to load from 
    425455        """ 
    426         database_file = file(db_file, "r") 
     456        database_file = file(self.object_db_file, "r") 
    427457        database = yaml.load_all(database_file) 
    428458        for object_info in database: 
    429459            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  
    3434 
    3535 
    36     def __init__(self, engine, view, model, application, settings): 
     36    def __init__(self, engine, view, model, application): 
    3737        ''' 
    3838        Constructor 
     
    5252                                                  model, 
    5353                                                  application, 
    54                                                   settings, 
    5554                                                  reg_mouse=True,  
    5655                                                  reg_keys=True) 
     
    6059        self.mouse_callback = None 
    6160 
    62         # don't force restart if skipping to new section 
    63         if settings.get("FIFE",  "PlaySounds"): 
     61        if model.settings.get("FIFE",  "PlaySounds"): 
    6462            if not self.view.sounds.music_init: 
    6563                music_file = random.choice(glob.glob(os.path.join( 
     
    7876        } 
    7977        self.view.hud = Hud(self.engine,  
    80                             self.settings,  
     78                            self.model.settings,  
    8179                            self.model,  
    8280                            hud_callbacks) 
  • branches/map_loading_change/game/scripts/parpg.py

    r558 r559  
    9696        super(PARPGApplication, self).__init__(setting) 
    9797        #self.engine.getModel(self) 
    98         self.model = gamemodel.GameModel(self.engine) 
     98        self.model = gamemodel.GameModel(self.engine, setting) 
    9999        self.model.maps_file = self._setting.get("PARPG", "MapsFile") 
    100100        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() 
    101107        self.model.all_agents_file = self._setting.get("PARPG", "AllAgentsFile") 
    102108        self.model.readAllAgents() 
     
    105111                                                        self.view,  
    106112                                                        self.model,  
    107                                                         self, 
    108                                                         setting) 
    109         self.model.readObjectDB(self._setting.get("PARPG",  
    110                                                   "ObjectDatabaseFile")) 
     113                                                        self) 
    111114        self.controller.initHud() 
    112115        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"> 
    44        <Setting name="FullScreen" type="bool">False</Setting> 
    55        <Setting name="PlaySounds" type="bool">True</Setting> 
     
    2626        <Setting name="ObjectDatabaseFile" type="str">objects/ObjectDatabase.yaml</Setting> 
    2727        <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> 
    2930        <Setting name="PCSpeed" type="int">3</Setting> 
    3031   </Module> 
Note: See TracChangeset for help on using the changeset viewer.