summaryrefslogtreecommitdiff
path: root/src/storage.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-20 14:03:39 -0600
committertom barrett <spalf0@gmail.com>2019-02-20 14:03:39 -0600
commiteb920a2c85e4ce4bbf755968a42218c0eb74987f (patch)
tree95943cfb9fa4d5b20dc38af0896d5d69e9bbb706 /src/storage.rs
parentc6be289134c1f749884d269f955b39d39b604469 (diff)
better mass access functions which improved testing code
Diffstat (limited to 'src/storage.rs')
-rw-r--r--src/storage.rs32
1 files changed, 7 insertions, 25 deletions
diff --git a/src/storage.rs b/src/storage.rs
index 5cbd55e..fbb99b1 100644
--- a/src/storage.rs
+++ b/src/storage.rs
@@ -35,31 +35,6 @@ impl Storage {
}
}
- pub fn take_items(&mut self, item_type: ItemType, count: usize) -> Option<Vec<Item>> {
- if self
- .items
- .iter()
- .filter(|item| item.item_type == item_type)
- .count()
- >= count
- {
- let mut items = Vec::new();
- for _ in 0..count {
- let index = self
- .items
- .iter()
- .position(|item| item.item_type == item_type)
- .unwrap();
- let item = self.items.remove(index);
- self.carrying -= item.size;
- items.push(item);
- }
- Some(items)
- } else {
- None
- }
- }
-
pub fn give_item(&mut self, item: Item) -> bool {
if self.capacity >= self.carrying + item.size {
self.carrying += item.size;
@@ -69,4 +44,11 @@ impl Storage {
false
}
}
+
+ pub fn item_count(&self, item_type: ItemType) -> usize {
+ self.items
+ .iter()
+ .filter(|item| item.item_type == item_type)
+ .count()
+ }
}