Ignore:
Timestamp:
07/09/09 23:19:35 (11 years ago)
Author:
tZee_parpg
Message:
  • changed objectLoader to do only what it is supposed to do
  • thus the engine can now add FIFE related references in an intermediate step to the object creation
  • which happens in the factory method, which is now located in scripts/objects/init
  • disregard the save/load mess for now
  • deleted some obsolete stuff
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/scripts/objectLoader.py

    r187 r198  
    1818from xml.sax import make_parser 
    1919from xml.sax.handler import ContentHandler 
    20 from objects import getAllObjects 
    21 from objects.containers import * 
    2220import sys 
    2321 
     
    3230        # parser is created when getObjects is called. 
    3331        self.parser = None 
    34         # an agent layer, which is set to something in getObjects and is set 
    35         # to None at the end of getObjects to ensure that it is always current. 
    36         self.agent_layer = None 
    3732     
    38     def getObjects(self, file_desc, a_layer): 
    39         """Gets the objects from the file. Populates local_info. This function 
    40            is how the scripts.Engine object interacts with the objectLoader. 
    41            So, this function takes the current agent_layer from the engine and 
    42            sets self.agent_layer so that it can be used in startElement. 
     33    def getObjects(self, file_desc): 
     34        """Reads the object data into dictionaries out of which 
     35        the game objects can be constructed. 
    4336           @type file_desc: File 
    4437           @param file_desc: an open file from which we read 
     
    4639        parser = make_parser() 
    4740        parser.setContentHandler(self) 
    48         self.agent_layer = a_layer 
    4941        parser.parse(file_desc) 
    5042        self.agent_layer = None 
     
    6052        # For now, only looking for game_obj things 
    6153        if str(name) == "object": 
    62             obj_info = dict(attrs.items()) 
     54            obj_info = {} 
    6355            # we need to convert all the unicode strings to ascii strings 
    6456            for key, val in attrs.items(): 
    65                 obj_info.pop(key) 
    6657                obj_info[str(key)] = str(val) 
    67             self.local_info.append(self.createObject(obj_info)) 
    68   
    69     def createObject(self, info): 
    70         """Called when we need to get an actual object.  
    71            @type info: dict 
    72            @param info: stores information about the object we want to create 
    73            @return: the object""" 
    74         # First, we try to get the type and ID, which every game_obj needs. 
    75         try: 
    76             obj_type = info.pop('type') 
    77             ID = info.pop('id') 
    78         except KeyError: 
    79             sys.stderr.write("Error: Game object missing type or id.") 
    80             sys.exit(False) 
    81          
    82         # add the agent_layer to the object dictionary in case it is needed by 
    83         # the object we are constructing. If it is not needed, it will be  
    84         # ignored 
    85         info['agent_layer'] = self.agent_layer 
    86  
    87         all_types = getAllObjects() 
    88         return all_types[obj_type](ID, **info) 
     58            self.local_info.append(obj_info) 
Note: See TracChangeset for help on using the changeset viewer.