| 793 | } |
| 794 | |
| 795 | void PlayerInventory::load(Json const& store) { |
| 796 | auto itemDatabase = Root::singleton().itemDatabase(); |
| 797 | |
| 798 | for (auto slot : EquipmentSlotNames) { |
| 799 | auto jItem = store.get(strf("{}Slot", slot.second), Json()); |
| 800 | m_equipment[slot.first] = itemDatabase->diskLoad(jItem); |
| 801 | } |
| 802 | |
| 803 | //reuse ItemBags so the Inventory pane still works after load()'ing into the same PlayerInventory again (from swap) |
| 804 | auto itemBags = store.get("itemBags").toObject(); |
| 805 | m_inventoryLoadOverflow.clear(); |
| 806 | for (auto const& p : itemBags) { |
| 807 | auto& bagType = p.first; |
| 808 | auto newBag = ItemBag::loadStore(p.second); |
| 809 | if (m_bags.contains(bagType)) { |
| 810 | auto& bag = m_bags.at(bagType); |
| 811 | m_inventoryLoadOverflow.appendAll(newBag.resize(bag->size())); |
| 812 | *bag = std::move(newBag); |
| 813 | } else { |
| 814 | m_inventoryLoadOverflow.appendAll(newBag.items()); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | m_swapSlot = itemDatabase->diskLoad(store.get("swapSlot")); |
| 819 | m_trashSlot = itemDatabase->diskLoad(store.get("trashSlot")); |
| 820 | |
| 821 | m_currencies = jsonToMapV<StringMap<uint64_t>>(store.get("currencies"), mem_fn(&Json::toUInt)); |
| 822 | |
| 823 | m_customBarGroup = store.getUInt("customBarGroup"); |
| 824 | |
| 825 | for (size_t i = 0; i < m_customBar.size(0); ++i) { |
| 826 | for (size_t j = 0; j < m_customBar.size(1); ++j) { |
| 827 | Json cbl = store.get("customBar").get(i, JsonArray()).get(j, JsonArray()); |
| 828 | auto validateLink = [this](Maybe<InventorySlot> link) -> Maybe<InventorySlot> { |
| 829 | if (link && link->is<BagSlot>()) { |
| 830 | auto& slot = link->get<BagSlot>(); |
| 831 | if (m_bags.contains(slot.first) && size_t(slot.second) < m_bags[slot.first]->size()) |
| 832 | return link; |
| 833 | else |
| 834 | return {}; |
| 835 | } |
| 836 | return link; |
| 837 | }; |
| 838 | m_customBar.at(i, j) = CustomBarLink{ |
| 839 | validateLink(jsonToMaybe<InventorySlot>(cbl.get(0, {}), jsonToInventorySlot)), |
| 840 | validateLink(jsonToMaybe<InventorySlot>(cbl.get(1, {}), jsonToInventorySlot)) |
| 841 | }; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | m_selectedActionBar = jsonToSelectedActionBarLocation(store.get("selectedActionBar")); |
| 846 | |
| 847 | m_essential.clear(); |
| 848 | m_essential[EssentialItem::BeamAxe] = itemDatabase->diskLoad(store.get("beamAxe")); |
| 849 | m_essential[EssentialItem::WireTool] = itemDatabase->diskLoad(store.get("wireTool")); |
| 850 | m_essential[EssentialItem::PaintTool] = itemDatabase->diskLoad(store.get("paintTool")); |
| 851 | m_essential[EssentialItem::InspectionTool] = itemDatabase->diskLoad(store.get("inspectionTool")); |
| 852 |
no test coverage detected