1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-30 11:47:45 +00:00
kawari/src/inventory/generic.rs
Joshua Goins 01697c8f62 Begin implementing currency, add //gm gil command and more
This doesn't work yet though , and I'm not sure why. I also fixed a bug
where new characters doesn't get their inventories initialized properly.
2025-06-24 19:16:32 -04:00

34 lines
782 B
Rust

use serde::{Deserialize, Serialize};
use super::{Item, Storage};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GenericStorage<const N: usize> {
pub slots: Vec<Item>,
}
impl<const N: usize> GenericStorage<N> {
pub fn default() -> Self {
Self {
slots: vec![Item::default(); N],
}
}
}
impl<const N: usize> Storage for GenericStorage<N> {
fn max_slots(&self) -> u32 {
N as u32
}
fn num_items(&self) -> u32 {
self.slots.iter().filter(|item| item.quantity > 0).count() as u32
}
fn get_slot_mut(&mut self, index: u16) -> &mut Item {
self.slots.get_mut(index as usize).unwrap()
}
fn get_slot(&self, index: u16) -> &Item {
self.slots.get(index as usize).unwrap()
}
}