Struct game_features::Inventory [−][src]
pub struct Inventory<K, S: SlotType, U: Default> { pub content: Vec<Option<ItemInstance<K, U>>>, pub slot_restriction: Vec<Option<S>>, pub move_to_front: MoveToFrontMode, pub sizing_mode: InventorySizingMode, }
Expand description
Generics
- K: Item Type
- S: Type of inventory location
- U: Custom item data
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.
Implementations
impl<K, S: SlotType, U: Default> Inventory<K, S, U>
[src]
impl<K, S: SlotType, U: Default> Inventory<K, 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]
pub fn new(
content: Vec<Option<ItemInstance<K, U>>>,
slot_restriction: Vec<Option<S>>,
move_to_front: MoveToFrontMode,
sizing_mode: InventorySizingMode
) -> Self
[src]Constructs a new Inventory
.
impl<K: PartialEq + Clone + Debug + Hash + Eq, S: SlotType, U: Default + Clone + Debug + PartialEq> Inventory<K, S, U>
[src]
impl<K: PartialEq + Clone + Debug + Hash + Eq, S: SlotType, U: Default + Clone + Debug + PartialEq> Inventory<K, S, U>
[src]pub fn new_fixed(count: usize) -> Inventory<K, S, U>
[src]
pub fn new_fixed(count: usize) -> Inventory<K, S, U>
[src]Creates a new Inventory
with a fixed slot count.
pub fn new_dynamic(minimum: usize, maximum: usize) -> Inventory<K, S, U>
[src]
pub fn new_dynamic(minimum: usize, maximum: usize) -> Inventory<K, 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]
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]
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 transfer<U2: Default>(
&mut self,
from_idx: usize,
target: &mut Inventory<K, S, U>,
to_idx: usize,
quantity: usize,
_with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]
pub fn transfer<U2: Default>(
&mut self,
from_idx: usize,
target: &mut Inventory<K, S, U>,
to_idx: usize,
quantity: usize,
_with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]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<U2: Default>(
&mut self,
from_idx: usize,
target: &mut Inventory<K, S, U>,
to_idx: usize,
with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]
pub fn transfer_stack<U2: Default>(
&mut self,
from_idx: usize,
target: &mut Inventory<K, S, U>,
to_idx: usize,
with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]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<U2: Default>(
&mut self,
from_idx: usize,
to_idx: usize,
quantity: usize,
_with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]
pub fn move_item<U2: Default>(
&mut self,
from_idx: usize,
to_idx: usize,
quantity: usize,
_with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]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<U2: Default>(
&mut self,
from_idx: usize,
to_idx: usize,
with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]
pub fn move_stack<U2: Default>(
&mut self,
from_idx: usize,
to_idx: usize,
with_overflow: bool,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]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]
pub fn delete(
&mut self,
idx: usize,
quantity: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
[src]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]
pub fn delete_stack(
&mut self,
idx: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
[src]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]
pub fn delete_key(
&mut self,
key: &K,
quantity: usize
) -> Result<ItemInstance<K, U>, ItemError<K, U>>
[src]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]
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]
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]
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]
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]
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]
pub fn get_key_mut(
&mut self,
key: &K
) -> impl Iterator<Item = &mut ItemInstance<K, U>>
[src]Finds the item instances using the specified key. Returns an iterator of mutable references.
pub fn insert_into<U2: Default>(
&mut self,
idx: usize,
item: ItemInstance<K, U>,
_item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]
pub fn insert_into<U2: Default>(
&mut self,
idx: usize,
item: ItemInstance<K, U>,
_item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]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<U2: Default>(
&mut self,
item: ItemInstance<K, U>,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]
pub fn insert<U2: Default>(
&mut self,
item: ItemInstance<K, U>,
item_defs: &ItemDefinitions<K, S, U2>
) -> Result<(), ItemError<K, U>>
[src]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]
pub fn first_empty_slot(&self) -> Option<usize>
[src]Returns the first empty slot if any is available.
Trait Implementations
impl<'de, K, S: SlotType, U: Default> Deserialize<'de> for Inventory<K, S, U> where
K: Deserialize<'de>,
S: Deserialize<'de>,
U: Deserialize<'de>,
[src]
impl<'de, K, S: SlotType, U: Default> Deserialize<'de> for Inventory<K, S, U> where
K: Deserialize<'de>,
S: Deserialize<'de>,
U: Deserialize<'de>,
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl<K, S, U> RefUnwindSafe for Inventory<K, S, U> where
K: RefUnwindSafe,
S: RefUnwindSafe,
U: RefUnwindSafe,
K: RefUnwindSafe,
S: RefUnwindSafe,
U: RefUnwindSafe,
impl<K, S, U> Send for Inventory<K, S, U> where
K: Send,
S: Send,
U: Send,
K: Send,
S: Send,
U: Send,
impl<K, S, U> Sync for Inventory<K, S, U> where
K: Sync,
S: Sync,
U: Sync,
K: Sync,
S: Sync,
U: Sync,
impl<K, S, U> Unpin for Inventory<K, S, U> where
K: Unpin,
S: Unpin,
U: Unpin,
K: Unpin,
S: Unpin,
U: Unpin,
impl<K, S, U> UnwindSafe for Inventory<K, S, U> where
K: UnwindSafe,
S: UnwindSafe,
U: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
U: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,