inventory regions, minor refactor
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user