mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Addressed review comments
This commit is contained in:
parent
8d1df956d6
commit
e925664d36
@ -1442,6 +1442,7 @@ impl Item {
|
|||||||
/// If an item is stackable and has an amount greater than 1, creates a new
|
/// 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
|
/// item with half the amount (rounded down), and decreases the amount of
|
||||||
/// the original item by the same quantity.
|
/// the original item by the same quantity.
|
||||||
|
#[must_use = "Returned items will be lost if not used"]
|
||||||
pub fn take_half(
|
pub fn take_half(
|
||||||
&mut self,
|
&mut self,
|
||||||
ability_map: &AbilityMap,
|
ability_map: &AbilityMap,
|
||||||
|
@ -605,7 +605,7 @@ impl Inventory {
|
|||||||
) -> Option<Item> {
|
) -> Option<Item> {
|
||||||
if let Some(Some(item)) = self.slot_mut(inv_slot_id) {
|
if let Some(Some(item)) = self.slot_mut(inv_slot_id) {
|
||||||
item.take_half(ability_map, msm)
|
item.take_half(ability_map, msm)
|
||||||
.or(self.remove(inv_slot_id))
|
.or_else(|| self.remove(inv_slot_id))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -621,7 +621,7 @@ impl Inventory {
|
|||||||
) -> Option<Item> {
|
) -> Option<Item> {
|
||||||
if let Some(item) = self.overflow_items.get_mut(overflow_slot) {
|
if let Some(item) = self.overflow_items.get_mut(overflow_slot) {
|
||||||
item.take_half(ability_map, msm)
|
item.take_half(ability_map, msm)
|
||||||
.or(self.overflow_remove(overflow_slot))
|
.or_else(|| self.overflow_remove(overflow_slot))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ fn push_full() {
|
|||||||
.map(|a| Some(a.duplicate(ability_map, msm)))
|
.map(|a| Some(a.duplicate(ability_map, msm)))
|
||||||
.collect(),
|
.collect(),
|
||||||
loadout: LoadoutBuilder::empty().build(),
|
loadout: LoadoutBuilder::empty().build(),
|
||||||
|
overflow_items: vec![],
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
inv.push(TEST_ITEMS[0].duplicate(ability_map, msm))
|
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)))
|
.map(|a| Some(a.duplicate(ability_map, msm)))
|
||||||
.collect(),
|
.collect(),
|
||||||
loadout: LoadoutBuilder::empty().build(),
|
loadout: LoadoutBuilder::empty().build(),
|
||||||
|
overflow_items: vec![],
|
||||||
};
|
};
|
||||||
let Error::Full(leftovers) = inv
|
let Error::Full(leftovers) = inv
|
||||||
.push_all(
|
.push_all(
|
||||||
@ -73,6 +75,7 @@ fn push_unique_all_full() {
|
|||||||
.map(|a| Some(a.duplicate(ability_map, msm)))
|
.map(|a| Some(a.duplicate(ability_map, msm)))
|
||||||
.collect(),
|
.collect(),
|
||||||
loadout: LoadoutBuilder::empty().build(),
|
loadout: LoadoutBuilder::empty().build(),
|
||||||
|
overflow_items: vec![],
|
||||||
};
|
};
|
||||||
inv.push_all_unique(
|
inv.push_all_unique(
|
||||||
TEST_ITEMS
|
TEST_ITEMS
|
||||||
@ -92,6 +95,7 @@ fn push_all_empty() {
|
|||||||
next_sort_order: InventorySortOrder::Name,
|
next_sort_order: InventorySortOrder::Name,
|
||||||
slots: vec![None, None],
|
slots: vec![None, None],
|
||||||
loadout: LoadoutBuilder::empty().build(),
|
loadout: LoadoutBuilder::empty().build(),
|
||||||
|
overflow_items: vec![],
|
||||||
};
|
};
|
||||||
inv.push_all(
|
inv.push_all(
|
||||||
TEST_ITEMS
|
TEST_ITEMS
|
||||||
@ -111,6 +115,7 @@ fn push_all_unique_empty() {
|
|||||||
next_sort_order: InventorySortOrder::Name,
|
next_sort_order: InventorySortOrder::Name,
|
||||||
slots: vec![None, None],
|
slots: vec![None, None],
|
||||||
loadout: LoadoutBuilder::empty().build(),
|
loadout: LoadoutBuilder::empty().build(),
|
||||||
|
overflow_items: vec![],
|
||||||
};
|
};
|
||||||
inv.push_all_unique(
|
inv.push_all_unique(
|
||||||
TEST_ITEMS
|
TEST_ITEMS
|
||||||
|
Loading…
Reference in New Issue
Block a user