migrate from std::filesystem::path to io::path (WIP)

This commit is contained in:
MihailRis
2025-01-30 22:23:13 +03:00
parent 1e22882284
commit e0314803c0
72 changed files with 1189 additions and 791 deletions
+89 -87
View File
@@ -43,55 +43,57 @@ ContentLoader::ContentLoader(
}
static void detect_defs(
const fs::path& folder,
const io::path& folder,
const std::string& prefix,
std::vector<std::string>& detected
) {
if (fs::is_directory(folder)) {
for (const auto& entry : fs::directory_iterator(folder)) {
const fs::path& file = entry.path();
std::string name = file.stem().string();
if (name[0] == '_') {
continue;
}
if (fs::is_regular_file(file) && io::is_data_file(file)) {
auto map = io::read_object(file);
std::string id = prefix.empty() ? name : prefix + ":" + name;
detected.emplace_back(id);
} else if (fs::is_directory(file) &&
file.extension() != fs::u8path(".files")) {
detect_defs(file, name, detected);
}
if (!io::is_directory(folder)) {
return;
}
for (const auto& entry : std::filesystem::directory_iterator(io::resolve(folder))) {
io::path file = folder / entry.path().filename().u8string();
std::string name = file.stem();
if (name[0] == '_') {
continue;
}
if (io::is_regular_file(file) && io::is_data_file(file)) {
auto map = io::read_object(file);
std::string id = prefix.empty() ? name : prefix + ":" + name;
detected.emplace_back(id);
} else if (io::is_directory(file) &&
file.extension() != fs::u8path(".files")) {
detect_defs(file, name, detected);
}
}
}
static void detect_defs_pairs(
const fs::path& folder,
const io::path& folder,
const std::string& prefix,
std::vector<std::tuple<std::string, std::string>>& detected
) {
if (fs::is_directory(folder)) {
for (const auto& entry : fs::directory_iterator(folder)) {
const fs::path& file = entry.path();
std::string name = file.stem().string();
if (name[0] == '_') {
continue;
}
if (fs::is_regular_file(file) && io::is_data_file(file)) {
try {
auto map = io::read_object(file);
auto id = prefix.empty() ? name : prefix + ":" + name;
auto caption = util::id_to_caption(id);
map.at("caption").get(caption);
detected.emplace_back(id, name);
} catch (const std::runtime_error& err) {
logger.error() << err.what();
}
} else if (fs::is_directory(file) &&
file.extension() != fs::u8path(".files")) {
detect_defs_pairs(file, name, detected);
if (!io::is_directory(folder)) {
return;
}
for (const auto& entry : fs::directory_iterator(io::resolve(folder))) {
io::path file = folder / entry.path().filename().u8string();
std::string name = file.stem();
if (name[0] == '_') {
continue;
}
if (io::is_regular_file(file) && io::is_data_file(file)) {
try {
auto map = io::read_object(file);
auto id = prefix.empty() ? name : prefix + ":" + name;
auto caption = util::id_to_caption(id);
map.at("caption").get(caption);
detected.emplace_back(id, name);
} catch (const std::runtime_error& err) {
logger.error() << err.what();
}
} else if (io::is_directory(file) &&
file.extension() != fs::u8path(".files")) {
detect_defs_pairs(file, name, detected);
}
}
}
@@ -106,7 +108,7 @@ std::vector<std::tuple<std::string, std::string>> ContentLoader::scanContent(
}
bool ContentLoader::fixPackIndices(
const fs::path& folder,
const io::path& folder,
dv::value& indicesRoot,
const std::string& contentSection
) {
@@ -146,7 +148,7 @@ void ContentLoader::fixPackIndices() {
auto entitiesFolder = folder / ContentPack::ENTITIES_FOLDER;
dv::value root;
if (fs::is_regular_file(contentFile)) {
if (io::is_regular_file(contentFile)) {
root = io::read_json(contentFile);
} else {
root = dv::object();
@@ -213,7 +215,7 @@ static void process_method(
}
void ContentLoader::loadBlock(
Block& def, const std::string& name, const fs::path& file
Block& def, const std::string& name, const io::path& file
) {
auto root = io::read_json(file);
if (def.properties == nullptr) {
@@ -402,7 +404,7 @@ void ContentLoader::loadBlock(
}
void ContentLoader::loadItem(
ItemDef& def, const std::string& name, const fs::path& file
ItemDef& def, const std::string& name, const io::path& file
) {
auto root = io::read_json(file);
def.properties = root;
@@ -446,7 +448,7 @@ void ContentLoader::loadItem(
}
void ContentLoader::loadEntity(
EntityDef& def, const std::string& name, const fs::path& file
EntityDef& def, const std::string& name, const io::path& file
) {
auto root = io::read_json(file);
@@ -518,16 +520,16 @@ void ContentLoader::loadEntity(
EntityDef& def, const std::string& full, const std::string& name
) {
auto folder = pack->folder;
auto configFile = folder / fs::path("entities/" + name + ".json");
if (fs::exists(configFile)) loadEntity(def, full, configFile);
auto configFile = folder / ("entities/" + name + ".json");
if (io::exists(configFile)) loadEntity(def, full, configFile);
}
void ContentLoader::loadBlock(
Block& def, const std::string& full, const std::string& name
) {
auto folder = pack->folder;
auto configFile = folder / fs::path("blocks/" + name + ".json");
if (fs::exists(configFile)) loadBlock(def, full, configFile);
auto configFile = folder / ("blocks/" + name + ".json");
if (io::exists(configFile)) loadBlock(def, full, configFile);
if (!def.hidden) {
bool created;
@@ -549,8 +551,8 @@ void ContentLoader::loadItem(
ItemDef& def, const std::string& full, const std::string& name
) {
auto folder = pack->folder;
auto configFile = folder / fs::path("items/" + name + ".json");
if (fs::exists(configFile)) loadItem(def, full, configFile);
auto configFile = folder / ("items/" + name + ".json");
if (io::exists(configFile)) loadItem(def, full, configFile);
}
static std::tuple<std::string, std::string, std::string> create_unit_id(
@@ -566,7 +568,7 @@ static std::tuple<std::string, std::string, std::string> create_unit_id(
}
void ContentLoader::loadBlockMaterial(
BlockMaterial& def, const fs::path& file
BlockMaterial& def, const io::path& file
) {
auto root = io::read_json(file);
root.at("steps-sound").get(def.stepsSound);
@@ -577,9 +579,9 @@ void ContentLoader::loadBlockMaterial(
void ContentLoader::loadContent(const dv::value& root) {
std::vector<std::pair<std::string, std::string>> pendingDefs;
auto getJsonParent = [this](const std::string& prefix, const std::string& name) {
auto configFile = pack->folder / fs::path(prefix + "/" + name + ".json");
auto configFile = pack->folder / (prefix + "/" + name + ".json");
std::string parent;
if (fs::exists(configFile)) {
if (io::exists(configFile)) {
auto root = io::read_json(configFile);
root.at("parent").get(parent);
}
@@ -740,16 +742,17 @@ void ContentLoader::loadContent(const dv::value& root) {
}
static inline void foreach_file(
const fs::path& dir, std::function<void(const fs::path&)> handler
const io::path& dir, std::function<void(const io::path&)> handler
) {
if (fs::is_directory(dir)) {
for (const auto& entry : fs::directory_iterator(dir)) {
const auto& path = entry.path();
if (fs::is_directory(path)) {
continue;
}
handler(path);
if (!io::is_directory(dir)) {
return;
}
for (const auto& entry : fs::directory_iterator(io::resolve(dir))) {
io::path path = dir / entry.path().filename().u8string();
if (io::is_directory(path)) {
continue;
}
handler(path);
}
}
@@ -761,11 +764,10 @@ void ContentLoader::load() {
auto folder = pack->folder;
// Load world generators
fs::path generatorsDir = folder / fs::u8path("generators");
foreach_file(generatorsDir, [this](const fs::path& file) {
std::string name = file.stem().u8string();
auto [packid, full, filename] =
create_unit_id(pack->id, file.stem().u8string());
io::path generatorsDir = folder / fs::u8path("generators");
foreach_file(generatorsDir, [this](const io::path& file) {
std::string name = file.stem();
auto [packid, full, filename] = create_unit_id(pack->id, name);
auto& def = builder.generators.create(full);
try {
@@ -776,8 +778,8 @@ void ContentLoader::load() {
});
// Load pack resources.json
fs::path resourcesFile = folder / fs::u8path("resources.json");
if (fs::exists(resourcesFile)) {
io::path resourcesFile = folder / "resources.json";
if (io::exists(resourcesFile)) {
auto resRoot = io::read_json(resourcesFile);
for (const auto& [key, arr] : resRoot.asObject()) {
if (auto resType = ResourceType_from(key)) {
@@ -790,8 +792,8 @@ void ContentLoader::load() {
}
// Load pack resources aliases
fs::path aliasesFile = folder / fs::u8path("resource-aliases.json");
if (fs::exists(aliasesFile)) {
io::path aliasesFile = folder / "resource-aliases.json";
if (io::exists(aliasesFile)) {
auto resRoot = io::read_json(aliasesFile);
for (const auto& [key, arr] : resRoot.asObject()) {
if (auto resType = ResourceType_from(key)) {
@@ -804,32 +806,32 @@ void ContentLoader::load() {
}
// Load block materials
fs::path materialsDir = folder / fs::u8path("block_materials");
if (fs::is_directory(materialsDir)) {
for (const auto& entry : fs::directory_iterator(materialsDir)) {
const auto& file = entry.path();
io::path materialsDir = folder / "block_materials";
if (io::is_directory(materialsDir)) {
for (const auto& entry : fs::directory_iterator(io::resolve(materialsDir))) {
io::path file = materialsDir / entry.path().filename().u8string();
auto [packid, full, filename] =
create_unit_id(pack->id, file.stem().u8string());
create_unit_id(pack->id, file.stem());
loadBlockMaterial(
builder.createBlockMaterial(full),
materialsDir / fs::u8path(filename + ".json")
materialsDir / (filename + ".json")
);
}
}
// Load skeletons
fs::path skeletonsDir = folder / fs::u8path("skeletons");
foreach_file(skeletonsDir, [this](const fs::path& file) {
std::string name = pack->id + ":" + file.stem().u8string();
io::path skeletonsDir = folder / fs::u8path("skeletons");
foreach_file(skeletonsDir, [this](const io::path& file) {
std::string name = pack->id + ":" + file.stem();
std::string text = io::read_string(file);
builder.add(
rigging::SkeletonConfig::parse(text, file.u8string(), name)
rigging::SkeletonConfig::parse(text, file.string(), name)
);
});
// Process content.json and load defined content units
auto contentFile = pack->getContentFile();
if (fs::exists(contentFile)) {
if (io::exists(contentFile)) {
loadContent(io::read_json(contentFile));
}
}
@@ -844,8 +846,8 @@ static void load_scripts(Content& content, ContentUnitDefs<T>& units) {
const auto runtime = content.getPackRuntime(name.substr(0, pos));
const auto& pack = runtime->getInfo();
const auto& folder = pack.folder;
auto scriptfile = folder / fs::path("scripts/" + def->scriptName + ".lua");
if (fs::is_regular_file(scriptfile)) {
auto scriptfile = folder / ("scripts/" + def->scriptName + ".lua");
if (io::is_regular_file(scriptfile)) {
scripting::load_content_script(
runtime->getEnvironment(),
name,
@@ -866,8 +868,8 @@ void ContentLoader::loadScripts(Content& content) {
const auto& folder = pack.folder;
// Load main world script
fs::path scriptFile = folder / fs::path("scripts/world.lua");
if (fs::is_regular_file(scriptFile)) {
io::path scriptFile = folder / "scripts/world.lua";
if (io::is_regular_file(scriptFile)) {
scripting::load_world_script(
runtime->getEnvironment(),
pack.id,
@@ -877,13 +879,13 @@ void ContentLoader::loadScripts(Content& content) {
);
}
// Load entity components
fs::path componentsDir = folder / fs::u8path("scripts/components");
foreach_file(componentsDir, [&pack](const fs::path& file) {
auto name = pack.id + ":" + file.stem().u8string();
io::path componentsDir = folder / fs::u8path("scripts/components");
foreach_file(componentsDir, [&pack](const io::path& file) {
auto name = pack.id + ":" + file.stem();
scripting::load_entity_component(
name,
file,
pack.id + ":scripts/components/" + file.filename().u8string()
pack.id + ":scripts/components/" + file.name()
);
});
}
+6 -8
View File
@@ -1,14 +1,12 @@
#pragma once
#include <filesystem>
#include <memory>
#include <string>
#include "io/io.hpp"
#include "content_fwd.hpp"
#include "data/dv.hpp"
namespace fs = std::filesystem;
class Block;
struct BlockMaterial;
struct ItemDef;
@@ -43,15 +41,15 @@ class ContentLoader {
GeneratorDef& def, const std::string& full, const std::string& name
);
static void loadBlockMaterial(BlockMaterial& def, const fs::path& file);
static void loadBlockMaterial(BlockMaterial& def, const io::path& file);
void loadBlock(
Block& def, const std::string& name, const fs::path& file
Block& def, const std::string& name, const io::path& file
);
void loadItem(
ItemDef& def, const std::string& name, const fs::path& file
ItemDef& def, const std::string& name, const io::path& file
);
void loadEntity(
EntityDef& def, const std::string& name, const fs::path& file
EntityDef& def, const std::string& name, const io::path& file
);
void loadResources(ResourceType type, const dv::value& list);
void loadResourceAliases(ResourceType type, const dv::value& aliases);
@@ -66,7 +64,7 @@ public:
// Refresh pack content.json
static bool fixPackIndices(
const fs::path& folder,
const io::path& folder,
dv::value& indicesRoot,
const std::string& contentSection
);
+27 -27
View File
@@ -15,7 +15,7 @@ namespace fs = std::filesystem;
ContentPack ContentPack::createCore(const EnginePaths& paths) {
return ContentPack {
"core", "Core", ENGINE_VERSION_STRING, "", "", paths.getResourcesFolder(), "res:", {}
"core", "Core", ENGINE_VERSION_STRING, "", "", "res:", "res:", {}
};
}
@@ -23,7 +23,7 @@ const std::vector<std::string> ContentPack::RESERVED_NAMES = {
"res", "abs", "local", "core", "user", "world", "none", "null"};
contentpack_error::contentpack_error(
std::string packId, fs::path folder, const std::string& message
std::string packId, io::path folder, const std::string& message
)
: std::runtime_error(message),
packId(std::move(packId)),
@@ -33,19 +33,19 @@ contentpack_error::contentpack_error(
std::string contentpack_error::getPackId() const {
return packId;
}
fs::path contentpack_error::getFolder() const {
io::path contentpack_error::getFolder() const {
return folder;
}
fs::path ContentPack::getContentFile() const {
return folder / fs::path(CONTENT_FILENAME);
io::path ContentPack::getContentFile() const {
return folder / CONTENT_FILENAME;
}
bool ContentPack::is_pack(const fs::path& folder) {
return fs::is_regular_file(folder / fs::path(PACKAGE_FILENAME));
bool ContentPack::is_pack(const io::path& folder) {
return io::is_regular_file(folder / PACKAGE_FILENAME);
}
static void checkContentPackId(const std::string& id, const fs::path& folder) {
static void checkContentPackId(const std::string& id, const io::path& folder) {
if (id.length() < 2 || id.length() > 24)
throw contentpack_error(
id, folder, "content-pack id length is out of range [2, 24]"
@@ -70,8 +70,8 @@ static void checkContentPackId(const std::string& id, const fs::path& folder) {
}
}
ContentPack ContentPack::read(const std::string& path, const fs::path& folder) {
auto root = io::read_json(folder / fs::path(PACKAGE_FILENAME));
ContentPack ContentPack::read(const std::string& path, const io::path& folder) {
auto root = io::read_json(folder / PACKAGE_FILENAME);
ContentPack pack;
root.at("id").get(pack.id);
root.at("title").get(pack.title);
@@ -124,21 +124,21 @@ ContentPack ContentPack::read(const std::string& path, const fs::path& folder) {
}
void ContentPack::scanFolder(
const std::string& path, const fs::path& folder, std::vector<ContentPack>& packs
const std::string& path, const io::path& folder, std::vector<ContentPack>& packs
) {
if (!fs::is_directory(folder)) {
if (!io::is_directory(folder)) {
return;
}
for (const auto& entry : fs::directory_iterator(folder)) {
const fs::path& packFolder = entry.path();
if (!fs::is_directory(packFolder)) continue;
for (const auto& entry : fs::directory_iterator(io::resolve(folder))) {
io::path packFolder = folder / entry.path().filename().u8string();
if (!io::is_directory(packFolder)) continue;
if (!is_pack(packFolder)) continue;
try {
packs.push_back(
read(path + "/" + packFolder.filename().string(), packFolder)
read(path + "/" + packFolder.name(), packFolder)
);
} catch (const contentpack_error& err) {
std::cerr << "package.json error at " << err.getFolder().u8string();
std::cerr << "package.json error at " << err.getFolder().string();
std::cerr << ": " << err.what() << std::endl;
} catch (const std::runtime_error& err) {
std::cerr << err.what() << std::endl;
@@ -146,26 +146,26 @@ void ContentPack::scanFolder(
}
}
std::vector<std::string> ContentPack::worldPacksList(const fs::path& folder) {
fs::path listfile = folder / fs::path("packs.list");
if (!fs::is_regular_file(listfile)) {
std::vector<std::string> ContentPack::worldPacksList(const io::path& folder) {
io::path listfile = folder / "packs.list";
if (!io::is_regular_file(listfile)) {
throw std::runtime_error("missing file 'packs.list'");
}
return io::read_list(listfile);
}
fs::path ContentPack::findPack(
const EnginePaths* paths, const fs::path& worldDir, const std::string& name
io::path ContentPack::findPack(
const EnginePaths* paths, const io::path& worldDir, const std::string& name
) {
fs::path folder = worldDir / fs::path("content") / fs::path(name);
if (fs::is_directory(folder)) {
io::path folder = worldDir / "content" / name;
if (io::is_directory(folder)) {
return folder;
}
folder = paths->getUserFilesFolder() / fs::path("content") / fs::path(name);
if (fs::is_directory(folder)) {
folder = io::path("user:content") / name;
if (io::is_directory(folder)) {
return folder;
}
return paths->getResourcesFolder() / fs::path("content") / fs::path(name);
return io::path("res:content") / name;
}
ContentPackRuntime::ContentPackRuntime(ContentPack info, scriptenv env)
+19 -19
View File
@@ -1,27 +1,27 @@
#pragma once
#include <filesystem>
#include <stdexcept>
#include <string>
#include <vector>
#include "typedefs.hpp"
#include "content_fwd.hpp"
#include "io/io.hpp"
class EnginePaths;
class contentpack_error : public std::runtime_error {
std::string packId;
std::filesystem::path folder;
io::path folder;
public:
contentpack_error(
std::string packId,
std::filesystem::path folder,
io::path folder,
const std::string& message
);
std::string getPackId() const;
std::filesystem::path getFolder() const;
io::path getFolder() const;
};
enum class DependencyLevel {
@@ -42,52 +42,52 @@ struct ContentPack {
std::string version = "0.0";
std::string creator = "";
std::string description = "no description";
std::filesystem::path folder;
io::path folder;
std::string path;
std::vector<DependencyPack> dependencies;
std::string source = "";
std::filesystem::path getContentFile() const;
io::path getContentFile() const;
static inline const std::string PACKAGE_FILENAME = "package.json";
static inline const std::string CONTENT_FILENAME = "content.json";
static inline const std::filesystem::path BLOCKS_FOLDER = "blocks";
static inline const std::filesystem::path ITEMS_FOLDER = "items";
static inline const std::filesystem::path ENTITIES_FOLDER = "entities";
static inline const std::filesystem::path GENERATORS_FOLDER = "generators";
static inline const io::path BLOCKS_FOLDER = "blocks";
static inline const io::path ITEMS_FOLDER = "items";
static inline const io::path ENTITIES_FOLDER = "entities";
static inline const io::path GENERATORS_FOLDER = "generators";
static const std::vector<std::string> RESERVED_NAMES;
static bool is_pack(const std::filesystem::path& folder);
static bool is_pack(const io::path& folder);
static ContentPack read(
const std::string& path, const std::filesystem::path& folder
const std::string& path, const io::path& folder
);
static void scanFolder(
const std::string& path,
const std::filesystem::path& folder,
const io::path& folder,
std::vector<ContentPack>& packs
);
static std::vector<std::string> worldPacksList(
const std::filesystem::path& folder
const io::path& folder
);
static std::filesystem::path findPack(
static io::path findPack(
const EnginePaths* paths,
const std::filesystem::path& worldDir,
const io::path& worldDir,
const std::string& name
);
static ContentPack createCore(const EnginePaths&);
static inline std::filesystem::path getFolderFor(ContentType type) {
static inline io::path getFolderFor(ContentType type) {
switch (type) {
case ContentType::BLOCK: return ContentPack::BLOCKS_FOLDER;
case ContentType::ITEM: return ContentPack::ITEMS_FOLDER;
case ContentType::ENTITY: return ContentPack::ENTITIES_FOLDER;
case ContentType::GENERATOR: return ContentPack::GENERATORS_FOLDER;
case ContentType::NONE: return std::filesystem::u8path("");
default: return std::filesystem::u8path("");
case ContentType::NONE: return "";
default: return "";
}
}
};
+1 -1
View File
@@ -67,7 +67,7 @@ static void process_blocks_data(
std::shared_ptr<ContentReport> ContentReport::create(
const std::shared_ptr<WorldFiles>& worldFiles,
const fs::path& filename,
const io::path& filename,
const Content* content
) {
auto worldInfo = worldFiles->readWorldInfo();
+2 -3
View File
@@ -1,6 +1,5 @@
#pragma once
#include <filesystem>
#include <string>
#include <utility>
#include <vector>
@@ -10,10 +9,10 @@
#include "data/dv.hpp"
#include "typedefs.hpp"
#include "Content.hpp"
#include "io/io.hpp"
#include "data/StructLayout.hpp"
#include "world/files/world_regions_fwd.hpp"
namespace fs = std::filesystem;
enum class ContentIssueType {
REORDER,
@@ -139,7 +138,7 @@ public:
static std::shared_ptr<ContentReport> create(
const std::shared_ptr<WorldFiles>& worldFiles,
const fs::path& filename,
const io::path& filename,
const Content* content
);
+4 -4
View File
@@ -7,7 +7,7 @@
PacksManager::PacksManager() = default;
void PacksManager::setSources(std::vector<std::pair<std::string, fs::path>> sources) {
void PacksManager::setSources(std::vector<std::pair<std::string, io::path>> sources) {
this->sources = std::move(sources);
}
@@ -42,7 +42,7 @@ std::vector<ContentPack> PacksManager::getAll(
for (auto& name : names) {
auto found = packs.find(name);
if (found == packs.end()) {
throw contentpack_error(name, fs::path(""), "pack not found");
throw contentpack_error(name, io::path(), "pack not found");
}
packsList.push_back(found->second);
}
@@ -92,7 +92,7 @@ static bool resolve_dependencies(
bool exists = found != packs.end();
if (!exists && dep.level == DependencyLevel::required) {
throw contentpack_error(
dep.id, fs::path(), "dependency of '" + pack->id + "'"
dep.id, io::path(), "dependency of '" + pack->id + "'"
);
}
if (!exists) {
@@ -127,7 +127,7 @@ std::vector<std::string> PacksManager::assemble(
for (auto& name : names) {
auto found = packs.find(name);
if (found == packs.end()) {
throw contentpack_error(name, fs::path(""), "pack not found");
throw contentpack_error(name, io::path(), "pack not found");
}
queue.push(&found->second);
}
+3 -5
View File
@@ -1,21 +1,19 @@
#pragma once
#include <filesystem>
#include <unordered_map>
#include <vector>
#include "io/io.hpp"
#include "ContentPack.hpp"
namespace fs = std::filesystem;
class PacksManager {
std::unordered_map<std::string, ContentPack> packs;
std::vector<std::pair<std::string, fs::path>> sources;
std::vector<std::pair<std::string, io::path>> sources;
public:
PacksManager();
/// @brief Set content packs sources (search folders)
void setSources(std::vector<std::pair<std::string, fs::path>> sources);
void setSources(std::vector<std::pair<std::string, io::path>> sources);
/// @brief Scan sources and collect all found packs excluding duplication.
/// Scanning order depends on sources order
+21 -21
View File
@@ -132,18 +132,18 @@ static VoxelStructureMeta load_structure_meta(
}
static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
const dv::value& map, const fs::path& filesFolder, const ResPaths& paths
const dv::value& map, const io::path& filesFolder, const ResPaths& paths
) {
auto structuresDir = filesFolder / fs::path("fragments");
auto structuresDir = filesFolder / "fragments";
std::vector<std::unique_ptr<VoxelStructure>> structures;
for (auto& [name, config] : map.asObject()) {
auto structFile = structuresDir / fs::u8path(name + ".vox");
structFile = paths.find(structFile.u8string());
logger.debug() << "loading voxel fragment " << structFile.u8string();
if (!fs::exists(structFile)) {
auto structFile = structuresDir / (name + ".vox");
structFile = paths.find(structFile.string());
logger.debug() << "loading voxel fragment " << structFile.string();
if (!io::exists(structFile)) {
throw std::runtime_error("structure file does not exist (" +
structFile.u8string());
structFile.string());
}
auto fragment = std::make_unique<VoxelFragment>();
fragment->deserialize(io::read_binary_json(structFile));
@@ -162,7 +162,7 @@ static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
static void load_structures(
GeneratorDef& def,
const dv::value& map,
const fs::path& filesFolder,
const io::path& filesFolder,
const ResPaths& paths
) {
auto rawStructures = load_structures(map, filesFolder, paths);
@@ -178,9 +178,9 @@ static void load_structures(
}
}
static inline const auto STRUCTURES_FILE = fs::u8path("structures.toml");
static inline const auto BIOMES_FILE = fs::u8path("biomes.toml");
static inline const auto GENERATORS_DIR = fs::u8path("generators");
static inline const io::path STRUCTURES_FILE = "structures.toml";
static inline const io::path BIOMES_FILE = "biomes.toml";
static inline const io::path GENERATORS_DIR = "generators";
static void load_biomes(GeneratorDef& def, const dv::value& root) {
for (const auto& [biomeName, biomeMap] : root.asObject()) {
@@ -198,11 +198,11 @@ void ContentLoader::loadGenerator(
) {
auto packDir = pack->folder;
auto generatorsDir = packDir / GENERATORS_DIR;
auto generatorFile = generatorsDir / fs::u8path(name + ".toml");
if (!fs::exists(generatorFile)) {
auto generatorFile = generatorsDir / (name + ".toml");
if (!io::exists(generatorFile)) {
return;
}
auto map = io::read_toml(generatorsDir / fs::u8path(name + ".toml"));
auto map = io::read_toml(generatorsDir / (name + ".toml"));
map.at("caption").get(def.caption);
map.at("biome-parameters").get(def.biomeParameters);
map.at("biome-bpd").get(def.biomesBPD);
@@ -233,15 +233,15 @@ void ContentLoader::loadGenerator(
logger.warning() << "generator has heightmap-inputs but biomes-bpd "
"is not equal to heights-bpd, generator will work slower!";
}
auto folder = generatorsDir / fs::u8path(name + ".files");
auto scriptFile = folder / fs::u8path("script.lua");
auto folder = generatorsDir / (name + ".files");
auto scriptFile = folder / "script.lua";
auto structuresFile = GENERATORS_DIR / fs::u8path(name + ".files") / STRUCTURES_FILE;
auto structuresMap = paths.readCombinedObject(structuresFile.u8string());
load_structures(def, structuresMap, structuresFile.parent_path(), paths);
auto structuresFile = GENERATORS_DIR / (name + ".files") / STRUCTURES_FILE;
auto structuresMap = paths.readCombinedObject(structuresFile.string());
load_structures(def, structuresMap, structuresFile.parent(), paths);
auto biomesFile = GENERATORS_DIR / fs::u8path(name + ".files") / BIOMES_FILE;
auto biomesMap = paths.readCombinedObject(biomesFile.u8string());
auto biomesFile = GENERATORS_DIR / (name + ".files") / BIOMES_FILE;
auto biomesMap = paths.readCombinedObject(biomesFile.string());
if (biomesMap.empty()) {
throw std::runtime_error(
"generator " + util::quote(def.name) +