[−][src]Struct game_features::Inventory
Fields
content: Vec<Option<ItemInstance<K, U>>>
The contents of the Inventory
.
None values indicate empty but existing inventory slots.
slot_restriction: Vec<Option<S>>
Restricts what kind of item can go in different slots.
This is not compatible with InventorySizingMode::Dynamic
.
Maps to the inventory content using the index. None values indicate that there are no restrictions for that slot.
move_to_front: MoveToFrontMode
Configures how item deletion is handled.
sizing_mode: InventorySizingMode
Configures if the inventory resizes when item are inserted/removed or not.
Methods
impl<K, T, S: SlotType<T>, U: Default> Inventory<K, T, S, U>
[src]
pub fn new(
content: Vec<Option<ItemInstance<K, U>>>,
slot_restriction: Vec<Option<S>>,
move_to_front: MoveToFrontMode,
sizing_mode: InventorySizingMode
) -> Self
[src]
content: Vec<Option<ItemInstance<K, U>>>,
slot_restriction: Vec<Option<S>>,
move_to_front: MoveToFrontMode,
sizing_mode: InventorySizingMode
) -> Self
Constructs a new Inventory
.
impl<K: PartialEq + Clone + Debug, T, S: SlotType<T>, U: Default + Clone + Debug> Inventory<K, T, S, U>
[src]
pub fn new_fixed(count: usize) -> Inventory<K, T, S, U>
[src]
Creates a new Inventory
with a fixed slot count.
pub fn new_dynamic(minimum: usize, maximum: usize) -> Inventory<K, T, S, U>
[src]
Creates a new dynamically sized Inventory
. A minimum of minimum
slots are garanteed to
be present at all time. The quantity of slots will not go over maximum
.
pub fn use_item(&mut self, idx: usize) -> Result<Option<usize>, ItemError<K, U>>
[src]
Will attempt to decrease the durability of the item at the specified index.
If the item has no durability value (None) or a non zero durability, it will return this
value.
If the item has a durability of 0 when using it, it will break and
ItemError::ItemDestroyed
will be returned.
pub fn consume(&mut self, idx: usize) -> Result<usize, ItemError<K, U>>
[src]
Decreases the stack size by one and returns the current value.
Once the stack size hits zero, it will return ItemError::StackConsumed
.
pub fn has_space(&self) -> bool
[src]
Looks if there is enough space to add another item stack.
pub fn transfer(
&mut self,
from_idx: usize,
target: &mut Inventory<K, T, S, U>,
to_idx: usize,
quantity: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
[src]
&mut self,
from_idx: usize,
target: &mut Inventory<K, T, S, U>,
to_idx: usize,
quantity: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
Transfers a specified quantity of item from one slot of this inventory to a specified slot of the provided target inventory. with_overflow indicates if the item can be spread out in free slots in case that the target slot does not have enough free space.
Errors:
See Transform::delete
and Transform::insert_into
.
pub fn transfer_stack(
&mut self,
from_idx: usize,
target: &mut Inventory<K, T, S, U>,
to_idx: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
[src]
&mut self,
from_idx: usize,
target: &mut Inventory<K, T, S, U>,
to_idx: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
Transfers a whole stack from the specified slot into a specified slot of the provided target directory. with_overflow indicates if the item can be spread out in free slots in case that the target slot does not have enough free space.
Errors:
See Transform::delete
and Transform::insert_into
.
pub fn move_item(
&mut self,
from_idx: usize,
to_idx: usize,
quantity: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
[src]
&mut self,
from_idx: usize,
to_idx: usize,
quantity: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
Moves a specified quantity of item from a slot to another. with_overflow indicates if the item can be spread out in free slots in case that the target slot does not have enough free space.
Errors:
See Inventory::delete
and Inventory::insert_into
.
pub fn move_stack(
&mut self,
from_idx: usize,
to_idx: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
[src]
&mut self,
from_idx: usize,
to_idx: usize,
with_overflow: bool
) -> Result<(), ItemError<K, U>>
Moves a full stack of item from a slot to another. with_overflow indicates if the item can be spread out in free slots in case that the target slot does not have enough free space.
Errors:
- SlotEmpty: Nothing is present in the specified slot.
pub fn delete(
&mut self,
idx: usize,
quantity: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
[src]
&mut self,
idx: usize,
quantity: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
Deletes a specified quantity of item from the specified slot.
Errors:
- NotEnoughQuantity: Not enough items are present in the item stack.
- SlotEmpty: Nothing is present in the specified slot.
pub fn delete_stack(
&mut self,
idx: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
[src]
&mut self,
idx: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
Deletes a full stack of item at the provided index and returns it.
Errors:
See Transform::delete
.
pub fn delete_key(
&mut self,
key: &K,
quantity: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
[src]
&mut self,
key: &K,
quantity: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
Deletes items by matching the key until the deleted quantity reaches the specified quantity.
Errors:
- NotEnoughQuantity: Not enough items with the specified key are present in the inventory.
pub fn has_quantity(&self, key: &K, quantity: usize) -> bool
[src]
Checks if the total quantity of items of the specified key are present in the inventory.
pub fn has(&self, key: &K) -> bool
[src]
Checks if the inventory contains at least one ItemInstance
of the specified key.
pub fn get(&self, idx: usize) -> &Option<ItemInstance<K, U>>
[src]
Gets an immutable reference to the ItemInstance
at the specified index.
pub fn get_mut(&mut self, idx: usize) -> Option<&mut ItemInstance<K, U>>
[src]
Gets a mutable reference to the ItemInstance
at the specified index.
pub fn get_key(&self, key: &K) -> impl Iterator<Item = &ItemInstance<K, U>>
[src]
Finds the item instances using the specified key. Returns an iterator of immutable references.
pub fn get_key_mut(
&mut self,
key: &K
) -> impl Iterator<Item = &mut ItemInstance<K, U>>
[src]
&mut self,
key: &K
) -> impl Iterator<Item = &mut ItemInstance<K, U>>
Finds the item instances using the specified key. Returns an iterator of mutable references.
pub fn insert_into(
&mut self,
idx: usize,
item: ItemInstance<K, U>
) -> Result<(), ItemError<K, U>>
[src]
&mut self,
idx: usize,
item: ItemInstance<K, U>
) -> Result<(), ItemError<K, U>>
Inserts the ItemInstance
into the specified index.
It will eventually attempt to merge stacks together, but this is not implemented yet.
Errors:
- SlotOccupied: The slot is currently occupied by another item type.
pub fn insert(
&mut self,
item: ItemInstance<K, U>
) -> Result<(), ItemError<K, U>>
[src]
&mut self,
item: ItemInstance<K, U>
) -> Result<(), ItemError<K, U>>
Inserts the ItemInstance
at the first available inventory space.
If the inventory is dynamically size, it will attempt to create a slot and insert into it.
It will eventually attempt to merge stacks together, but this is not implemented yet.
Errors:
- InventoryFull: The inventory is full and no more space can be created.
pub fn first_empty_slot(&self) -> Option<usize>
[src]
Returns the first empty slot if any is available.
Trait Implementations
impl<K: Clone, T: Clone, S: Clone + SlotType<T>, U: Clone + Default> Clone for Inventory<K, T, S, U>
[src]
fn clone(&self) -> Inventory<K, T, S, U>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K: Debug, T: Debug, S: Debug + SlotType<T>, U: Debug + Default> Debug for Inventory<K, T, S, U>
[src]
impl<K, T, S: SlotType<T>, U: Default> Serialize for Inventory<K, T, S, U> where
K: Serialize,
S: Serialize,
U: Serialize,
[src]
K: Serialize,
S: Serialize,
U: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de, K, T, S: SlotType<T>, U: Default> Deserialize<'de> for Inventory<K, T, S, U> where
K: Deserialize<'de>,
S: Deserialize<'de>,
U: Deserialize<'de>,
[src]
K: Deserialize<'de>,
S: Deserialize<'de>,
U: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<K, T, S, U> Send for Inventory<K, T, S, U> where
K: Send,
S: Send,
T: Send,
U: Send,
K: Send,
S: Send,
T: Send,
U: Send,
impl<K, T, S, U> Sync for Inventory<K, T, S, U> where
K: Sync,
S: Sync,
T: Sync,
U: Sync,
K: Sync,
S: Sync,
T: Sync,
U: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,