Fix conditions and actions referencing macros not loading correctly

The reason is that while loading the required macro might not have been
loaded resulting in the pointer to the macro never being set correctly
in the loading phase.
This commit is contained in:
WarmUpTill
2021-05-24 02:01:32 +02:00
committed by WarmUpTill
parent 6893d9539e
commit 48e6bcbb7a
6 changed files with 130 additions and 42 deletions

View File

@@ -216,6 +216,23 @@ bool Macro::Load(obs_data_t *obj)
return true;
}
void Macro::ResolveMacroRef()
{
for (auto &c : _conditions) {
MacroRefCondition *ref =
dynamic_cast<MacroRefCondition *>(c.get());
if (ref) {
ref->_macro.UpdateRef();
}
}
for (auto &a : _actions) {
MacroRefAction *ref = dynamic_cast<MacroRefAction *>(a.get());
if (ref) {
ref->_macro.UpdateRef();
}
}
}
bool Macro::SwitchesScene()
{
MacroActionSwitchScene temp;
@@ -350,6 +367,10 @@ void SwitcherData::loadMacros(obs_data_t *obj)
obs_data_release(array_obj);
}
obs_data_array_release(macroArray);
for (auto &m : macros) {
m.ResolveMacroRef();
}
}
bool SwitcherData::checkMacros()
@@ -398,3 +419,53 @@ Macro *GetMacroByQString(const QString &name)
{
return GetMacroByName(name.toUtf8().constData());
}
MacroRef::MacroRef(std::string name) : _name(name)
{
UpdateRef();
}
void MacroRef::UpdateRef()
{
_ref = GetMacroByName(_name.c_str());
}
void MacroRef::UpdateRef(std::string newName)
{
_name = newName;
UpdateRef();
}
void MacroRef::UpdateRef(QString newName)
{
_name = newName.toStdString();
UpdateRef();
}
void MacroRef::Save(obs_data_t *obj)
{
if (_ref) {
obs_data_set_string(obj, "macro", _ref->Name().c_str());
}
}
void MacroRef::Load(obs_data_t *obj)
{
_name = obs_data_get_string(obj, "macro");
UpdateRef();
}
Macro *MacroRef::get()
{
return _ref;
}
Macro *MacroRef::operator->()
{
return _ref;
}
void MacroRefCondition::ResolveMacroRef()
{
_macro.UpdateRef();
}
void MacroRefAction::ResolveMacroRef()
{
_macro.UpdateRef();
}