Show variable usage count on variable tab

This commit is contained in:
WarmUpTill
2026-10-19 18:26:51 +02:00
committed by WarmUpTill
parent 561f8224fd
commit d0f483b634
6 changed files with 144 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
#include "variable-usage.hpp"
#include "macro-helpers.hpp"
#include "macro.hpp"
#include "sync-helpers.hpp"
#include "variable-ref.hpp"
#include <obs.hpp>
namespace advss {
static std::unordered_map<std::string, int> collectReferences(Macro *macro)
{
VariableRefCollector collector;
OBSDataAutoRelease data = obs_data_create();
macro->Save(data);
return collector.Counts();
}
std::unordered_map<std::string, VariableUsage> GetVariableUsage()
{
std::unordered_map<std::string, VariableUsage> result;
auto lock = LockContext();
// Nested macros are saved as part of their parent macro
for (const auto &macro : GetTopLevelMacros()) {
for (const auto &[name, count] :
collectReferences(macro.get())) {
auto &usage = result[name];
usage.referenceCount += count;
usage.macroNames.emplace_back(macro->Name());
}
}
return result;
}
} // namespace advss