//Re-Exports pub mod item; // Reexports pub use self::item::Item; use specs::{Component, HashMapStorage}; use specs_idvs::IDVStorage; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Inventory { pub slots: Vec>, } impl Inventory { pub fn new() -> Inventory { Inventory { slots: vec![None; 24], } } // Get info about an item slot pub fn get(&self, cell: usize) -> Option { self.slots.get(cell).cloned().flatten() } // Insert an item to a slot if its empty pub fn swap(&mut self, cell: usize, item: Item) -> Option { //TODO: Check if a slot is empty first. self.slots.get_mut(cell).and_then(|cell| cell.replace(item)) } // Remove an item from the slot pub fn remove(&mut self, cell: usize) -> Option { self.slots.get_mut(cell).and_then(|item| item.take()) } } impl Component for Inventory { type Storage = HashMapStorage; }