mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-10-29 03:45:54 -05:00
Show variable usage count on variable tab
This commit is contained in:
35
lib/variables/variable-usage.cpp
Normal file
35
lib/variables/variable-usage.cpp
Normal 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 ¯o : 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
|
||||
Reference in New Issue
Block a user