inventory reindexing
This commit is contained in:
@@ -4,8 +4,12 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include "WorldFiles.h"
|
||||
|
||||
#include "../data/dynamic.h"
|
||||
#include "../files/files.h"
|
||||
#include "../voxels/Chunk.h"
|
||||
#include "../content/ContentLUT.h"
|
||||
#include "../objects/Player.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -21,8 +25,9 @@ WorldConverter::WorldConverter(fs::path folder,
|
||||
std::cerr << "nothing to convert" << std::endl;
|
||||
return;
|
||||
}
|
||||
tasks.push(convert_task {convert_task_type::player, wfile->getPlayerFile()});
|
||||
for (auto file : fs::directory_iterator(regionsFolder)) {
|
||||
regions.push(file.path());
|
||||
tasks.push(convert_task {convert_task_type::region, file.path()});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,19 +36,12 @@ WorldConverter::~WorldConverter() {
|
||||
}
|
||||
|
||||
bool WorldConverter::hasNext() const {
|
||||
return !regions.empty();
|
||||
return !tasks.empty();
|
||||
}
|
||||
|
||||
void WorldConverter::convertNext() {
|
||||
if (!hasNext()) {
|
||||
throw std::runtime_error("no more regions to convert");
|
||||
}
|
||||
fs::path regfile = regions.front();
|
||||
regions.pop();
|
||||
if (!fs::is_regular_file(regfile))
|
||||
return;
|
||||
void WorldConverter::convertRegion(fs::path file) {
|
||||
int x, z;
|
||||
std::string name = regfile.stem().string();
|
||||
std::string name = file.stem().string();
|
||||
if (!WorldFiles::parseRegionFilename(name, x, z)) {
|
||||
std::cerr << "could not parse name " << name << std::endl;
|
||||
return;
|
||||
@@ -64,6 +62,32 @@ void WorldConverter::convertNext() {
|
||||
}
|
||||
}
|
||||
|
||||
void WorldConverter::convertPlayer(fs::path file) {
|
||||
std::cout << "converting player " << file.u8string() << std::endl;
|
||||
auto map = files::read_json(file);
|
||||
Player::convert(map.get(), lut.get());
|
||||
files::write_json(file, map.get());
|
||||
}
|
||||
|
||||
void WorldConverter::convertNext() {
|
||||
if (!hasNext()) {
|
||||
throw std::runtime_error("no more regions to convert");
|
||||
}
|
||||
convert_task task = tasks.front();
|
||||
tasks.pop();
|
||||
|
||||
if (!fs::is_regular_file(task.file))
|
||||
return;
|
||||
switch (task.type) {
|
||||
case convert_task_type::region:
|
||||
convertRegion(task.file);
|
||||
break;
|
||||
case convert_task_type::player:
|
||||
convertPlayer(task.file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WorldConverter::write() {
|
||||
std::cout << "writing world" << std::endl;
|
||||
wfile->write(nullptr, content);
|
||||
|
||||
@@ -11,11 +11,23 @@ class Content;
|
||||
class ContentLUT;
|
||||
class WorldFiles;
|
||||
|
||||
enum class convert_task_type {
|
||||
region, player
|
||||
};
|
||||
|
||||
struct convert_task {
|
||||
convert_task_type type;
|
||||
fs::path file;
|
||||
};
|
||||
|
||||
class WorldConverter {
|
||||
WorldFiles* wfile;
|
||||
std::shared_ptr<ContentLUT> const lut;
|
||||
const Content* const content;
|
||||
std::queue<fs::path> regions;
|
||||
std::queue<convert_task> tasks;
|
||||
|
||||
void convertPlayer(fs::path file);
|
||||
void convertRegion(fs::path file);
|
||||
public:
|
||||
WorldConverter(fs::path folder, const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut);
|
||||
|
||||
@@ -531,29 +531,7 @@ bool WorldFiles::readWorldInfo(World* world) {
|
||||
}
|
||||
|
||||
void WorldFiles::writePlayer(Player* player) {
|
||||
glm::vec3 position = player->hitbox->position;
|
||||
dynamic::Map root;
|
||||
auto& posarr = root.putList("position");
|
||||
posarr.put(position.x);
|
||||
posarr.put(position.y);
|
||||
posarr.put(position.z);
|
||||
|
||||
auto& rotarr = root.putList("rotation");
|
||||
rotarr.put(player->cam.x);
|
||||
rotarr.put(player->cam.y);
|
||||
|
||||
auto& sparr = root.putList("spawnpoint");
|
||||
glm::vec3 spawnpoint = player->getSpawnPoint();
|
||||
sparr.put(spawnpoint.x);
|
||||
sparr.put(spawnpoint.y);
|
||||
sparr.put(spawnpoint.z);
|
||||
|
||||
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);
|
||||
files::write_json(getPlayerFile(), player->write().release());
|
||||
}
|
||||
|
||||
bool WorldFiles::readPlayer(Player* player) {
|
||||
|
||||
@@ -76,7 +76,6 @@ class WorldFiles {
|
||||
void writeWorldInfo(const World* world);
|
||||
fs::path getLightsFolder() const;
|
||||
fs::path getRegionFilename(int x, int y) const;
|
||||
fs::path getPlayerFile() const;
|
||||
fs::path getWorldFile() const;
|
||||
fs::path getIndicesFile() const;
|
||||
fs::path getPacksFile() const;
|
||||
@@ -114,6 +113,7 @@ class WorldFiles {
|
||||
public:
|
||||
static bool parseRegionFilename(const std::string& name, int& x, int& y);
|
||||
fs::path getRegionsFolder() const;
|
||||
fs::path getPlayerFile() const;
|
||||
|
||||
regionsmap regions;
|
||||
regionsmap lights;
|
||||
|
||||
Reference in New Issue
Block a user