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) { : allNames(allNames), type(type) {
} }
T& create(const std::string& id) { T& create(const std::string& id, bool* created = nullptr) {
auto found = defs.find(id); auto found = defs.find(id);
if (found != defs.end()) { if (found != defs.end()) {
if (created) *created = false;
return *found->second; return *found->second;
} }
if (created) *created = true;
checkIdentifier(id); checkIdentifier(id);
allNames[id] = type; allNames[id] = type;
names.push_back(id); names.push_back(id);

View File

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