add file.read_combined_list(...)
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
#include <utility>
|
||||
|
||||
#include "WorldFiles.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
|
||||
static debug::Logger logger("engine-paths");
|
||||
|
||||
|
||||
/// @brief ENUM for accessing folder and file names
|
||||
@@ -258,6 +261,31 @@ std::vector<std::filesystem::path> ResPaths::listdir(
|
||||
return entries;
|
||||
}
|
||||
|
||||
dv::value ResPaths::readCombinedList(const std::string& filename) {
|
||||
dv::value list = dv::list();
|
||||
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.isList()) {
|
||||
logger.warning() << "reading combined list " << root.name << ":"
|
||||
<< filename << " is not a list (skipped)";
|
||||
continue;
|
||||
}
|
||||
for (const auto& elem : value) {
|
||||
list.add(elem);
|
||||
}
|
||||
} catch (const std::runtime_error& err) {
|
||||
logger.warning() << "reading combined list " << root.name << ":"
|
||||
<< filename << ": " << err.what();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
const std::filesystem::path& ResPaths::getMainRoot() const {
|
||||
return mainRoot;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include "data/dv.hpp"
|
||||
#include "content/ContentPack.hpp"
|
||||
|
||||
|
||||
@@ -63,6 +64,11 @@ public:
|
||||
std::vector<std::filesystem::path> listdir(const std::string& folder) const;
|
||||
std::vector<std::string> listdirRaw(const std::string& folder) const;
|
||||
|
||||
/// @brief Read all found list versions from all packs and combine into a
|
||||
/// single list. Invalid versions will be skipped with logging a warning
|
||||
/// @param file *.json file path relative to entry point
|
||||
dv::value readCombinedList(const std::string& file);
|
||||
|
||||
const std::filesystem::path& getMainRoot() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -63,8 +63,13 @@ namespace files {
|
||||
/// @brief Read JSON or BJSON file
|
||||
/// @param file *.json or *.bjson file
|
||||
dv::value read_json(const fs::path& file);
|
||||
|
||||
dv::value read_binary_json(const fs::path& file);
|
||||
|
||||
/// @brief Read TOML file
|
||||
/// @param file *.toml file
|
||||
dv::value read_toml(const fs::path& file);
|
||||
|
||||
std::vector<std::string> read_list(const fs::path& file);
|
||||
|
||||
bool is_data_file(const fs::path& file);
|
||||
|
||||
Reference in New Issue
Block a user