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];
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
class ContentLUT;
|
||||
class ContentIndices;
|
||||
|
||||
// TODO: items indices fix
|
||||
class Inventory : Serializable {
|
||||
uint id;
|
||||
std::vector<ItemStack> slots;
|
||||
public:
|
||||
Inventory(size_t size);
|
||||
Inventory(uint id, size_t size);
|
||||
|
||||
ItemStack& getSlot(size_t index);
|
||||
size_t findEmptySlot(size_t begin=0, size_t end=-1) const;
|
||||
@@ -40,6 +40,10 @@ public:
|
||||
|
||||
static void convert(dynamic::Map* data, const ContentLUT* lut);
|
||||
|
||||
inline uint getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
static const size_t npos;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user