Changeset 537


Ignore:
Timestamp:
04/14/10 20:52:53 (9 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]

Location:
trunk/game
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/run.py

    r475 r537  
    9696        """Initialise the instance. 
    9797           @return: None""" 
    98         super(PARPG,self).__init__() 
     98        super(PARPG, self).__init__() 
    9999        self.world = world.World(self.engine) 
    100100        self.model = engine.Engine(self.world) 
     101        self.model.readObjectDB(str(TDS.readSetting("ObjectDatabaseFile"))) 
    101102        self.world.data = self.model 
    102103        self.world.initHud() 
    103         self.listener = ApplicationListener(self.engine,self.world,self.model) 
     104        self.listener = ApplicationListener(self.engine, self.world, self.model) 
    104105        self.world.quitFunction = self.listener.quitGame 
    105106        self.model.loadMap("main-map", str(TDS.readSetting("MapFile"))) 
  • 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) 
  • trunk/game/settings-dist.xml

    r520 r537  
    1212        <WindowIcon>gui/icons/window_icon.png</WindowIcon> 
    1313        <MapFile> maps/map.xml </MapFile> 
     14        <ObjectDatabaseFile>objects/ObjectDatabase.yaml</ObjectDatabaseFile> 
    1415        <Font> fonts/samanata.ttf </Font> 
    1516        <FontGlyphs> abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&amp;`'*#=[]\"</FontGlyphs> 
Note: See TracChangeset for help on using the changeset viewer.