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->init(world);
}
for (auto& p : m_inventory->clearOverflow()) {
world->addEntity(ItemDrop::createRandomizedDrop(p,m_movementController->position(),true));
}
}
m_xAimPositionNetState.setInterpolator(world->geometry().xLerpFunction());
@ -346,7 +349,7 @@ void Player::uninit() {
m_questManager->uninit();
m_companions->uninit();
m_deployment->uninit();
for (auto& p : m_genericScriptContexts) {
p.second->uninit();
p.second->removeCallbacks("entity");
@ -2589,7 +2592,7 @@ void Player::setSecretProperty(String const& name, Json const& value) {
ds.write(value);
auto& data = ds.data();
m_effectsAnimator->setGlobalTag(secretProprefix + name, String(data.ptr(), data.size()));
}
}
else
m_effectsAnimator->removeGlobalTag(secretProprefix + name);
}

View File

@ -443,7 +443,7 @@ void PlayerInventory::condenseBagStacks(String const& bagType) {\
auto bag = m_bags[bagType];
bag->condenseStacks();
m_customBar.forEach([&](auto const&, CustomBarLink& link) {
if (link.first) {
if (auto bs = link.first->ptr<BagSlot>()) {
@ -756,6 +756,12 @@ Maybe<InventorySlot> PlayerInventory::secondaryHeldSlot() const {
return {};
}
List<ItemPtr> PlayerInventory::clearOverflow(){
auto list = m_inventoryLoadOverflow;
m_inventoryLoadOverflow.clear();
return list;
}
void PlayerInventory::load(Json const& store) {
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)
auto itemBags = store.get("itemBags").toObject();
eraseWhere(m_bags, [&](auto const& p) { return !itemBags.contains(p.first); });
m_inventoryLoadOverflow.clear();
for (auto const& p : itemBags) {
auto& bagType = p.first;
auto newBag = ItemBag::loadStore(p.second);
auto& bagPtr = m_bags[bagType];
if (bagPtr)
*bagPtr = std::move(newBag);
else
bagPtr = make_shared<ItemBag>(std::move(newBag));
if (m_bags.keys().contains(bagType)) {
auto& bagPtr = m_bags[bagType];
auto size = bagPtr.get()->size();
if (bagPtr)
*bagPtr = std::move(newBag);
else
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"));
@ -790,10 +803,17 @@ void PlayerInventory::load(Json const& store) {
for (size_t i = 0; i < m_customBar.size(0); ++i) {
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{
jsonToMaybe<InventorySlot>(cbl.get(0, {}), jsonToInventorySlot),
jsonToMaybe<InventorySlot>(cbl.get(1, {}), jsonToInventorySlot)
jsonToMaybe<InventorySlot>(validateLink(cbl.get(0, Json())), jsonToInventorySlot),
jsonToMaybe<InventorySlot>(validateLink(cbl.get(1, Json())), jsonToInventorySlot)
};
}
}

View File

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