replace biomes.json with biomes.toml & make it combined object

This commit is contained in:
MihailRis
2024-10-13 21:50:39 +03:00
parent e7d7753d47
commit 7c56d8fd7f
12 changed files with 130 additions and 95 deletions
+26 -1
View File
@@ -255,7 +255,7 @@ std::vector<std::filesystem::path> ResPaths::listdir(
return entries;
}
dv::value ResPaths::readCombinedList(const std::string& filename) {
dv::value ResPaths::readCombinedList(const std::string& filename) const {
dv::value list = dv::list();
for (const auto& root : roots) {
auto path = root.path / fs::u8path(filename);
@@ -280,6 +280,31 @@ dv::value ResPaths::readCombinedList(const std::string& filename) {
return list;
}
dv::value ResPaths::readCombinedObject(const std::string& filename) const {
dv::value object = dv::object();
for (const auto& root : roots) {
auto path = root.path / fs::u8path(filename);
if (!fs::exists(path)) {
continue;
}
try {
auto value = files::read_object(path);
if (!value.isObject()) {
logger.warning()
<< "reading combined object " << root.name << ": "
<< filename << " is not an object (skipped)";
}
for (const auto& [key, element] : value.asObject()) {
object[key] = element;
}
} catch (const std::runtime_error& err) {
logger.warning() << "reading combined object " << root.name << ":"
<< filename << ": " << err.what();
}
}
return object;
}
const std::filesystem::path& ResPaths::getMainRoot() const {
return mainRoot;
}