make 'structures.toml' combined

This commit is contained in:
MihailRis
2024-11-28 13:41:59 +03:00
parent 31bf1f3432
commit bf9f6bbe79
+13 -9
View File
@@ -132,14 +132,14 @@ static VoxelStructureMeta load_structure_meta(
} }
static std::vector<std::unique_ptr<VoxelStructure>> load_structures( static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
const fs::path& structuresFile const dv::value& map, const fs::path& filesFolder, const ResPaths& paths
) { ) {
auto structuresDir = structuresFile.parent_path() / fs::path("fragments"); auto structuresDir = filesFolder / fs::path("fragments");
auto map = files::read_object(structuresFile);
std::vector<std::unique_ptr<VoxelStructure>> structures; std::vector<std::unique_ptr<VoxelStructure>> structures;
for (auto& [name, config] : map.asObject()) { for (auto& [name, config] : map.asObject()) {
auto structFile = structuresDir / fs::u8path(name + ".vox"); auto structFile = structuresDir / fs::u8path(name + ".vox");
structFile = paths.find(structFile.u8string());
logger.debug() << "loading voxel fragment " << structFile.u8string(); logger.debug() << "loading voxel fragment " << structFile.u8string();
if (!fs::exists(structFile)) { if (!fs::exists(structFile)) {
throw std::runtime_error("structure file does not exist (" + throw std::runtime_error("structure file does not exist (" +
@@ -159,8 +159,13 @@ static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
return structures; return structures;
} }
static void load_structures(GeneratorDef& def, const fs::path& structuresFile) { static void load_structures(
auto rawStructures = load_structures(structuresFile); GeneratorDef& def,
const dv::value& map,
const fs::path& filesFolder,
const ResPaths& paths
) {
auto rawStructures = load_structures(map, filesFolder, paths);
def.structures.resize(rawStructures.size()); def.structures.resize(rawStructures.size());
for (int i = 0; i < rawStructures.size(); i++) { for (int i = 0; i < rawStructures.size(); i++) {
@@ -231,10 +236,9 @@ void ContentLoader::loadGenerator(
auto folder = generatorsDir / fs::u8path(name + ".files"); auto folder = generatorsDir / fs::u8path(name + ".files");
auto scriptFile = folder / fs::u8path("script.lua"); auto scriptFile = folder / fs::u8path("script.lua");
auto structuresFile = folder / STRUCTURES_FILE; auto structuresFile = GENERATORS_DIR / fs::u8path(name + ".files") / STRUCTURES_FILE;
if (fs::exists(structuresFile)) { auto structuresMap = paths.readCombinedObject(structuresFile.u8string());
load_structures(def, structuresFile); load_structures(def, structuresMap, structuresFile.parent_path(), paths);
}
auto biomesFile = GENERATORS_DIR / fs::u8path(name + ".files") / BIOMES_FILE; auto biomesFile = GENERATORS_DIR / fs::u8path(name + ".files") / BIOMES_FILE;
auto biomesMap = paths.readCombinedObject(biomesFile.u8string()); auto biomesMap = paths.readCombinedObject(biomesFile.u8string());