diff gamemodel.py @ 78:a57ec730e753

Fixed item_type not being set when creating items.
author KarstenBock@gmx.net
date Fri, 23 Sep 2011 13:30:41 +0200
parents 4cf150131139
children 43e7a8d94446
line wrap: on
line diff
--- a/gamemodel.py	Fri Sep 23 13:30:17 2011 +0200
+++ b/gamemodel.py	Fri Sep 23 13:30:41 2011 +0200
@@ -444,25 +444,31 @@
                 obj.container.children.append(None)
             items = inv["Items"] if inv.has_key("Items") else list()
             for data in items:
+                item_type = data["type"]
                 item_data = {}
-                item_data = self.checkAttributes(item_data, data["type"])
+                item_data = self.checkAttributes(item_data, item_type)
                 if item_data.has_key("containable"):
-                    item = createEntity(item_data, world, None)
-                    self.game_state.addObject(self.createUniqueID(data["ID"]), None, item)
+                    item = self.create_item(item_data, world, item_type, data)
                     container.put_item(obj.container, item.containable)
                 else:
-                    raise Exception("Item %s is not containable." % data["type"])
+                    raise Exception("Item %s is not containable." % item_type)
 
         if agent.has_key("Equipment"):
             for slot, data in agent["Equipment"].iteritems():
+                item_type = data["type"]
                 item_data = {}
-                item_data = self.checkAttributes(item_data, data["type"])
+                item_data = self.checkAttributes(item_data, item_type)
                 if item_data.has_key("containable") and item_data.has_key("equipable"):
-                    item = createEntity(item_data, world, None)
-                    self.game_state.addObject(self.createUniqueID(data["ID"]), None, item)
+                    item = self.create_item(item_data, world, item_type, data)
                     equip.equip(obj.equip, item.equipable, slot)
                 else:
-                    raise Exception("Item %s is not containable or equipable." % data["type"])
+                    raise Exception("Item %s is not containable or equipable." % item_type)
+
+    def create_item(self, item_data, world, item_type, data):
+        item = createEntity(item_data, world, None)
+        item.containable.item_type = item_type
+        self.game_state.addObject(self.createUniqueID(data["ID"]), None, item)
+        return item
 
     def placeAgents(self, world):
         """Places the current maps agents """