Ignore:
Timestamp:
05/07/10 20:14:52 (9 years ago)
Author:
beliar
Message:

Inventories can now be set in the map file
Items values read from the object database (objects/ObjectDatabase.yaml)
Again, values set in the map override those in the database.
Sample inventory for PC added to map.xml (same as that in init of PlayerCharacter?)

For now only the CarryableItem? type is supported. Once we decide how to implement items that do more than just sit in the inventory we need to change it.

File:
1 edited

Legend:

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

    r538 r540  
    105105        # In most maps we'll create the PC Instance internally. In these 
    106106        # cases we need a target position 
    107              
    108     def createObject (self, layer, attributes, instance): 
     107         
     108 
     109    def checkAttributes(self, attributes): 
     110        """Checks for attributes that where not given in the map file 
     111        and fills them with values from the object database 
     112        @param attributes: attributes to check 
     113        @type attributes: Dictionary 
     114        @return: The modified attributes"""         
     115        if attributes.has_key("object_type"): 
     116            class_name = attributes.pop("object_type") 
     117        else: 
     118            class_name = attributes["type"] 
     119        if self.object_db.has_key(class_name): 
     120            db_attributes = self.object_db[class_name].copy() 
     121            for key in db_attributes.keys(): 
     122                if attributes.has_key(key): 
     123                    attributes[key] = attributes[key] or db_attributes[key] 
     124                else: 
     125                    attributes[key] = db_attributes[key] 
     126        return attributes 
     127     
     128    def createInventoryObject(self, container, attributes): 
     129        """Create an inventory object and place it into a container 
     130           @type container: base.Container 
     131           @param container: Container where the item is on 
     132           @type attributes: Dictionary 
     133           @param attributes: Dictionary of all object attributes 
     134           @return: None""" 
     135        # create the extra data 
     136        extra = {} 
     137        extra['engine'] = self 
     138        attributes = self.checkAttributes(attributes) 
     139         
     140        """TODO: Change when we use other and or more classes  
     141        for inventory objects""" 
     142        from objects.composed import CarryableItem 
     143        info = {} 
     144        info.update(attributes) 
     145        info.update(extra) 
     146        ID = info.pop("id") 
     147         
     148        obj = CarryableItem(ID = ID, **info) 
     149        #obj = createObject(attributes, extra) 
     150        container.placeItem(obj) 
     151         
     152    def createMapObject (self, layer, attributes, instance): 
    109153        """Create an object and add it to the current map. 
    110154           @type layer: fife.Layer 
     
    117161        # create the extra data 
    118162        extra = {} 
    119         extra['agent_layer'] = layer 
     163        if layer is not None: 
     164            extra['agent_layer'] = layer 
    120165        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                 attributes[key] = attributes[key] or db_attributes[key] 
     166        attributes = self.checkAttributes(attributes) 
    126167         
    127168        obj = createObject(attributes, extra) 
Note: See TracChangeset for help on using the changeset viewer.