fix: missing pack.has_indices if content is not loaded
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user