inventory

package
v0.0.0-...-b9cfb1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2019 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
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

func NewInventory(size int) *Inventory

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

func (inventory *Inventory) AddItem(item *items.Stack) error

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

func (inventory *Inventory) ClearSlot(slot int) error

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

func (inventory *Inventory) Contains(searched *items.Stack) bool

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

func (inventory *Inventory) GetAll() []*items.Stack

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

func (inventory *Inventory) GetItem(slot int) (*items.Stack, error)

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

func (inventory *Inventory) IsEmpty(slot int) bool

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

func (inventory *Inventory) RemoveItem(searched *items.Stack) bool

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

func (inventory *Inventory) SetAll(items []*items.Stack)

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.

func (*Inventory) SetItem

func (inventory *Inventory) SetItem(stack *items.Stack, slot int) error

SetItem sets an item in a slot in an inventory. If the slot exceeds the max inventory size, a nil item gets returned with ExceedingSlot error, otherwise returns nil.

func (*Inventory) String

func (inventory *Inventory) String() string

String returns a string representation of an inventory. String implements the fmt.Stringer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL