the big refactor + extracted data classes from coders/json to data/dynamic
This commit is contained in:
+13
-18
@@ -8,15 +8,10 @@
|
||||
#include "../coders/json.h"
|
||||
#include "../voxels/Block.h"
|
||||
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
using std::filesystem::path;
|
||||
|
||||
#include <iostream>
|
||||
#include "../data/dynamic.h"
|
||||
|
||||
ContentLUT::ContentLUT(size_t blocksCount, const Content* content) {
|
||||
ContentIndices* indices = content->indices;
|
||||
auto* indices = content->getIndices();
|
||||
for (size_t i = 0; i < blocksCount; i++) {
|
||||
blocks.push_back(i);
|
||||
}
|
||||
@@ -24,25 +19,25 @@ ContentLUT::ContentLUT(size_t blocksCount, const Content* content) {
|
||||
blockNames.push_back(indices->getBlockDef(i)->name);
|
||||
}
|
||||
|
||||
for (size_t i = indices->countBlockDefs(); i < blocksCount; i++) {
|
||||
for (size_t i = indices->countBlockDefs(); i < blocksCount; i++) {
|
||||
blockNames.push_back("");
|
||||
}
|
||||
}
|
||||
|
||||
ContentLUT* ContentLUT::create(const path& filename,
|
||||
ContentLUT* ContentLUT::create(const fs::path& filename,
|
||||
const Content* content) {
|
||||
unique_ptr<json::JObject> root(files::read_json(filename));
|
||||
json::JArray* blocksarr = root->arr("blocks");
|
||||
auto root = files::read_json(filename);
|
||||
auto blocklist = root->list("blocks");
|
||||
|
||||
auto& indices = content->indices;
|
||||
size_t blocks_c = blocksarr
|
||||
? std::max(blocksarr->size(), indices->countBlockDefs())
|
||||
auto* indices = content->getIndices();
|
||||
size_t blocks_c = blocklist
|
||||
? std::max(blocklist->size(), indices->countBlockDefs())
|
||||
: indices->countBlockDefs();
|
||||
|
||||
auto lut = make_unique<ContentLUT>(blocks_c, content);
|
||||
if (blocksarr) {
|
||||
for (size_t i = 0; i < blocksarr->size(); i++) {
|
||||
string name = blocksarr->str(i);
|
||||
auto lut = std::make_unique<ContentLUT>(blocks_c, content);
|
||||
if (blocklist) {
|
||||
for (size_t i = 0; i < blocklist->size(); i++) {
|
||||
std::string name = blocklist->str(i);
|
||||
Block* def = content->findBlock(name);
|
||||
if (def) {
|
||||
lut->setBlock(i, name, def->rt.id);
|
||||
|
||||
Reference in New Issue
Block a user