Mercurial > parpg-source
changeset 131:d1c2d316cc25
Fixed contents of containers, that are contained in other containers, not correctly restoring.
author | KarstenBock@gmx.net |
---|---|
date | Fri, 07 Oct 2011 18:15:09 +0200 |
parents | aea5a9229b4c |
children | e2ccd64f3a86 |
files | gamemodel.py gui/hud.py |
diffstat | 2 files changed, 37 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/gamemodel.py Fri Oct 07 15:37:44 2011 +0200 +++ b/gamemodel.py Fri Oct 07 18:15:09 2011 +0200 @@ -424,35 +424,7 @@ if agent.has_key("Inventory"): inv = agent["Inventory"] - slots = inv["Slots"] - obj.container.children = list() - for x in xrange(slots): - obj.container.children.append(None) - items = inv["Items"] if inv.has_key("Items") else list() - for data in items: - item = None - slot = data["Slot"] if data.has_key("Slot") else -1 - if data.has_key("type"): - item_type = data["type"] - item_data = {} - item_data = self.checkAttributes(item_data, item_type) - if item_data.has_key("containable"): - item = self.create_item( - self.createUniqueID(data["ID"]), - item_data, world, item_type) - else: - raise Exception("Item %s is not containable." % item_type) - else: - identifier = data["ID"] - if self.game_state.hasObject(identifier): - item = self.game_state.getObjectById(identifier) - else: - item_data = self.items[identifier]["Entity"] - item_type = item_data["containable"]["item_type"] - item = self.create_item(identifier, item_data, - world, item_type) - - container.put_item(obj.container, item.containable, slot) + self.create_inventory_items(inv, obj, world) if agent.has_key("Equipment"): for slot, data in agent["Equipment"].iteritems(): @@ -481,6 +453,41 @@ obj.fifeagent.behaviour.animate("opened", repeating=True) return obj + def create_inventory_items(self, inv, obj, world): + slots = inv["Slots"] + obj.container.children = list() + for x in xrange(slots): + obj.container.children.append(None) + items = inv["Items"] if inv.has_key("Items") else list() + for data in items: + item = None + slot = data["Slot"] if data.has_key("Slot") else -1 + if data.has_key("type"): + item_type = data["type"] + item_data = {} + item_data = self.checkAttributes(item_data, item_type) + if item_data.has_key("containable"): + item = self.create_item( + self.createUniqueID(data["ID"]), + item_data, world, item_type) + else: + raise Exception("Item %s is not containable." % item_type) + else: + identifier = data["ID"] + if self.game_state.hasObject(identifier): + item = self.game_state.getObjectById(identifier) + else: + agent_data = self.items[identifier] + item_data = agent_data["Entity"] + item_type = item_data["containable"]["item_type"] + item = self.create_item(identifier, item_data, + world, item_type) + if item.container and agent_data.has_key("Inventory"): + self.create_inventory_items(agent_data["Inventory"], + item, world) + + container.put_item(obj.container, item.containable, slot) + def create_item(self, identifier, item_data, world, item_type): if not item_data["description"].has_key("view_name"): item_data["description"]["view_name"] = (
--- a/gui/hud.py Fri Oct 07 15:37:44 2011 +0200 +++ b/gui/hud.py Fri Oct 07 18:15:09 2011 +0200 @@ -29,6 +29,7 @@ from parpg.gui.inventorygui import CharacterGUI from actionsbox import ActionsBox from parpg.objects.action import DropItemAction +from parpg.components import container logger = logging.getLogger('hud') class Hud(object):