# HG changeset patch # User KarstenBock@gmx.net # Date 1316701087 -7200 # Node ID 9e03f7816061532ae855dca00281e22ee41d6e36 # Parent c9818290bbe7fcb0c1e94ebf89f8c10a18846d0d (Re)added setting of inventory and equipment in the object files. diff -r c9818290bbe7 -r 9e03f7816061 components/equip.py --- a/components/equip.py Thu Sep 22 14:39:00 2011 +0200 +++ b/components/equip.py Thu Sep 22 16:18:07 2011 +0200 @@ -54,7 +54,7 @@ raise AlreadyEquippedError if slot in equipable.possible_slots: try: - old_item = getattr(wearer, slot) + old_item = getattr(wearer, slot) if hasattr(wearer, slot) else None setattr(wearer, slot, equipable) equipable.in_slot = slot equipable.wearer = wearer diff -r c9818290bbe7 -r 9e03f7816061 components/equipable.py --- a/components/equipable.py Thu Sep 22 14:39:00 2011 +0200 +++ b/components/equipable.py Thu Sep 22 16:18:07 2011 +0200 @@ -19,4 +19,4 @@ """ def __init__(self): - Component.__init__(self, possible_slots=list, wearer=object, in_slot=str) \ No newline at end of file + Component.__init__(self, image=str, possible_slots=list, wearer=object, in_slot=str) \ No newline at end of file diff -r c9818290bbe7 -r 9e03f7816061 gamemodel.py --- a/gamemodel.py Thu Sep 22 14:39:00 2011 +0200 +++ b/gamemodel.py Thu Sep 22 16:18:07 2011 +0200 @@ -31,7 +31,7 @@ from parpg.dialogueparsers import YamlDialogueParser, DialogueFormatError from parpg.entities import createEntity from parpg import behaviours -from parpg.components import fifeagent +from parpg.components import fifeagent, container, equip try: import xml.etree.cElementTree as ElementTree @@ -133,65 +133,6 @@ ID = ID + "_" + str(id_number) return ID - - def createContainerItems(self, container_objs): - """Create the items of a container from a dictionary - @param container_objs: Dictionary containing the items - @type container_objs: dict""" - items = [] - for container_obj in container_objs: - items.append(self.createContainerObject(container_obj)) - - return items - - def createContainerObject(self, attributes): - """Create an object that can be stored in - an container and return it - @param attributes: Dictionary of all object attributes - @type attributes: Dictionary - @return: The created object """ - # create the extra data - extra = {} - extra['controller'] = self - - info = {} - info.update(attributes) - info.update(extra) - ID = info.pop("id") if info.has_key("id") else info.pop("ID") - if not info.has_key("item_type"): - info["item_type"] = info["type"] - ID = self.createUniqueID(ID) - if info.has_key("attributes"): - attributes = info["attributes"] - if "Container" in attributes: - info["actions"]["Open"] = "" - if info.has_key("Items"): - inventory_objs = info["Items"] - info["items"] = self.createContainerItems(inventory_objs) - - new_item = CarryableContainer(ID = ID, **info) - else: - new_item = CarryableItem(ID = ID, **info) - else: - new_item = CarryableItem(ID = ID, **info) - self.game_state.addObject(None, new_item) - return new_item - - def createInventoryObject(self, container, attributes): - """Create an inventory object and place it into a container - @type container: base.Container - @param container: Container where the item is on - @type attributes: Dictionary - @param attributes: Dictionary of all object attributes - @return: None""" - index = attributes.pop("index") if attributes.has_key("index") else None - slot = attributes.pop("slot") if attributes.has_key("slot") else None - obj = self.createContainerObject(attributes) - #obj = createObject(attributes, extra) - if slot: - container.moveItemToSlot(obj, slot) - else: - container.placeItem(obj, index) def deleteObject(self, object_id): """Removes an object from the game @@ -491,10 +432,42 @@ entity_data["fifeagent"]["behaviour"] = behaviours.Base() if self.dialogues.has_key(inst_id): entity_data["dialogue"] = {} - entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id] - - self.createMapObject(self.active_map.agent_layer, entity_data, world) - + entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id] + + obj = self.createMapObject(self.active_map.agent_layer, entity_data, world) + + 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_data = {} + item_data = self.checkAttributes(item_data, data["type"]) + if item_data.has_key("containable"): + item = createEntity(item_data, world, None) + self.game_state.addObject(self.createUniqueID(data["ID"]), None, item) + container.put_item(obj.container, item.containable) + else: + raise Exception("Item %s is not containable." % data["type"]) + + if agent.has_key("Equipment"): + for slot, data in agent["Equipment"].iteritems(): + item_data = {} + item_data = self.checkAttributes(item_data, data["type"]) + if item_data.has_key("containable") and item_data.has_key("equipable"): + if not item_data["equipable"].has_key("image"): + item_data["equipable"]["image"]=item_data["containable"]["image"] + if not item_data["containable"].has_key("image"): + item_data["containable"]["image"]=item_data["equipable"]["image"] + item = createEntity(item_data, world, None) + self.game_state.addObject(self.createUniqueID(data["ID"]), None, item) + equip.equip(obj.equip, item.equipable, slot) + else: + raise Exception("Item %s is not containable or equipable." % data["type"]) + def placeAgents(self, world): """Places the current maps agents """ if not self.active_map: @@ -565,7 +538,7 @@ @param attributes: Dictionary of all object attributes @type instance: fife.Instance @param instance: FIFE instance corresponding to the object - @return: None""" + @return: The created object""" # create the extra data extra = {} if layer is not None: @@ -574,7 +547,8 @@ obj = createEntity(attributes, world, extra) if obj: - self.addObject(layer, obj) + self.addObject(layer, obj) + return obj def addPC(self, layer, player_char): """Add the PlayerCharacter to the map @@ -606,7 +580,7 @@ self.game_state.current_map_name) if ref is None: # no, add it to the game state - self.game_state.addObject(self.game_state.current_map_name, obj) + self.game_state.addObject(obj.fifeagent.identifier, self.game_state.current_map_name, obj) else: # yes, use the current game state data obj.fifeagent.pos.X = ref.X diff -r c9818290bbe7 -r 9e03f7816061 gamestate.py --- a/gamestate.py Thu Sep 22 14:39:00 2011 +0200 +++ b/gamestate.py Thu Sep 22 16:18:07 2011 +0200 @@ -22,6 +22,7 @@ self.quest_engine = QuestEngine(quests_dir) self.quest_engine.readQuests() self.objects = {} + self.objects[None] = {} self.object_ids = {} self.current_map_name = None self.maps = {}