diff options
author | tom barrett <spalf0@gmail.com> | 2019-02-20 14:03:39 -0600 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-02-20 14:03:39 -0600 |
commit | eb920a2c85e4ce4bbf755968a42218c0eb74987f (patch) | |
tree | 95943cfb9fa4d5b20dc38af0896d5d69e9bbb706 /src/mass.rs | |
parent | c6be289134c1f749884d269f955b39d39b604469 (diff) |
better mass access functions which improved testing code
Diffstat (limited to 'src/mass.rs')
-rw-r--r-- | src/mass.rs | 36 |
1 files changed, 36 insertions, 0 deletions
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<Item> { + 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, + } + } } |