inventory and hotbar size mismatch fixes

I realized why that was there

checking patch arrays in a more clean manner

also support for checking values in other files using a string in the patch arrays

Revert "checking patch arrays in a more clean manner"

sorry that wasn't supposed to be in this one
This commit is contained in:
WasabiRaptor 2024-03-07 13:12:11 -05:00
parent 79cd235939
commit f8a6a3e57d
3 changed files with 38 additions and 11 deletions

View File

@ -330,6 +330,9 @@ void Player::init(World* world, EntityId entityId, EntityMode mode) {
p.second->addCallbacks("celestial", LuaBindings::makeCelestialCallbacks(m_client)); p.second->addCallbacks("celestial", LuaBindings::makeCelestialCallbacks(m_client));
p.second->init(world); p.second->init(world);
} }
for (auto& p : m_inventory->clearOverflow()) {
world->addEntity(ItemDrop::createRandomizedDrop(p,m_movementController->position(),true));
}
} }
m_xAimPositionNetState.setInterpolator(world->geometry().xLerpFunction()); m_xAimPositionNetState.setInterpolator(world->geometry().xLerpFunction());

View File

@ -756,6 +756,12 @@ Maybe<InventorySlot> PlayerInventory::secondaryHeldSlot() const {
return {}; return {};
} }
List<ItemPtr> PlayerInventory::clearOverflow(){
auto list = m_inventoryLoadOverflow;
m_inventoryLoadOverflow.clear();
return list;
}
void PlayerInventory::load(Json const& store) { void PlayerInventory::load(Json const& store) {
auto itemDatabase = Root::singleton().itemDatabase(); auto itemDatabase = Root::singleton().itemDatabase();
@ -771,14 +777,21 @@ 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); }); eraseWhere(m_bags, [&](auto const& p) { return !itemBags.contains(p.first); });
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.keys().contains(bagType)) {
auto& bagPtr = m_bags[bagType]; auto& bagPtr = m_bags[bagType];
auto size = bagPtr.get()->size();
if (bagPtr) if (bagPtr)
*bagPtr = std::move(newBag); *bagPtr = std::move(newBag);
else else
bagPtr = make_shared<ItemBag>(std::move(newBag)); bagPtr = make_shared<ItemBag>(std::move(newBag));
m_inventoryLoadOverflow.appendAll(bagPtr.get()->resize(size));
} else {
m_inventoryLoadOverflow.appendAll(ItemBag(newBag).items());
}
} }
m_swapSlot = itemDatabase->diskLoad(store.get("swapSlot")); m_swapSlot = itemDatabase->diskLoad(store.get("swapSlot"));
@ -790,10 +803,17 @@ void PlayerInventory::load(Json const& store) {
for (size_t i = 0; i < m_customBar.size(0); ++i) { for (size_t i = 0; i < m_customBar.size(0); ++i) {
for (size_t j = 0; j < m_customBar.size(1); ++j) { for (size_t j = 0; j < m_customBar.size(1); ++j) {
Json cbl = store.get("customBar").get(i).get(j); Json cbl = store.get("customBar").get(i,JsonArray()).get(j,JsonArray());
auto validateLink = [this](Json link) -> Json {
if ((link.isType(Json::Type::Object))
&& (m_bags.keys().contains(link.getString("type")))
&& (m_bags[link.getString("type")].get()->size() > link.getUInt("location")))
return link;
return Json();
};
m_customBar.at(i, j) = CustomBarLink{ m_customBar.at(i, j) = CustomBarLink{
jsonToMaybe<InventorySlot>(cbl.get(0, {}), jsonToInventorySlot), jsonToMaybe<InventorySlot>(validateLink(cbl.get(0, Json())), jsonToInventorySlot),
jsonToMaybe<InventorySlot>(cbl.get(1, {}), jsonToInventorySlot) jsonToMaybe<InventorySlot>(validateLink(cbl.get(1, Json())), jsonToInventorySlot)
}; };
} }
} }

View File

@ -168,6 +168,8 @@ public:
Maybe<InventorySlot> primaryHeldSlot() const; Maybe<InventorySlot> primaryHeldSlot() const;
Maybe<InventorySlot> secondaryHeldSlot() const; Maybe<InventorySlot> secondaryHeldSlot() const;
List<ItemPtr> clearOverflow();
void load(Json const& store); void load(Json const& store);
Json store() const; Json store() const;
@ -219,6 +221,8 @@ private:
NetElementUInt m_customBarGroupNetState; NetElementUInt m_customBarGroupNetState;
MultiArray<NetElementData<CustomBarLink>, 2> m_customBarNetState; MultiArray<NetElementData<CustomBarLink>, 2> m_customBarNetState;
NetElementData<SelectedActionBarLocation> m_selectedActionBarNetState; NetElementData<SelectedActionBarLocation> m_selectedActionBarNetState;
List<ItemPtr> m_inventoryLoadOverflow;
}; };
} }