fix: missing pack.has_indices if content is not loaded

This commit is contained in:
MihailRis
2025-07-13 15:36:09 +03:00
parent aca9b49c77
commit b02b454573
3 changed files with 40 additions and 11 deletions
+21
View File
@@ -9,7 +9,10 @@
#include "data/dv.hpp"
#include "io/engine_paths.hpp"
#include "io/io.hpp"
#include "coders/commons.hpp"
#include "debug/Logger.hpp"
static debug::Logger logger("content-pack");
namespace fs = std::filesystem;
@@ -47,6 +50,24 @@ bool ContentPack::is_pack(const io::path& folder) {
return io::is_regular_file(folder / PACKAGE_FILENAME);
}
std::optional<ContentPackStats> ContentPack::loadStats() const {
auto contentFile = getContentFile();
if (!io::exists(contentFile)) {
return std::nullopt;
}
dv::value object;
try {
object = io::read_object(contentFile);
} catch (const parsing_error& err) {
logger.error() << err.errorLog();
}
ContentPackStats stats {};
stats.totalBlocks = object.has("blocks") ? object["blocks"].size() : 0;
stats.totalItems = object.has("items") ? object["items"].size() : 0;
stats.totalEntities = object.has("entities") ? object["entities"].size() : 0;
return stats;
}
static void checkContentPackId(const std::string& id, const io::path& folder) {
if (id.length() < 2 || id.length() > 24)
throw contentpack_error(