the big refactor + extracted data classes from coders/json to data/dynamic
This commit is contained in:
+18
-16
@@ -18,6 +18,8 @@
|
||||
#include "../constants.h"
|
||||
#include "../items/ItemDef.h"
|
||||
|
||||
#include "../data/dynamic.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
@@ -444,7 +446,7 @@ void WorldFiles::write(const World* world, const Content* content) {
|
||||
if (generatorTestMode)
|
||||
return;
|
||||
|
||||
writeIndices(content->indices);
|
||||
writeIndices(content->getIndices());
|
||||
writeRegions(regions, regionsFolder, REGION_LAYER_VOXELS);
|
||||
writeRegions(lights, lightsFolder, REGION_LAYER_LIGHTS);
|
||||
}
|
||||
@@ -460,16 +462,16 @@ void WorldFiles::writePacks(const World* world) {
|
||||
}
|
||||
|
||||
void WorldFiles::writeIndices(const ContentIndices* indices) {
|
||||
json::JObject root;
|
||||
dynamic::Map root;
|
||||
uint count;
|
||||
json::JArray& blocks = root.putArray("blocks");
|
||||
auto& blocks = root.putList("blocks");
|
||||
count = indices->countBlockDefs();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
const Block* def = indices->getBlockDef(i);
|
||||
blocks.put(def->name);
|
||||
}
|
||||
|
||||
json::JArray& items = root.putArray("items");
|
||||
auto& items = root.putList("items");
|
||||
count = indices->countItemDefs();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
const ItemDef* def = indices->getItemDef(i);
|
||||
@@ -480,16 +482,16 @@ void WorldFiles::writeIndices(const ContentIndices* indices) {
|
||||
}
|
||||
|
||||
void WorldFiles::writeWorldInfo(const World* world) {
|
||||
json::JObject root;
|
||||
dynamic::Map root;
|
||||
|
||||
json::JObject& versionobj = root.putObj("version");
|
||||
auto& versionobj = root.putMap("version");
|
||||
versionobj.put("major", ENGINE_VERSION_MAJOR);
|
||||
versionobj.put("minor", ENGINE_VERSION_MINOR);
|
||||
|
||||
root.put("name", world->name);
|
||||
root.put("seed", world->seed);
|
||||
|
||||
json::JObject& timeobj = root.putObj("time");
|
||||
auto& timeobj = root.putMap("time");
|
||||
timeobj.put("day-time", world->daytime);
|
||||
timeobj.put("day-time-speed", world->daytimeSpeed);
|
||||
|
||||
@@ -503,11 +505,11 @@ bool WorldFiles::readWorldInfo(World* world) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<json::JObject> root(files::read_json(file));
|
||||
auto root = files::read_json(file);
|
||||
root->str("name", world->name);
|
||||
root->num("seed", world->seed);
|
||||
|
||||
json::JObject* verobj = root->obj("version");
|
||||
auto verobj = root->map("version");
|
||||
if (verobj) {
|
||||
int major=0, minor=-1;
|
||||
verobj->num("major", major);
|
||||
@@ -515,7 +517,7 @@ bool WorldFiles::readWorldInfo(World* world) {
|
||||
std::cout << "world version: " << major << "." << minor << std::endl;
|
||||
}
|
||||
|
||||
json::JObject* timeobj = root->obj("time");
|
||||
auto timeobj = root->map("time");
|
||||
if (timeobj) {
|
||||
timeobj->num("day-time", world->daytime);
|
||||
timeobj->num("day-time-speed", world->daytimeSpeed);
|
||||
@@ -526,13 +528,13 @@ bool WorldFiles::readWorldInfo(World* world) {
|
||||
|
||||
void WorldFiles::writePlayer(Player* player){
|
||||
glm::vec3 position = player->hitbox->position;
|
||||
json::JObject root;
|
||||
json::JArray& posarr = root.putArray("position");
|
||||
dynamic::Map root;
|
||||
auto& posarr = root.putList("position");
|
||||
posarr.put(position.x);
|
||||
posarr.put(position.y);
|
||||
posarr.put(position.z);
|
||||
|
||||
json::JArray& rotarr = root.putArray("rotation");
|
||||
auto& rotarr = root.putList("rotation");
|
||||
rotarr.put(player->cam.x);
|
||||
rotarr.put(player->cam.y);
|
||||
|
||||
@@ -549,15 +551,15 @@ bool WorldFiles::readPlayer(Player* player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<json::JObject> root(files::read_json(file));
|
||||
json::JArray* posarr = root->arr("position");
|
||||
auto root = files::read_json(file);
|
||||
auto posarr = root->list("position");
|
||||
glm::vec3& position = player->hitbox->position;
|
||||
position.x = posarr->num(0);
|
||||
position.y = posarr->num(1);
|
||||
position.z = posarr->num(2);
|
||||
player->camera->position = position;
|
||||
|
||||
json::JArray* rotarr = root->arr("rotation");
|
||||
auto rotarr = root->list("rotation");
|
||||
player->cam.x = rotarr->num(0);
|
||||
player->cam.y = rotarr->num(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user