fix content stats

This commit is contained in:
MihailRis 2024-12-29 20:28:45 +03:00
parent 7132bb0758
commit 97eef3ef19
2 changed files with 24 additions and 15 deletions

View File

@ -35,11 +35,13 @@ public:
: allNames(allNames), type(type) {
}
T& create(const std::string& id) {
T& create(const std::string& id, bool* created = nullptr) {
auto found = defs.find(id);
if (found != defs.end()) {
if (created) *created = false;
return *found->second;
}
if (created) *created = true;
checkIdentifier(id);
allNames[id] = type;
names.push_back(id);

View File

@ -530,7 +530,8 @@ void ContentLoader::loadBlock(
if (fs::exists(configFile)) loadBlock(def, full, configFile);
if (!def.hidden) {
auto& item = builder.items.create(full + BLOCK_ITEM_SUFFIX);
bool created;
auto& item = builder.items.create(full + BLOCK_ITEM_SUFFIX, &created);
item.generated = true;
item.caption = def.caption;
item.iconType = ItemIconType::BLOCK;
@ -540,7 +541,7 @@ void ContentLoader::loadBlock(
for (uint j = 0; j < 4; j++) {
item.emission[j] = def.emission[j];
}
stats->totalItems++;
stats->totalItems += created;
}
}
@ -602,9 +603,10 @@ void ContentLoader::loadContent(const dv::value& root) {
if (parent.empty() || builder.blocks.get(parent)) {
// No dependency or dependency already loaded/exists in another
// content pack
auto& def = builder.blocks.create(full);
bool created;
auto& def = builder.blocks.create(full, &created);
loadBlock(def, full, name);
stats->totalBlocks++;
stats->totalBlocks += created;
} else {
// Dependency not loaded yet, add to pending items
pendingDefs.emplace_back(full, name);
@ -621,9 +623,10 @@ void ContentLoader::loadContent(const dv::value& root) {
if (builder.blocks.get(parent)) {
// Dependency resolved or parent exists in another pack,
// load the item
auto& def = builder.blocks.create(it->first);
bool created;
auto& def = builder.blocks.create(it->first, &created);
loadBlock(def, it->first, it->second);
stats->totalBlocks++;
stats->totalBlocks += created;
it = pendingDefs.erase(it); // Remove resolved item
progressMade = true;
} else {
@ -647,9 +650,10 @@ void ContentLoader::loadContent(const dv::value& root) {
if (parent.empty() || builder.items.get(parent)) {
// No dependency or dependency already loaded/exists in another
// content pack
auto& def = builder.items.create(full);
bool created;
auto& def = builder.items.create(full, &created);
loadItem(def, full, name);
stats->totalItems++;
stats->totalItems += created;
} else {
// Dependency not loaded yet, add to pending items
pendingDefs.emplace_back(full, name);
@ -666,9 +670,10 @@ void ContentLoader::loadContent(const dv::value& root) {
if (builder.items.get(parent)) {
// Dependency resolved or parent exists in another pack,
// load the item
auto& def = builder.items.create(it->first);
bool created;
auto& def = builder.items.create(it->first, &created);
loadItem(def, it->first, it->second);
stats->totalItems++;
stats->totalItems += created;
it = pendingDefs.erase(it); // Remove resolved item
progressMade = true;
} else {
@ -692,9 +697,10 @@ void ContentLoader::loadContent(const dv::value& root) {
if (parent.empty() || builder.entities.get(parent)) {
// No dependency or dependency already loaded/exists in another
// content pack
auto& def = builder.entities.create(full);
bool created;
auto& def = builder.entities.create(full, &created);
loadEntity(def, full, name);
stats->totalEntities++;
stats->totalEntities += created;
} else {
// Dependency not loaded yet, add to pending items
pendingDefs.emplace_back(full, name);
@ -711,9 +717,10 @@ void ContentLoader::loadContent(const dv::value& root) {
if (builder.entities.get(parent)) {
// Dependency resolved or parent exists in another pack,
// load the item
auto& def = builder.entities.create(it->first);
bool created;
auto& def = builder.entities.create(it->first, &created);
loadEntity(def, it->first, it->second);
stats->totalEntities++;
stats->totalEntities += created;
it = pendingDefs.erase(it); // Remove resolved item
progressMade = true;
} else {