PlayerInventory: fix bag loading issue
This commit is contained in:
parent
25f3edbae3
commit
03b7e3a22b
@ -781,19 +781,14 @@ void PlayerInventory::load(Json const& store) {
|
|||||||
|
|
||||||
//reuse ItemBags so the Inventory pane still works after load()'ing into the same PlayerInventory again (from swap)
|
//reuse ItemBags so the Inventory pane still works after load()'ing into the same PlayerInventory again (from swap)
|
||||||
auto itemBags = store.get("itemBags").toObject();
|
auto itemBags = store.get("itemBags").toObject();
|
||||||
eraseWhere(m_bags, [&](auto const& p) { return !itemBags.contains(p.first); });
|
|
||||||
m_inventoryLoadOverflow.clear();
|
m_inventoryLoadOverflow.clear();
|
||||||
for (auto const& p : itemBags) {
|
for (auto const& p : itemBags) {
|
||||||
auto& bagType = p.first;
|
auto& bagType = p.first;
|
||||||
auto newBag = ItemBag::loadStore(p.second);
|
auto newBag = ItemBag::loadStore(p.second);
|
||||||
if (m_bags.contains(bagType)) {
|
if (m_bags.contains(bagType)) {
|
||||||
auto& bag = m_bags[bagType];
|
auto& bag = m_bags.at(bagType);
|
||||||
auto size = bag->size();
|
m_inventoryLoadOverflow.appendAll(newBag.resize(bag->size()));
|
||||||
if (bag)
|
*bag = std::move(newBag);
|
||||||
*bag = std::move(newBag);
|
|
||||||
else
|
|
||||||
bag = make_shared<ItemBag>(std::move(newBag));
|
|
||||||
m_inventoryLoadOverflow.appendAll(bag->resize(size));
|
|
||||||
} else {
|
} else {
|
||||||
m_inventoryLoadOverflow.appendAll(newBag.items());
|
m_inventoryLoadOverflow.appendAll(newBag.items());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user