minor code polish
This commit is contained in:
parent
52a6f200ed
commit
165bcbefee
@ -204,7 +204,7 @@ String hexEncode(ByteArray const& data) {
|
||||
|
||||
ByteArray hexDecode(String const& encodedData) {
|
||||
ByteArray res(encodedData.size() / 2, 0);
|
||||
size_t decoded = hexDecode(encodedData.utf8Ptr(), encodedData.size(), res.ptr(), res.size());
|
||||
size_t decoded = hexDecode(encodedData.utf8Ptr(), encodedData.utf8Size(), res.ptr(), res.size());
|
||||
_unused(decoded);
|
||||
starAssert(decoded == res.size());
|
||||
return res;
|
||||
@ -216,7 +216,7 @@ String base64Encode(ByteArray const& data) {
|
||||
|
||||
ByteArray base64Decode(String const& encodedData) {
|
||||
ByteArray res(encodedData.size() * 3 / 4, 0);
|
||||
size_t decoded = base64Decode(encodedData.utf8Ptr(), encodedData.size(), res.ptr(), res.size());
|
||||
size_t decoded = base64Decode(encodedData.utf8Ptr(), encodedData.utf8Size(), res.ptr(), res.size());
|
||||
_unused(decoded);
|
||||
starAssert(decoded <= res.size());
|
||||
res.resize(decoded);
|
||||
|
@ -330,7 +330,8 @@ 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()) {
|
||||
|
||||
for (auto& p : m_inventory->pullOverflow()) {
|
||||
world->addEntity(ItemDrop::createRandomizedDrop(p, m_movementController->position(), true));
|
||||
}
|
||||
}
|
||||
|
@ -756,10 +756,8 @@ Maybe<InventorySlot> PlayerInventory::secondaryHeldSlot() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
List<ItemPtr> PlayerInventory::clearOverflow(){
|
||||
auto list = m_inventoryLoadOverflow;
|
||||
m_inventoryLoadOverflow.clear();
|
||||
return list;
|
||||
List<ItemPtr> PlayerInventory::pullOverflow() {
|
||||
return std::move(m_inventoryLoadOverflow);
|
||||
}
|
||||
|
||||
void PlayerInventory::load(Json const& store) {
|
||||
@ -781,16 +779,16 @@ void PlayerInventory::load(Json const& store) {
|
||||
for (auto const& p : itemBags) {
|
||||
auto& bagType = p.first;
|
||||
auto newBag = ItemBag::loadStore(p.second);
|
||||
if (m_bags.keys().contains(bagType)) {
|
||||
auto& bagPtr = m_bags[bagType];
|
||||
auto size = bagPtr.get()->size();
|
||||
if (bagPtr)
|
||||
*bagPtr = std::move(newBag);
|
||||
if (m_bags.contains(bagType)) {
|
||||
auto& bag = m_bags[bagType];
|
||||
auto size = bag->size();
|
||||
if (bag)
|
||||
*bag = std::move(newBag);
|
||||
else
|
||||
bagPtr = make_shared<ItemBag>(std::move(newBag));
|
||||
m_inventoryLoadOverflow.appendAll(bagPtr.get()->resize(size));
|
||||
bag = make_shared<ItemBag>(std::move(newBag));
|
||||
m_inventoryLoadOverflow.appendAll(bag->resize(size));
|
||||
} else {
|
||||
m_inventoryLoadOverflow.appendAll(ItemBag(newBag).items());
|
||||
m_inventoryLoadOverflow.appendAll(newBag.items());
|
||||
}
|
||||
}
|
||||
|
||||
@ -804,16 +802,19 @@ 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, 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")))
|
||||
auto validateLink = [this](Maybe<InventorySlot> link) -> Maybe<InventorySlot> {
|
||||
if (link && link->is<BagSlot>()) {
|
||||
auto& slot = link->get<BagSlot>();
|
||||
if (m_bags.contains(slot.first) && size_t(slot.second) < m_bags[slot.first]->size())
|
||||
return link;
|
||||
else
|
||||
return {};
|
||||
}
|
||||
return link;
|
||||
return Json();
|
||||
};
|
||||
m_customBar.at(i, j) = CustomBarLink{
|
||||
jsonToMaybe<InventorySlot>(validateLink(cbl.get(0, Json())), jsonToInventorySlot),
|
||||
jsonToMaybe<InventorySlot>(validateLink(cbl.get(1, Json())), jsonToInventorySlot)
|
||||
validateLink(jsonToMaybe<InventorySlot>(cbl.get(0, {}), jsonToInventorySlot)),
|
||||
validateLink(jsonToMaybe<InventorySlot>(cbl.get(1, {}), jsonToInventorySlot))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ public:
|
||||
Maybe<InventorySlot> primaryHeldSlot() const;
|
||||
Maybe<InventorySlot> secondaryHeldSlot() const;
|
||||
|
||||
List<ItemPtr> clearOverflow();
|
||||
List<ItemPtr> pullOverflow();
|
||||
|
||||
void load(Json const& store);
|
||||
Json store() const;
|
||||
|
@ -574,8 +574,10 @@ bool UniverseClient::switchPlayer(size_t index) {
|
||||
bool UniverseClient::switchPlayer(String const& name) {
|
||||
if (auto uuid = m_playerStorage->playerUuidByName(name, mainPlayer()->uuid()))
|
||||
return switchPlayer(*uuid);
|
||||
else
|
||||
else if (name.utf8Size() == UuidSize * 2)
|
||||
return switchPlayer(Uuid(name));
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
UniverseClient::ReloadPlayerCallback& UniverseClient::playerReloadPreCallback() {
|
||||
|
Loading…
Reference in New Issue
Block a user