diff --git a/SPID/include/LinkedDistribution.h b/SPID/include/LinkedDistribution.h index 930d2fb..c9827e5 100644 --- a/SPID/include/LinkedDistribution.h +++ b/SPID/include/LinkedDistribution.h @@ -64,6 +64,8 @@ namespace LinkedDistribution /// A raw linked item entries that should be processed. void LookupLinkedItems(RE::TESDataHandler* const dataHandler, INI::LinkedItemsVec& rawLinkedItems = INI::linkedItems); + void LogLinkedItemsLookup(); + /// /// Calculates DistributionSet for each linked form and calls a callback for each of them. /// @@ -72,12 +74,6 @@ namespace LinkedDistribution /// A callback to be called with each DistributionSet. This is supposed to do the actual distribution. void ForEachLinkedDistributionSet(const std::set& linkedForms, std::function callback); - /// - /// Iterates over each type of LinkedForms and calls a callback with each of them. - /// - template - void ForEachLinkedForms(Func&& func, const Args&&... args); - private: template DataVec
& LinkedFormsForForm(RE::TESForm* form, LinkedForms& linkedForms) const; @@ -92,6 +88,13 @@ namespace LinkedDistribution LinkedForms keywords{ RECORD::kKeyword }; LinkedForms factions{ RECORD::kFaction }; LinkedForms skins{ RECORD::kSkin }; + + /// + /// Iterates over each type of LinkedForms and calls a callback with each of them. + /// + template + void ForEachLinkedForms(Func&& func, const Args&&... args); + }; #pragma region Implementation diff --git a/SPID/src/LinkedDistribution.cpp b/SPID/src/LinkedDistribution.cpp index a1580a3..8c4799c 100644 --- a/SPID/src/LinkedDistribution.cpp +++ b/SPID/src/LinkedDistribution.cpp @@ -145,6 +145,50 @@ namespace LinkedDistribution ForEachLinkedForms([&](LinkedForms& forms) { std::erase_if(forms.forms, [](const auto& pair) { return pair.second.empty(); }); }); + + // Clear INI once lookup is done + rawLinkedItems.clear(); + + // Clear logger's buffer to free some memory :) + buffered_logger::clear(); + } + + void Manager::LogLinkedItemsLookup() + { + logger::info("{:*^50}", "LINKED ITEMS"); + + ForEachLinkedForms([](const LinkedForms& linkedForms) { + if (linkedForms.GetForms().empty()) { + return; + } + + std::unordered_map> map{}; + + // Iterate through the original map + for (const auto& pair : linkedForms.GetForms()) { + const auto key = pair.first; + const DataVec& values = pair.second; + + for (const auto& value : values) { + map[value.form].push_back(key); + } + } + + const auto& recordName = RECORD::add[linkedForms.GetType()]; + logger::info("Linked {}s: ", recordName); + + for (const auto& [form, linkedItems] : map) { + logger::info("\t{}", describe(form)); + + const auto lastItemIndex = linkedItems.size() - 1; + for (int i = 0; i < lastItemIndex; ++i) { + const auto& linkedItem = linkedItems[i]; + logger::info("\t├─── {}", describe(linkedItem)); + } + const auto& lastLinkedItem = linkedItems[lastItemIndex]; + logger::info("\t└─── {}", describe(lastLinkedItem)); + } + }); } void Manager::ForEachLinkedDistributionSet(const std::set& targetForms, std::function performDistribution) diff --git a/SPID/src/LookupForms.cpp b/SPID/src/LookupForms.cpp index 8cf578f..aa6720e 100644 --- a/SPID/src/LookupForms.cpp +++ b/SPID/src/LookupForms.cpp @@ -85,35 +85,7 @@ void LookupLinkedItems(RE::TESDataHandler* const dataHandler) void LogLinkedItemsLookup() { - using namespace LinkedDistribution; - - logger::info("{:*^50}", "LINKED ITEMS"); - - Manager::GetSingleton()->ForEachLinkedForms([](const LinkedForms& linkedForms) { - if (linkedForms.GetForms().empty()) { - return; - } - const auto& recordName = RECORD::add[linkedForms.GetType()]; - logger::info("Linked {}s: ", recordName); - - for (const auto& [form, linkedItems] : linkedForms.GetForms()) { - logger::info("\t{}", describe(form)); - - const auto lastItemIndex = linkedItems.size() - 1; - for (int i = 0; i < lastItemIndex; ++i) { - const auto& linkedItem = linkedItems[i]; - logger::info("\t├─── {}", describe(linkedItem.form)); - } - const auto& lastLinkedItem = linkedItems[lastItemIndex]; - logger::info("\t└─── {}", describe(lastLinkedItem.form)); - } - }); - - // Clear INI once lookup is done - LinkedDistribution::INI::linkedItems.clear(); - - // Clear logger's buffer to free some memory :) - buffered_logger::clear(); + LinkedDistribution::Manager::GetSingleton()->LogLinkedItemsLookup(); } bool Lookup::LookupForms()