Addressed review comments

This commit is contained in:
Sam 2023-10-20 21:19:30 -04:00
parent 8d1df956d6
commit e925664d36
3 changed files with 8 additions and 2 deletions

View File

@ -1442,6 +1442,7 @@ impl Item {
/// If an item is stackable and has an amount greater than 1, creates a new
/// item with half the amount (rounded down), and decreases the amount of
/// the original item by the same quantity.
#[must_use = "Returned items will be lost if not used"]
pub fn take_half(
&mut self,
ability_map: &AbilityMap,

View File

@ -605,7 +605,7 @@ impl Inventory {
) -> Option<Item> {
if let Some(Some(item)) = self.slot_mut(inv_slot_id) {
item.take_half(ability_map, msm)
.or(self.remove(inv_slot_id))
.or_else(|| self.remove(inv_slot_id))
} else {
None
}
@ -621,7 +621,7 @@ impl Inventory {
) -> Option<Item> {
if let Some(item) = self.overflow_items.get_mut(overflow_slot) {
item.take_half(ability_map, msm)
.or(self.overflow_remove(overflow_slot))
.or_else(|| self.overflow_remove(overflow_slot))
} else {
None
}

View File

@ -23,6 +23,7 @@ fn push_full() {
.map(|a| Some(a.duplicate(ability_map, msm)))
.collect(),
loadout: LoadoutBuilder::empty().build(),
overflow_items: vec![],
};
assert_eq!(
inv.push(TEST_ITEMS[0].duplicate(ability_map, msm))
@ -43,6 +44,7 @@ fn push_all_full() {
.map(|a| Some(a.duplicate(ability_map, msm)))
.collect(),
loadout: LoadoutBuilder::empty().build(),
overflow_items: vec![],
};
let Error::Full(leftovers) = inv
.push_all(
@ -73,6 +75,7 @@ fn push_unique_all_full() {
.map(|a| Some(a.duplicate(ability_map, msm)))
.collect(),
loadout: LoadoutBuilder::empty().build(),
overflow_items: vec![],
};
inv.push_all_unique(
TEST_ITEMS
@ -92,6 +95,7 @@ fn push_all_empty() {
next_sort_order: InventorySortOrder::Name,
slots: vec![None, None],
loadout: LoadoutBuilder::empty().build(),
overflow_items: vec![],
};
inv.push_all(
TEST_ITEMS
@ -111,6 +115,7 @@ fn push_all_unique_empty() {
next_sort_order: InventorySortOrder::Name,
slots: vec![None, None],
loadout: LoadoutBuilder::empty().build(),
overflow_items: vec![],
};
inv.push_all_unique(
TEST_ITEMS