Documentation ¶
Index ¶
- Variables
- type Inventory
- func (inventory *Inventory) AddItem(item *items.Stack) error
- func (inventory *Inventory) ClearSlot(slot int) error
- func (inventory *Inventory) Contains(searched *items.Stack) bool
- func (inventory *Inventory) GetAll() []*items.Stack
- func (inventory *Inventory) GetItem(slot int) (*items.Stack, error)
- func (inventory *Inventory) IsEmpty(slot int) bool
- func (inventory *Inventory) RemoveItem(searched *items.Stack) bool
- func (inventory *Inventory) SetAll(items []*items.Stack)
- func (inventory *Inventory) SetItem(stack *items.Stack, slot int) error
- func (inventory *Inventory) String() string
Constants ¶
This section is empty.
Variables ¶
var EmptySlot = errors.New("slot given contains no item")
EmptySlot gets returned in GetItem when a slot gets given and no item is available in that slot.
var ExceedingSlot = errors.New("slot given exceeds the inventory")
ExceedingSlot gets returned when an slot gets given that exceeds the inventory size. This may be for GetItem, or SetItem as example.
var FullInventory = errors.New("inventory has no space for item")
FullInventory gets returned in AddItem when the inventory does not have enough space for the item.
Functions ¶
This section is empty.
Types ¶
type Inventory ¶
type Inventory struct {
// contains filtered or unexported fields
}
Inventory is a container of item stacks. Every inventory has a fixed amount of max slots, and the item stack count will never exceed these slots.
func NewInventory ¶
NewInventory returns a new inventory with size. An item slice gets made with the size, which's length will never grow or shrink.
func (*Inventory) AddItem ¶
AddItem adds an item to the inventory. FullInventory gets returned if there was not sufficient space to fit the item. Items are first attempted to be stacked onto previously existed stacks, and once all pre-existing stacks are filled new stacks are created.
func (*Inventory) ClearSlot ¶
ClearSlot clears a given slot in the inventory. ClearSlot returns ExceedingSlot if the slot exceeds the inventory size, and EmptySlot if the slot was already empty before clearing.
func (*Inventory) Contains ¶
Contains checks if the inventory contains an item. This function checks through the whole inventory, to try and find out the total count of items with the same type of the item stack. The checked item stack may therefore be split out over multiple stacks in the inventory.
func (*Inventory) GetAll ¶
GetAll returns a copied slice of all item stacks, that are currently contained within the inventory. Operating on this slice will not operate directly on the content of this inventory.
func (*Inventory) GetItem ¶
GetItem returns an item in a slot in an inventory. If the slot exceeds the max inventory size, a nil item gets returned with ExceedingSlot error. If there is no item available at that slot, a nil item gets returned with EmptySlot. If the item was retrieved successfully, the item gets returned with no error.
func (*Inventory) IsEmpty ¶
IsEmpty checks if a slot in the inventory is empty. True gets returned if no item was in the slot. True is also returned when the slot exceeds the maximum size of the inventory.
func (*Inventory) RemoveItem ¶
RemoveItem removes an item from an inventory. A given item gets searched in the inventory, removing every equal stack until the count of the given stack has been exhausted. Items may be removed from multiple stacks. A bool gets returned to indicate if the complete stack got removed from the inventory.
func (*Inventory) SetAll ¶
SetAll sets all items in the inventory. This function merely copies the items from slice to slice, and does not implement any other behaviour. Use SetItem where possible.