# inventory file
# holds inventory info, inventory methods

class Inventory(object):
    def __init__(self):
        # we create a dictionary, where object data makes a key and the value is the count
        # each data object is a dictionary of the objects attributes, so an object is uniquely defined
        # by its attributes
        
        #im just gonna go with a list of instantiated items.
        
        self.items = {}

        
    def add_new(self, object):
        """ adds an item to the inventory
        """
        self.items[object.sim_type] = [object]

    def add(self, object, count = 1):
        """ adds an item to the inventory
        """
        type_set = self.items.keys()

        if object.sim_type in type_set:
            if object.stackable:
                self.items[object.sim_type][0].stack_count += count
            else:
                self.items[object.sim_type].append(object)
        else:
            self.items[object.sim_type] = []
            if object.stackable:
                new_item = object.world.add_sim(object.sim_type, object.location)
                new_item.stack_count = count
                self.items[object.sim_type].append(new_item)
                #self.items[object.sim_type][0].stack_count = count
            else:
                for i in xrange(0,count):
                    #this is wrong since I guess I want n different instances of object
                    #but who cares for now
                    self.items[object.sim_type].append(object)
        #print self.items
            
    def rem(self, object, count = 1):
        """ removes an item from the inventory
        """
        type_set = self.items.keys()
        
        if object.sim_type in type_set:
            if object.stackable:
                self.items[object.sim_type][0].stack_count -= count
            else:
                self.items[object.sim_type].remove(object)
    
    def item_data(self, object):
        """ returns a dict of item data
        """
        pass
    
    def list_types(self):
        return self.items.keys()
    
    def list_items(self, item_type = None):
        if item_type:
            return self.items[item_type]
        else:
            list = []
            for type in self.list_types():
                for item in self.items[type]:
                    list.append(item)
            return list
