//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 { // 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 Default for Inventory { fn default() -> Inventory { Inventory { slots: vec![None; 24], } } } impl Component for Inventory { type Storage = HashMapStorage; }