Inventory

Inherits: object

Module: inventory

Brief Description

Represents a basic inventory for item management

Instance Methods

Inventory Inventory ( int size )
None load ( str path )
None save ( str path )
None sort ( str keyword=None )
None add ( Item item )
None set ( int slot, Item item )
None set_size ( int size )
int find ( Item item )
int find_first_item ( )
int find_first_empty ( )
Item get ( int slot )
int get_empty_count ( )
int get_items_count ( )
List get_items ( )
List get_items_with_kwargs ( str keyword, str args=None )
int get_size ( )
bool is_full ( )
bool is_empty ( )
Item remove ( Item item )
List remove_all ( )
Item remove_from ( int slot )

Instance Method Descriptions

  • Inventory Inventory ( int size )

Construct a new inventory of the passed in size.

  • None load ( str path )

Loads an inventory from the passed in filepath.

  • None save ( str path )

Saves the current inventory to the passed in filepath

  • None sort ( str keyword=None )

Moves the items with the keyword to the start of the inventory sorting them by keyword in either alphabetical order or numerical order (If only contains numbers). If keyword is not passed in then it just moves all of the items to the start of the inventory.

  • None add ( Item item )

Add the passed in item instance to the inventory at the next empty slot. If no slot is empty then it will raise an OverflowError. Use is_full before adding an item without slot specified to ensure that no error is thrown.

  • None set ( int slot, Item item )

Add the item to the specific inventory slot, The new item will replace the current item if one exists.

  • None set_size ( int size )

Sets the number of items that the inventory can hold. This will cut off any items that are past the current size, or add empty slots to extend the size.

  • Item get ( int slot )

Return the item instance at the inventory slot index.

  • int get_empty_count ( )

Returns the number of empty slots in the inventory.

  • int get_items_count ( Item item )

Returns the number of items if item is None. If item is specified then returns the number of instances of that item in the inventory.

  • List get_items ( )

Returns a List of items in the inventory. Alternative to Item().items_list that will also return empty items.

  • List get_items_with_kwargs ( str keyword, str arg=None )

Returns a list of inventory items with the specific keyword argument. If arg is not None then it will return only the items that have the keyword argument and the arguments value is args

  • List get_size ( )

Returns the the amount of items the inventory can hold

  • int find ( Item item )

Returns the first slot index of the item if it exists in the inventory. If no Item is found returns -1.

  • int find_first_item ( )

Returns the slot index of the first item in the inventory if the inventory is not empty. If the inventory is empty returns -1.

  • int find_first_empty ( )

Returns the slot index of the first empty slot in the inventory. If the inventory is full returns -1.

  • bool is_full ( )

Returns True if the inventory has no empty slots. Otherwise returns False.

  • bool is_empty ( )

Returns True if the inventory does not contain any items. If the inventory contains one or more items, returns False

Remove and return the first instance of the item. If the item is not found it will raise a SlotEmptyError.

  • List remove_all ( )

Removes all Items and returns them as a List.

  • Item remove_from ( int slot )

Remove and return the item from the inventory slot index. If the slot index is empty it raises a SlotEmptyError.

Supported Magic Methods

  • None __iter__ ( )

Iterates through the inventory items.

  • bool __contains__ ( )

Returns true if the item is in the inventory.

  • Item __getitem__ ( )

Calls get on the item.

  • int __len__ ( )

Returns items_count

Returns this inventory with the second inventory concatenated to the end.

  • bool __eq__ ( )

Returns True if this inventory has the same items and length as other inventory. Otherwise returns False.

  • bool __lt__ ( )

Returns True if this inventory has less items than the other inventory. Otherwise returns False.

  • bool __le__ ( )

Returns True if this inventory has less or equal number of items than the other inventory. Otherwise returns False

  • str __str__ ( )

Returns this inventory as a string.