Add PostLoad()

Used to reslove values that only can be resolved after all macros /
macro segments have been set up initally.
This commit is contained in:
WarmUpTill 2023-01-15 04:27:27 +01:00 committed by WarmUpTill
parent 1c3ff927a5
commit 334d173dc9
4 changed files with 20 additions and 1 deletions

View File

@ -25,6 +25,11 @@ bool MacroSegment::Load(obs_data_t *obj)
return true;
}
bool MacroSegment::PostLoad()
{
return true;
}
std::string MacroSegment::GetShortDesc() const
{
return "";

View File

@ -18,6 +18,7 @@ public:
bool GetCollapsed() const { return _collapsed; }
virtual bool Save(obs_data_t *obj) const = 0;
virtual bool Load(obs_data_t *obj) = 0;
virtual bool PostLoad();
virtual std::string GetShortDesc() const;
virtual std::string GetId() const = 0;
void SetHighlight();

View File

@ -489,6 +489,18 @@ bool Macro::Load(obs_data_t *obj)
return true;
}
bool Macro::PostLoad()
{
ResolveMacroRef();
for (auto &c : _conditions) {
c->PostLoad();
}
for (auto &a : _actions) {
a->PostLoad();
}
return true;
}
void Macro::ResolveMacroRef()
{
for (auto &c : _conditions) {
@ -699,7 +711,6 @@ void SwitcherData::loadMacros(obs_data_t *obj)
int groupCount = 0;
Macro *group = nullptr;
for (auto &m : macros) {
m->ResolveMacroRef();
if (groupCount) {
m->SetParent(group);
groupCount--;
@ -708,6 +719,7 @@ void SwitcherData::loadMacros(obs_data_t *obj)
groupCount = m->GroupSize();
group = m.get();
}
m->PostLoad();
}
}

View File

@ -63,6 +63,7 @@ public:
bool Save(obs_data_t *obj) const;
bool Load(obs_data_t *obj);
bool PostLoad();
// Some macros can refer to other macros, which are not yet loaded.
// Use this function to set these references after loading is complete.
void ResolveMacroRef();