Merge branch 'main' into heightmaps
This commit is contained in:
+187
-168
@@ -11,7 +11,6 @@
|
||||
#include "ContentPack.hpp"
|
||||
#include "coders/json.hpp"
|
||||
#include "core_defs.hpp"
|
||||
#include "data/dynamic.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "files/files.hpp"
|
||||
#include "items/ItemDef.hpp"
|
||||
@@ -21,6 +20,7 @@
|
||||
#include "util/listutil.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "data/dv_util.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -60,7 +60,7 @@ static void detect_defs(
|
||||
|
||||
bool ContentLoader::fixPackIndices(
|
||||
const fs::path& folder,
|
||||
dynamic::Map* indicesRoot,
|
||||
dv::value& indicesRoot,
|
||||
const std::string& contentSection
|
||||
) {
|
||||
std::vector<std::string> detected;
|
||||
@@ -68,25 +68,23 @@ bool ContentLoader::fixPackIndices(
|
||||
|
||||
std::vector<std::string> indexed;
|
||||
bool modified = false;
|
||||
if (!indicesRoot->has(contentSection)) {
|
||||
indicesRoot->putList(contentSection);
|
||||
if (!indicesRoot.has(contentSection)) {
|
||||
indicesRoot.list(contentSection);
|
||||
}
|
||||
auto arr = indicesRoot->list(contentSection);
|
||||
if (arr) {
|
||||
for (uint i = 0; i < arr->size(); i++) {
|
||||
std::string name = arr->str(i);
|
||||
if (!util::contains(detected, name)) {
|
||||
arr->remove(i);
|
||||
i--;
|
||||
modified = true;
|
||||
continue;
|
||||
}
|
||||
indexed.push_back(name);
|
||||
auto& arr = indicesRoot[contentSection];
|
||||
for (size_t i = 0; i < arr.size(); i++) {
|
||||
const std::string& name = arr[i].asString();
|
||||
if (!util::contains(detected, name)) {
|
||||
arr.erase(i);
|
||||
i--;
|
||||
modified = true;
|
||||
continue;
|
||||
}
|
||||
indexed.push_back(name);
|
||||
}
|
||||
for (auto name : detected) {
|
||||
if (!util::contains(indexed, name)) {
|
||||
arr->put(name);
|
||||
arr.add(name);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
@@ -100,21 +98,21 @@ void ContentLoader::fixPackIndices() {
|
||||
auto itemsFolder = folder / ContentPack::ITEMS_FOLDER;
|
||||
auto entitiesFolder = folder / ContentPack::ENTITIES_FOLDER;
|
||||
|
||||
dynamic::Map_sptr root;
|
||||
dv::value root;
|
||||
if (fs::is_regular_file(indexFile)) {
|
||||
root = files::read_json(indexFile);
|
||||
} else {
|
||||
root = dynamic::create_map();
|
||||
root = dv::object();
|
||||
}
|
||||
|
||||
bool modified = false;
|
||||
modified |= fixPackIndices(blocksFolder, root.get(), "blocks");
|
||||
modified |= fixPackIndices(itemsFolder, root.get(), "items");
|
||||
modified |= fixPackIndices(entitiesFolder, root.get(), "entities");
|
||||
modified |= fixPackIndices(blocksFolder, root, "blocks");
|
||||
modified |= fixPackIndices(itemsFolder, root, "items");
|
||||
modified |= fixPackIndices(entitiesFolder, root, "entities");
|
||||
|
||||
if (modified) {
|
||||
// rewrite modified json
|
||||
files::write_json(indexFile, root.get());
|
||||
files::write_json(indexFile, root);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,9 +121,8 @@ void ContentLoader::loadBlock(
|
||||
) {
|
||||
auto root = files::read_json(file);
|
||||
|
||||
if (root->has("parent")) {
|
||||
std::string parentName;
|
||||
root->str("parent", parentName);
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
auto parentDef = this->builder.blocks.get(parentName);
|
||||
if (parentDef == nullptr) {
|
||||
throw std::runtime_error(
|
||||
@@ -135,29 +132,28 @@ void ContentLoader::loadBlock(
|
||||
parentDef->cloneTo(def);
|
||||
}
|
||||
|
||||
root->str("caption", def.caption);
|
||||
root.at("caption").get(def.caption);
|
||||
|
||||
// block texturing
|
||||
if (root->has("texture")) {
|
||||
std::string texture;
|
||||
root->str("texture", texture);
|
||||
if (root.has("texture")) {
|
||||
const auto& texture = root["texture"].asString();
|
||||
for (uint i = 0; i < 6; i++) {
|
||||
def.textureFaces[i] = texture;
|
||||
}
|
||||
} else if (root->has("texture-faces")) {
|
||||
auto texarr = root->list("texture-faces");
|
||||
} else if (root.has("texture-faces")) {
|
||||
const auto& texarr = root["texture-faces"];
|
||||
for (uint i = 0; i < 6; i++) {
|
||||
def.textureFaces[i] = texarr->str(i);
|
||||
def.textureFaces[i] = texarr[i].asString();
|
||||
}
|
||||
}
|
||||
|
||||
// block model
|
||||
std::string modelName;
|
||||
root->str("model", modelName);
|
||||
root.at("model").get(modelName);
|
||||
if (auto model = BlockModel_from(modelName)) {
|
||||
if (*model == BlockModel::custom) {
|
||||
if (root->has("model-primitives")) {
|
||||
loadCustomBlockModel(def, root->map("model-primitives").get());
|
||||
if (root.has("model-primitives")) {
|
||||
loadCustomBlockModel(def, root["model-primitives"]);
|
||||
} else {
|
||||
logger.error() << name << ": no 'model-primitives' found";
|
||||
}
|
||||
@@ -168,11 +164,12 @@ void ContentLoader::loadBlock(
|
||||
def.model = BlockModel::none;
|
||||
}
|
||||
|
||||
root->str("material", def.material);
|
||||
root.at("material").get(def.material);
|
||||
|
||||
// rotation profile
|
||||
std::string profile = "none";
|
||||
root->str("rotation", profile);
|
||||
root.at("rotation").get(profile);
|
||||
|
||||
def.rotatable = profile != "none";
|
||||
if (profile == BlockRotProfile::PIPE_NAME) {
|
||||
def.rotations = BlockRotProfile::PIPE;
|
||||
@@ -184,20 +181,29 @@ void ContentLoader::loadBlock(
|
||||
}
|
||||
|
||||
// block hitbox AABB [x, y, z, width, height, depth]
|
||||
auto boxarr = root->list("hitboxes");
|
||||
if (boxarr) {
|
||||
def.hitboxes.resize(boxarr->size());
|
||||
for (uint i = 0; i < boxarr->size(); i++) {
|
||||
auto box = boxarr->list(i);
|
||||
if (auto found = root.at("hitboxes")) {
|
||||
const auto& boxarr = *found;
|
||||
def.hitboxes.resize(boxarr.size());
|
||||
for (uint i = 0; i < boxarr.size(); i++) {
|
||||
const auto& box = boxarr[i];
|
||||
auto& hitboxesIndex = def.hitboxes[i];
|
||||
hitboxesIndex.a = glm::vec3(box->num(0), box->num(1), box->num(2));
|
||||
hitboxesIndex.b = glm::vec3(box->num(3), box->num(4), box->num(5));
|
||||
hitboxesIndex.a = glm::vec3(
|
||||
box[0].asNumber(), box[1].asNumber(), box[2].asNumber()
|
||||
);
|
||||
hitboxesIndex.b = glm::vec3(
|
||||
box[3].asNumber(), box[4].asNumber(), box[5].asNumber()
|
||||
);
|
||||
hitboxesIndex.b += hitboxesIndex.a;
|
||||
}
|
||||
} else if ((boxarr = root->list("hitbox"))) {
|
||||
} else if (auto found = root.at("hitbox")) {
|
||||
const auto& box = *found;
|
||||
AABB aabb;
|
||||
aabb.a = glm::vec3(boxarr->num(0), boxarr->num(1), boxarr->num(2));
|
||||
aabb.b = glm::vec3(boxarr->num(3), boxarr->num(4), boxarr->num(5));
|
||||
aabb.a = glm::vec3(
|
||||
box[0].asNumber(), box[1].asNumber(), box[2].asNumber()
|
||||
);
|
||||
aabb.b = glm::vec3(
|
||||
box[3].asNumber(), box[4].asNumber(), box[5].asNumber()
|
||||
);
|
||||
aabb.b += aabb.a;
|
||||
def.hitboxes = {aabb};
|
||||
} else if (!def.modelBoxes.empty()) {
|
||||
@@ -207,17 +213,19 @@ void ContentLoader::loadBlock(
|
||||
}
|
||||
|
||||
// block light emission [r, g, b] where r,g,b in range [0..15]
|
||||
if (auto emissionarr = root->list("emission")) {
|
||||
def.emission[0] = emissionarr->num(0);
|
||||
def.emission[1] = emissionarr->num(1);
|
||||
def.emission[2] = emissionarr->num(2);
|
||||
if (auto found = root.at("emission")) {
|
||||
const auto& emissionarr = *found;
|
||||
def.emission[0] = emissionarr[0].asNumber();
|
||||
def.emission[1] = emissionarr[1].asNumber();
|
||||
def.emission[2] = emissionarr[2].asNumber();
|
||||
}
|
||||
|
||||
// block size
|
||||
if (auto sizearr = root->list("size")) {
|
||||
def.size.x = sizearr->num(0);
|
||||
def.size.y = sizearr->num(1);
|
||||
def.size.z = sizearr->num(2);
|
||||
if (auto found = root.at("size")) {
|
||||
const auto& sizearr = *found;
|
||||
def.size.x = sizearr[0].asNumber();
|
||||
def.size.y = sizearr[1].asNumber();
|
||||
def.size.z = sizearr[2].asNumber();
|
||||
if (def.model == BlockModel::block &&
|
||||
(def.size.x != 1 || def.size.y != 1 || def.size.z != 1)) {
|
||||
def.model = BlockModel::aabb;
|
||||
@@ -226,22 +234,22 @@ void ContentLoader::loadBlock(
|
||||
}
|
||||
|
||||
// primitive properties
|
||||
root->flag("obstacle", def.obstacle);
|
||||
root->flag("replaceable", def.replaceable);
|
||||
root->flag("light-passing", def.lightPassing);
|
||||
root->flag("sky-light-passing", def.skyLightPassing);
|
||||
root->flag("shadeless", def.shadeless);
|
||||
root->flag("ambient-occlusion", def.ambientOcclusion);
|
||||
root->flag("breakable", def.breakable);
|
||||
root->flag("selectable", def.selectable);
|
||||
root->flag("grounded", def.grounded);
|
||||
root->flag("hidden", def.hidden);
|
||||
root->num("draw-group", def.drawGroup);
|
||||
root->str("picking-item", def.pickingItem);
|
||||
root->str("script-name", def.scriptName);
|
||||
root->str("ui-layout", def.uiLayout);
|
||||
root->num("inventory-size", def.inventorySize);
|
||||
root->num("tick-interval", def.tickInterval);
|
||||
root.at("obstacle").get(def.obstacle);
|
||||
root.at("replaceable").get(def.replaceable);
|
||||
root.at("light-passing").get(def.lightPassing);
|
||||
root.at("sky-light-passing").get(def.skyLightPassing);
|
||||
root.at("shadeless").get(def.shadeless);
|
||||
root.at("ambient-occlusion").get(def.ambientOcclusion);
|
||||
root.at("breakable").get(def.breakable);
|
||||
root.at("selectable").get(def.selectable);
|
||||
root.at("grounded").get(def.grounded);
|
||||
root.at("hidden").get(def.hidden);
|
||||
root.at("draw-group").get(def.drawGroup);
|
||||
root.at("picking-item").get(def.pickingItem);
|
||||
root.at("script-name").get(def.scriptName);
|
||||
root.at("ui-layout").get(def.uiLayout);
|
||||
root.at("inventory-size").get(def.inventorySize);
|
||||
root.at("tick-interval").get(def.tickInterval);
|
||||
if (def.tickInterval == 0) {
|
||||
def.tickInterval = 1;
|
||||
}
|
||||
@@ -251,48 +259,57 @@ void ContentLoader::loadBlock(
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
|
||||
if (primitives->has("aabbs")) {
|
||||
auto modelboxes = primitives->list("aabbs");
|
||||
for (uint i = 0; i < modelboxes->size(); i++) {
|
||||
/* Parse aabb */
|
||||
auto boxarr = modelboxes->list(i);
|
||||
void ContentLoader::loadCustomBlockModel(Block& def, const dv::value& primitives) {
|
||||
if (primitives.has("aabbs")) {
|
||||
const auto& modelboxes = primitives["aabbs"];
|
||||
for (uint i = 0; i < modelboxes.size(); i++) {
|
||||
// Parse aabb
|
||||
const auto& boxarr = modelboxes[i];
|
||||
AABB modelbox;
|
||||
modelbox.a =
|
||||
glm::vec3(boxarr->num(0), boxarr->num(1), boxarr->num(2));
|
||||
modelbox.b =
|
||||
glm::vec3(boxarr->num(3), boxarr->num(4), boxarr->num(5));
|
||||
modelbox.a = glm::vec3(
|
||||
boxarr[0].asNumber(), boxarr[1].asNumber(), boxarr[2].asNumber()
|
||||
);
|
||||
modelbox.b = glm::vec3(
|
||||
boxarr[3].asNumber(), boxarr[4].asNumber(), boxarr[5].asNumber()
|
||||
);
|
||||
modelbox.b += modelbox.a;
|
||||
def.modelBoxes.push_back(modelbox);
|
||||
|
||||
if (boxarr->size() == 7)
|
||||
if (boxarr.size() == 7) {
|
||||
for (uint j = 6; j < 12; j++) {
|
||||
def.modelTextures.emplace_back(boxarr->str(6));
|
||||
def.modelTextures.emplace_back(boxarr[6].asString());
|
||||
}
|
||||
else if (boxarr->size() == 12)
|
||||
} else if (boxarr.size() == 12) {
|
||||
for (uint j = 6; j < 12; j++) {
|
||||
def.modelTextures.emplace_back(boxarr->str(j));
|
||||
def.modelTextures.emplace_back(boxarr[j].asString());
|
||||
}
|
||||
else
|
||||
} else {
|
||||
for (uint j = 6; j < 12; j++) {
|
||||
def.modelTextures.emplace_back("notfound");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (primitives->has("tetragons")) {
|
||||
auto modeltetragons = primitives->list("tetragons");
|
||||
for (uint i = 0; i < modeltetragons->size(); i++) {
|
||||
/* Parse tetragon to points */
|
||||
auto tgonobj = modeltetragons->list(i);
|
||||
glm::vec3 p1(tgonobj->num(0), tgonobj->num(1), tgonobj->num(2)),
|
||||
xw(tgonobj->num(3), tgonobj->num(4), tgonobj->num(5)),
|
||||
yh(tgonobj->num(6), tgonobj->num(7), tgonobj->num(8));
|
||||
if (primitives.has("tetragons")) {
|
||||
const auto& modeltetragons = primitives["tetragons"];
|
||||
for (uint i = 0; i < modeltetragons.size(); i++) {
|
||||
// Parse tetragon to points
|
||||
const auto& tgonobj = modeltetragons[i];
|
||||
glm::vec3 p1(
|
||||
tgonobj[0].asNumber(), tgonobj[1].asNumber(), tgonobj[2].asNumber()
|
||||
);
|
||||
glm::vec3 xw(
|
||||
tgonobj[3].asNumber(), tgonobj[4].asNumber(), tgonobj[5].asNumber()
|
||||
);
|
||||
glm::vec3 yh(
|
||||
tgonobj[6].asNumber(), tgonobj[7].asNumber(), tgonobj[8].asNumber()
|
||||
);
|
||||
def.modelExtraPoints.push_back(p1);
|
||||
def.modelExtraPoints.push_back(p1 + xw);
|
||||
def.modelExtraPoints.push_back(p1 + xw + yh);
|
||||
def.modelExtraPoints.push_back(p1 + yh);
|
||||
|
||||
def.modelTextures.emplace_back(tgonobj->str(9));
|
||||
def.modelTextures.emplace_back(tgonobj[9].asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,9 +319,8 @@ void ContentLoader::loadItem(
|
||||
) {
|
||||
auto root = files::read_json(file);
|
||||
|
||||
if (root->has("parent")) {
|
||||
std::string parentName;
|
||||
root->str("parent", parentName);
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
auto parentDef = this->builder.items.get(parentName);
|
||||
if (parentDef == nullptr) {
|
||||
throw std::runtime_error(
|
||||
@@ -313,11 +329,10 @@ void ContentLoader::loadItem(
|
||||
}
|
||||
parentDef->cloneTo(def);
|
||||
}
|
||||
|
||||
root->str("caption", def.caption);
|
||||
root.at("caption").get(def.caption);
|
||||
|
||||
std::string iconTypeStr = "";
|
||||
root->str("icon-type", iconTypeStr);
|
||||
root.at("icon-type").get(iconTypeStr);
|
||||
if (iconTypeStr == "none") {
|
||||
def.iconType = item_icon_type::none;
|
||||
} else if (iconTypeStr == "block") {
|
||||
@@ -327,16 +342,17 @@ void ContentLoader::loadItem(
|
||||
} else if (iconTypeStr.length()) {
|
||||
logger.error() << name << ": unknown icon type" << iconTypeStr;
|
||||
}
|
||||
root->str("icon", def.icon);
|
||||
root->str("placing-block", def.placingBlock);
|
||||
root->str("script-name", def.scriptName);
|
||||
root->num("stack-size", def.stackSize);
|
||||
root.at("icon").get(def.icon);
|
||||
root.at("placing-block").get(def.placingBlock);
|
||||
root.at("script-name").get(def.scriptName);
|
||||
root.at("stack-size").get(def.stackSize);
|
||||
|
||||
// item light emission [r, g, b] where r,g,b in range [0..15]
|
||||
if (auto emissionarr = root->list("emission")) {
|
||||
def.emission[0] = emissionarr->num(0);
|
||||
def.emission[1] = emissionarr->num(1);
|
||||
def.emission[2] = emissionarr->num(2);
|
||||
if (auto found = root.at("emission")) {
|
||||
const auto& emissionarr = *found;
|
||||
def.emission[0] = emissionarr[0].asNumber();
|
||||
def.emission[1] = emissionarr[1].asNumber();
|
||||
def.emission[2] = emissionarr[2].asNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,9 +361,8 @@ void ContentLoader::loadEntity(
|
||||
) {
|
||||
auto root = files::read_json(file);
|
||||
|
||||
if (root->has("parent")) {
|
||||
std::string parentName;
|
||||
root->str("parent", parentName);
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
auto parentDef = this->builder.entities.get(parentName);
|
||||
if (parentDef == nullptr) {
|
||||
throw std::runtime_error(
|
||||
@@ -357,54 +372,57 @@ void ContentLoader::loadEntity(
|
||||
parentDef->cloneTo(def);
|
||||
}
|
||||
|
||||
if (auto componentsarr = root->list("components")) {
|
||||
for (size_t i = 0; i < componentsarr->size(); i++) {
|
||||
def.components.emplace_back(componentsarr->str(i));
|
||||
if (auto found = root.at("components")) {
|
||||
for (const auto& elem : *found) {
|
||||
def.components.emplace_back(elem.asString());
|
||||
}
|
||||
}
|
||||
if (auto boxarr = root->list("hitbox")) {
|
||||
def.hitbox = glm::vec3(boxarr->num(0), boxarr->num(1), boxarr->num(2));
|
||||
if (auto found = root.at("hitbox")) {
|
||||
const auto& arr = *found;
|
||||
def.hitbox = glm::vec3(
|
||||
arr[0].asNumber(), arr[1].asNumber(), arr[2].asNumber()
|
||||
);
|
||||
}
|
||||
if (auto sensorsarr = root->list("sensors")) {
|
||||
for (size_t i = 0; i < sensorsarr->size(); i++) {
|
||||
if (auto sensorarr = sensorsarr->list(i)) {
|
||||
auto sensorType = sensorarr->str(0);
|
||||
if (sensorType == "aabb") {
|
||||
def.boxSensors.emplace_back(
|
||||
i,
|
||||
AABB {
|
||||
{sensorarr->num(1),
|
||||
sensorarr->num(2),
|
||||
sensorarr->num(3)},
|
||||
{sensorarr->num(4),
|
||||
sensorarr->num(5),
|
||||
sensorarr->num(6)}
|
||||
}
|
||||
);
|
||||
} else if (sensorType == "radius") {
|
||||
def.radialSensors.emplace_back(i, sensorarr->num(1));
|
||||
} else {
|
||||
logger.error()
|
||||
<< name << ": sensor #" << i << " - unknown type "
|
||||
<< util::quote(sensorType);
|
||||
}
|
||||
if (auto found = root.at("sensors")) {
|
||||
const auto& arr = *found;
|
||||
for (size_t i = 0; i < arr.size(); i++) {
|
||||
const auto& sensorarr = arr[i];
|
||||
const auto& sensorType = sensorarr[0].asString();
|
||||
if (sensorType == "aabb") {
|
||||
def.boxSensors.emplace_back(
|
||||
i,
|
||||
AABB {
|
||||
{sensorarr[1].asNumber(),
|
||||
sensorarr[2].asNumber(),
|
||||
sensorarr[3].asNumber()},
|
||||
{sensorarr[4].asNumber(),
|
||||
sensorarr[5].asNumber(),
|
||||
sensorarr[6].asNumber()}
|
||||
}
|
||||
);
|
||||
} else if (sensorType == "radius") {
|
||||
def.radialSensors.emplace_back(i, sensorarr[1].asNumber());
|
||||
} else {
|
||||
logger.error()
|
||||
<< name << ": sensor #" << i << " - unknown type "
|
||||
<< util::quote(sensorType);
|
||||
}
|
||||
}
|
||||
}
|
||||
root->flag("save", def.save.enabled);
|
||||
root->flag("save-skeleton-pose", def.save.skeleton.pose);
|
||||
root->flag("save-skeleton-textures", def.save.skeleton.textures);
|
||||
root->flag("save-body-velocity", def.save.body.velocity);
|
||||
root->flag("save-body-settings", def.save.body.settings);
|
||||
root.at("save").get(def.save.enabled);
|
||||
root.at("save-skeleton-pose").get(def.save.skeleton.pose);
|
||||
root.at("save-skeleton-textures").get(def.save.skeleton.textures);
|
||||
root.at("save-body-velocity").get(def.save.body.velocity);
|
||||
root.at("save-body-settings").get(def.save.body.settings);
|
||||
|
||||
std::string bodyTypeName;
|
||||
root->str("body-type", bodyTypeName);
|
||||
root.at("body-type").get(bodyTypeName);
|
||||
if (auto bodyType = BodyType_from(bodyTypeName)) {
|
||||
def.bodyType = *bodyType;
|
||||
}
|
||||
|
||||
root->str("skeleton-name", def.skeletonName);
|
||||
root->flag("blocking", def.blocking);
|
||||
root.at("skeleton-name").get(def.skeletonName);
|
||||
root.at("blocking").get(def.blocking);
|
||||
}
|
||||
|
||||
void ContentLoader::loadEntity(
|
||||
@@ -482,9 +500,9 @@ void ContentLoader::loadBlockMaterial(
|
||||
BlockMaterial& def, const fs::path& file
|
||||
) {
|
||||
auto root = files::read_json(file);
|
||||
root->str("steps-sound", def.stepsSound);
|
||||
root->str("place-sound", def.placeSound);
|
||||
root->str("break-sound", def.breakSound);
|
||||
root.at("steps-sound").get(def.stepsSound);
|
||||
root.at("place-sound").get(def.placeSound);
|
||||
root.at("break-sound").get(def.breakSound);
|
||||
}
|
||||
|
||||
void ContentLoader::load() {
|
||||
@@ -529,7 +547,7 @@ void ContentLoader::load() {
|
||||
std::string parent;
|
||||
if (fs::exists(configFile)) {
|
||||
auto root = files::read_json(configFile);
|
||||
if (root->has("parent")) root->str("parent", parent);
|
||||
root.at("parent").get(parent);
|
||||
}
|
||||
return parent;
|
||||
};
|
||||
@@ -543,9 +561,10 @@ void ContentLoader::load() {
|
||||
return std::make_pair(full, new_name);
|
||||
};
|
||||
|
||||
if (auto blocksarr = root->list("blocks")) {
|
||||
for (size_t i = 0; i < blocksarr->size(); i++) {
|
||||
auto [full, name] = processName(blocksarr->str(i));
|
||||
if (auto found = root.at("blocks")) {
|
||||
const auto& blocksarr = *found;
|
||||
for (size_t i = 0; i < blocksarr.size(); i++) {
|
||||
auto [full, name] = processName(blocksarr[i].asString());
|
||||
auto parent = getJsonParent("blocks", name);
|
||||
if (parent.empty() || builder.blocks.get(parent)) {
|
||||
// No dependency or dependency already loaded/exists in another
|
||||
@@ -587,9 +606,10 @@ void ContentLoader::load() {
|
||||
}
|
||||
}
|
||||
|
||||
if (auto itemsarr = root->list("items")) {
|
||||
for (size_t i = 0; i < itemsarr->size(); i++) {
|
||||
auto [full, name] = processName(itemsarr->str(i));
|
||||
if (auto found = root.at("items")) {
|
||||
const auto& itemsarr = *found;
|
||||
for (size_t i = 0; i < itemsarr.size(); i++) {
|
||||
auto [full, name] = processName(itemsarr[i].asString());
|
||||
auto parent = getJsonParent("items", name);
|
||||
if (parent.empty() || builder.items.get(parent)) {
|
||||
// No dependency or dependency already loaded/exists in another
|
||||
@@ -631,9 +651,10 @@ void ContentLoader::load() {
|
||||
}
|
||||
}
|
||||
|
||||
if (auto entitiesarr = root->list("entities")) {
|
||||
for (size_t i = 0; i < entitiesarr->size(); i++) {
|
||||
auto [full, name] = processName(entitiesarr->str(i));
|
||||
if (auto found = root.at("entities")) {
|
||||
const auto& entitiesarr = *found;
|
||||
for (size_t i = 0; i < entitiesarr.size(); i++) {
|
||||
auto [full, name] = processName(entitiesarr[i].asString());
|
||||
auto parent = getJsonParent("entities", name);
|
||||
if (parent.empty() || builder.entities.get(parent)) {
|
||||
// No dependency or dependency already loaded/exists in another
|
||||
@@ -716,11 +737,9 @@ void ContentLoader::load() {
|
||||
fs::path resourcesFile = folder / fs::u8path("resources.json");
|
||||
if (fs::exists(resourcesFile)) {
|
||||
auto resRoot = files::read_json(resourcesFile);
|
||||
for (const auto& [key, _] : resRoot->values) {
|
||||
for (const auto& [key, arr] : resRoot.asObject()) {
|
||||
if (auto resType = ResourceType_from(key)) {
|
||||
if (auto arr = resRoot->list(key)) {
|
||||
loadResources(*resType, arr.get());
|
||||
}
|
||||
loadResources(*resType, arr);
|
||||
} else {
|
||||
logger.warning() << "unknown resource type: " << key;
|
||||
}
|
||||
@@ -728,10 +747,10 @@ void ContentLoader::load() {
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadResources(ResourceType type, dynamic::List* list) {
|
||||
for (size_t i = 0; i < list->size(); i++) {
|
||||
void ContentLoader::loadResources(ResourceType type, const dv::value& list) {
|
||||
for (size_t i = 0; i < list.size(); i++) {
|
||||
builder.resourceIndices[static_cast<size_t>(type)].add(
|
||||
pack->id + ":" + list->str(i), nullptr
|
||||
pack->id + ":" + list[i].asString(), nullptr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user