From eb920a2c85e4ce4bbf755968a42218c0eb74987f Mon Sep 17 00:00:00 2001 From: tom barrett Date: Wed, 20 Feb 2019 14:03:39 -0600 Subject: better mass access functions which improved testing code --- src/mass.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/mass.rs') diff --git a/src/mass.rs b/src/mass.rs index 8d9f9fc..7cc7d70 100644 --- a/src/mass.rs +++ b/src/mass.rs @@ -272,4 +272,40 @@ impl Mass { } } } + + pub fn take_item(&mut self, item_type: ItemType) -> Option { + match self.mass_type { + MassType::Ship { + ref mut storage, .. + } => storage.take_item(item_type), + MassType::Astroid { + ref mut resources, .. + } => resources.take_item(item_type), + _ => None, + } + } + + pub fn give_item(&mut self, item: Item) -> bool { + match self.mass_type { + MassType::Ship { + ref mut storage, .. + } => storage.give_item(item), + MassType::Astroid { + ref mut resources, .. + } => resources.give_item(item), + _ => false, + } + } + + pub fn item_count(&self, item_type: ItemType) -> usize { + match &self.mass_type { + MassType::Ship { + storage, .. + } => storage.item_count(item_type), + MassType::Astroid { + resources, .. + } => resources.item_count(item_type), + _ => 0, + } + } } -- cgit v1.2.3