Changeset 540 for trunk/game/scripts/engine.py
- Timestamp:
- 05/07/10 20:14:52 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/game/scripts/engine.py
r538 r540 105 105 # In most maps we'll create the PC Instance internally. In these 106 106 # 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): 109 153 """Create an object and add it to the current map. 110 154 @type layer: fife.Layer … … 117 161 # create the extra data 118 162 extra = {} 119 extra['agent_layer'] = layer 163 if layer is not None: 164 extra['agent_layer'] = layer 120 165 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) 126 167 127 168 obj = createObject(attributes, extra)
Note: See TracChangeset
for help on using the changeset viewer.