Ignore:
Timestamp:
07/31/10 20:00:28 (9 years ago)
Author:
beliar
Message:

Patch by Beliar.

  • Added "Open" action to InventoryItems?. This will open a ContainerGui? for now. Should make a gui that can reflect the actual possible size of the container.
  • Split OpenBoxAction? into a generic OpenAction?, for Containers that are not "openable" and a OpenBoxAction? for all Containers that are "openable" (The latter ones have an "open" method)
  • Moved SingleItemContainer? from composed to base and made it derive from the normal Container class.
  • Added a SingleItemCarryableContainer? class
  • MapItems? in the agent files can now have an attributes item.
  • Added container attribute to possible MapItem? attributes
  • MapItems? that have the "Container" attribute will have the "Open" action automatically added on creation.
  • Inventory now uses Container from base instead of CarryableContainer? from composed
  • Gave "Pot" the "Container" attribute
  • Added ItemSelf? exception to Container which will be raised when trying to place a container in itself.
  • ContainerGui? and InventoryGui? now catch exceptions from the Container
  • Removed debug print statements left over in inventory_gui
File:
1 edited

Legend:

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

    r609 r610  
    1919import sys 
    2020import os.path 
     21from copy import deepcopy 
     22 
     23from fife import fife 
     24 
    2125from gamestate import GameState 
    2226from objects import createObject 
    23 from objects.composed import CarryableItem 
     27from objects.composed import CarryableItem, CarryableContainer 
    2428from gamemap import GameMap 
    25 from fife import fife 
    2629from common.utils import locateFiles 
    2730from common.utils import parseBool 
    2831from inventory import Inventory 
    29 from copy import deepcopy 
    3032 
    3133try: 
     
    119121        return ID 
    120122 
     123    def createContainerItems(self, container_objs): 
     124        """Create the items of a container from a dictionary 
     125        @param container_objs: Dictionary containing the items 
     126        @type container_objs: dict""" 
     127        items = [] 
     128        for container_obj in container_objs: 
     129            items.append(self.createContainerObject(container_obj)) 
     130         
     131        return items 
     132 
    121133    def createContainerObject(self, attributes): 
    122134        """Create an object that can be stored in  
     
    137149            info["item_type"] = info["type"] 
    138150        ID = self.createUniqueID(ID) 
    139         new_item = CarryableItem(ID = ID, **info)  
     151        if info.has_key("attributes"): 
     152            attributes = info["attributes"] 
     153            if "Container" in attributes: 
     154                info["actions"]["Open"] = "" 
     155                if info.has_key("Items"): 
     156                    inventory_objs = info["Items"] 
     157                    info["items"] = self.createContainerItems(inventory_objs) 
     158                 
     159                new_item = CarryableContainer(ID = ID, **info)  
     160        else: 
     161            new_item = CarryableItem(ID = ID, **info)  
    140162        self.game_state.addObject(None, new_item) 
    141163        return new_item 
     
    399421            new_map = GameMap(self.engine, self) 
    400422            self.game_state.maps[map_name] = new_map 
    401             new_map.load(map_file) 
    402      
     423            new_map.load(map_file)     
     424 
    403425    def createAgent(self, agent, inst_id): 
    404426        object_type = agent["ObjectType"] 
     
    489511 
    490512        if agent.has_key("Items"): 
    491             items = [] 
    492             inventory_objs = agent["Items"] 
    493             for inventory_obj in inventory_objs: 
    494                 items.append(self.createContainerObject(inventory_obj)) 
     513            container_objs = agent["Items"] 
     514            items = self.createContainerItems(container_objs) 
    495515            inst_dict["items"] = items 
    496516             
Note: See TracChangeset for help on using the changeset viewer.