From 15b473298160592d858e59e6997fe3255e0a7d2b Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 31 Aug 2020 23:45:40 -0600 Subject: [PATCH] item helper methods --- src/ship/items/inventory.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index b0cd347..044b6e2 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -3,6 +3,7 @@ use thiserror::Error; use libpso::character::character;//::InventoryItem; use crate::entity::item::{ItemEntityId, ItemDetail, ItemType}; use crate::entity::item::tool::Tool; +use crate::entity::item::mag::Mag; use crate::ship::items::{ClientItemId, BankItem, BankItemHandle}; use crate::ship::items::floor::{IndividualFloorItem, StackedFloorItem}; @@ -20,6 +21,15 @@ pub struct IndividualInventoryItem { pub equipped: bool, } +impl IndividualInventoryItem { + pub fn mag(&mut self) -> Option<&mut Mag> { + match self.item { + ItemDetail::Mag(ref mut mag) => Some(mag), + _ => None + } + } +} + #[derive(Debug, Clone)] pub struct StackedInventoryItem { pub entity_ids: Vec, @@ -178,6 +188,13 @@ impl InventoryItem { } Ok(()) } + + pub fn individual(&mut self) -> Option<&mut IndividualInventoryItem> { + match self { + InventoryItem::Individual(ref mut individual_inventory_item) => Some(individual_inventory_item), + _ => None + } + } }