inventory regions, minor refactor

This commit is contained in:
MihailRis
2024-01-31 00:14:43 +03:00
parent a57fba4fa4
commit 49fdcdfb27
29 changed files with 259 additions and 160 deletions
+4 -1
View File
@@ -2,7 +2,7 @@
#include "../content/ContentLUT.h"
Inventory::Inventory(size_t size) : slots(size) {
Inventory::Inventory(uint id, size_t size) : id(id), slots(size) {
}
ItemStack& Inventory::getSlot(size_t index) {
@@ -45,6 +45,7 @@ void Inventory::move(
}
void Inventory::deserialize(dynamic::Map* src) {
id = src->getNum("id", 1);
auto slotsarr = src->list("slots");
size_t slotscount = std::min(slotsarr->size(), slots.size());
for (size_t i = 0; i < slotscount; i++) {
@@ -58,6 +59,8 @@ void Inventory::deserialize(dynamic::Map* src) {
std::unique_ptr<dynamic::Map> Inventory::serialize() const {
auto map = std::make_unique<dynamic::Map>();
map->put("id", id);
auto& slotsarr = map->putList("slots");
for (size_t i = 0; i < slots.size(); i++) {
auto& item = slots[i];