summaryrefslogtreecommitdiff
path: root/src/storage.rs
diff options
context:
space:
mode:
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()
+ }
}