mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 20:11:50 +00:00
added serializable class
This commit is contained in:
parent
a9b55f35be
commit
8466c42896
6 changed files with 64 additions and 41 deletions
|
|
@ -44,7 +44,7 @@ void Inventory::move(
|
|||
}
|
||||
}
|
||||
|
||||
void Inventory::read(const dynamic::Map* src) {
|
||||
void Inventory::deserialize(dynamic::Map* src) {
|
||||
auto slotsarr = src->list("slots");
|
||||
size_t slotscount = std::min(slotsarr->size(), slots.size());
|
||||
for (size_t i = 0; i < slotscount; i++) {
|
||||
|
|
@ -56,7 +56,7 @@ void Inventory::read(const dynamic::Map* src) {
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<dynamic::Map> Inventory::write() const {
|
||||
std::unique_ptr<dynamic::Map> Inventory::serialize() const {
|
||||
auto map = std::make_unique<dynamic::Map>();
|
||||
auto& slotsarr = map->putList("slots");
|
||||
for (size_t i = 0; i < slots.size(); i++) {
|
||||
|
|
|
|||
|
|
@ -8,12 +8,13 @@
|
|||
|
||||
#include "../typedefs.h"
|
||||
#include "../data/dynamic.h"
|
||||
#include "../interfaces/Serializable.h"
|
||||
|
||||
class ContentLUT;
|
||||
class ContentIndices;
|
||||
|
||||
// TODO: items indices fix
|
||||
class Inventory {
|
||||
class Inventory : Serializable {
|
||||
std::vector<ItemStack> slots;
|
||||
public:
|
||||
Inventory(size_t size);
|
||||
|
|
@ -33,9 +34,9 @@ public:
|
|||
size_t end=-1);
|
||||
|
||||
/* deserializing inventory */
|
||||
void read(const dynamic::Map* src);
|
||||
void deserialize(dynamic::Map* src) override;
|
||||
/* serializing inventory */
|
||||
std::unique_ptr<dynamic::Map> write() const;
|
||||
std::unique_ptr<dynamic::Map> serialize() const override;
|
||||
|
||||
static void convert(dynamic::Map* data, const ContentLUT* lut);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue