mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
inventory regions, minor refactor
This commit is contained in:
parent
a57fba4fa4
commit
49fdcdfb27
29 changed files with 259 additions and 160 deletions
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue