Ignore:
Timestamp:
04/14/10 20:52:53 (10 years ago)
Author:
beliar
Message:
  • Added support for an "Object Information Database"
  • Database is a .yaml file
  • Added setting for the database file
  • Database will be loaded when the engine is initiated
  • Database contains attribute values for objects that will overwrite the hard coded default values
  • These values can themselves be overwritten in the map file
  • The database file itself currently only contains 2 objects

references[t:185]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/engine.py

    r498 r537  
    2222from objects import * 
    2323from objects.action import * 
     24import yaml 
    2425 
    2526class Engine: 
     
    4445        self.target_map_name = None 
    4546        self.target_map_file = None 
     47        self.object_db = {} 
    4648 
    4749    def save(self, path, filename): 
     
    117119        extra['agent_layer'] = layer 
    118120        extra['engine'] = self 
     121        class_name = attributes["type"] 
     122        if self.object_db.has_key(class_name): 
     123            db_attributes = self.object_db[class_name].copy() 
     124            for key in db_attributes.keys(): 
     125                if not attributes.has_key(key) or attributes[key] == None: 
     126                    attributes[key] = db_attributes[key] 
    119127         
    120128        obj = createObject(attributes, extra) 
     
    278286    def changeMap(self, map_name, map_file, target_position): 
    279287        """Registers for a map change on the next pump(). 
    280            @type name_name: String 
     288           @type map_name: String 
    281289           @param map_name: Id of the map to teleport to 
    282290           @type map_file: String 
     
    309317        """Main loop in the engine.""" 
    310318        self.handleCommands() 
     319         
     320    def readObjectDB(self, db_file): 
     321        """Reads the Object Information Database from a file. 
     322        @type db_file: String 
     323        @param db_file: The file to load from 
     324        """ 
     325        database_file = file(db_file, "r") 
     326        database = yaml.load_all(database_file) 
     327        for object_info in database: 
     328            self.object_db.update(object_info) 
Note: See TracChangeset for help on using the changeset viewer.