diff --git a/src/files/WorldFiles.cpp b/src/files/WorldFiles.cpp index 6fd51b84..4bb956d4 100644 --- a/src/files/WorldFiles.cpp +++ b/src/files/WorldFiles.cpp @@ -17,6 +17,7 @@ #include "../coders/json.h" #include "../constants.h" #include "../items/ItemDef.h" +#include "../items/Inventory.h" #include "../data/dynamic.h" @@ -526,7 +527,7 @@ bool WorldFiles::readWorldInfo(World* world) { return true; } -void WorldFiles::writePlayer(Player* player){ +void WorldFiles::writePlayer(Player* player) { glm::vec3 position = player->hitbox->position; dynamic::Map root; auto& posarr = root.putList("position"); @@ -540,6 +541,8 @@ void WorldFiles::writePlayer(Player* player){ root.put("flight", player->flight); root.put("noclip", player->noclip); + root.put("chosen-slot", player->getChosenSlot()); + root.put("inventory", player->getInventory()->write().release()); files::write_json(getPlayerFile(), &root); } @@ -565,5 +568,11 @@ bool WorldFiles::readPlayer(Player* player) { root->flag("flight", player->flight); root->flag("noclip", player->noclip); + player->setChosenSlot(root->getInt("chosen-slot", player->getChosenSlot())); + + auto invmap = root->map("inventory"); + if (invmap) { + player->getInventory()->read(invmap); + } return true; } diff --git a/src/items/Inventory.h b/src/items/Inventory.h index 34a38b44..6cde29a7 100644 --- a/src/items/Inventory.h +++ b/src/items/Inventory.h @@ -11,6 +11,7 @@ class ContentIndices; +// TODO: items indices fix class Inventory { std::vector slots; public: