inventory saving
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include "../coders/json.h"
|
#include "../coders/json.h"
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
#include "../items/ItemDef.h"
|
#include "../items/ItemDef.h"
|
||||||
|
#include "../items/Inventory.h"
|
||||||
|
|
||||||
#include "../data/dynamic.h"
|
#include "../data/dynamic.h"
|
||||||
|
|
||||||
@@ -526,7 +527,7 @@ bool WorldFiles::readWorldInfo(World* world) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFiles::writePlayer(Player* player){
|
void WorldFiles::writePlayer(Player* player) {
|
||||||
glm::vec3 position = player->hitbox->position;
|
glm::vec3 position = player->hitbox->position;
|
||||||
dynamic::Map root;
|
dynamic::Map root;
|
||||||
auto& posarr = root.putList("position");
|
auto& posarr = root.putList("position");
|
||||||
@@ -540,6 +541,8 @@ void WorldFiles::writePlayer(Player* player){
|
|||||||
|
|
||||||
root.put("flight", player->flight);
|
root.put("flight", player->flight);
|
||||||
root.put("noclip", player->noclip);
|
root.put("noclip", player->noclip);
|
||||||
|
root.put("chosen-slot", player->getChosenSlot());
|
||||||
|
root.put("inventory", player->getInventory()->write().release());
|
||||||
|
|
||||||
files::write_json(getPlayerFile(), &root);
|
files::write_json(getPlayerFile(), &root);
|
||||||
}
|
}
|
||||||
@@ -565,5 +568,11 @@ bool WorldFiles::readPlayer(Player* player) {
|
|||||||
|
|
||||||
root->flag("flight", player->flight);
|
root->flag("flight", player->flight);
|
||||||
root->flag("noclip", player->noclip);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
class ContentIndices;
|
class ContentIndices;
|
||||||
|
|
||||||
|
// TODO: items indices fix
|
||||||
class Inventory {
|
class Inventory {
|
||||||
std::vector<ItemStack> slots;
|
std::vector<ItemStack> slots;
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user