Adaptions for "else" support

* Fix "on change" option always being highlighted
* Fix "run macro" button performing actions based on condition state
* Fix "run" option of macro action performing action based on condition
  stated of selected macro
This commit is contained in:
WarmUpTill 2023-09-10 22:51:30 +02:00 committed by WarmUpTill
parent 81f669e226
commit fffb6c5f29
4 changed files with 16 additions and 19 deletions

View File

@ -49,7 +49,7 @@ bool MacroActionMacro::PerformAction()
break;
case Action::RUN:
if (!macro->Paused()) {
macro->PerformActions();
macro->PerformActions(false, false, true);
}
break;
case Action::STOP:

View File

@ -458,7 +458,7 @@ void AdvSceneSwitcher::on_runMacro_clicked()
return;
}
bool ret = macro->PerformActions(true, true);
bool ret = macro->PerformActions(true, true, true);
if (!ret) {
QString err =
obs_module_text("AdvSceneSwitcher.macroTab.runFail");

View File

@ -177,7 +177,7 @@ bool Macro::CeckMatch()
vblog(LOG_INFO, "Macro %s returned %d", _name.c_str(), _matched);
_conditionSateChanged = _lastMatched != _matched;
if (!_conditionSateChanged) {
if (!_conditionSateChanged && _performActionsOnChange) {
_onPreventedActionExecution = true;
}
_lastMatched = _matched;
@ -185,7 +185,8 @@ bool Macro::CeckMatch()
return _matched;
}
bool Macro::PerformActions(bool forceParallel, bool ignorePause)
bool Macro::PerformActions(bool forceParallel, bool ignorePause,
bool forceMatch)
{
if (!_done) {
vblog(LOG_INFO, "macro %s already running", _name.c_str());
@ -198,10 +199,13 @@ bool Macro::PerformActions(bool forceParallel, bool ignorePause)
if (_backgroundThread.joinable()) {
_backgroundThread.join();
}
_backgroundThread = std::thread(
[this, ignorePause] { RunActions(ignorePause); });
_backgroundThread =
std::thread([this, ignorePause, forceMatch] {
bool _ = false;
RunActions(_, ignorePause, forceMatch);
});
} else {
RunActions(ret, ignorePause);
RunActions(ret, ignorePause, forceMatch);
}
_lastExecutionTime = std::chrono::high_resolution_clock::now();
auto group = _parent.lock();
@ -270,11 +274,11 @@ void Macro::ResetTimers()
_lastExecutionTime = {};
}
void Macro::RunActions(bool &retVal, bool ignorePause)
void Macro::RunActions(bool &retVal, bool ignorePause, bool forceMatch)
{
bool ret = true;
const std::deque<std::shared_ptr<MacroAction>> &actionsToExecute =
_matched ? _actions : _elseActions;
_matched || forceMatch ? _actions : _elseActions;
vblog(LOG_INFO, "running %sactions of %s", _matched ? "" : "else ",
_name.c_str());
for (auto &action : actionsToExecute) {
@ -296,12 +300,6 @@ void Macro::RunActions(bool &retVal, bool ignorePause)
_done = true;
}
void Macro::RunActions(bool ignorePause)
{
bool unused;
RunActions(unused, ignorePause);
}
bool Macro::DockIsVisible() const
{
return _dock && _dockAction && _dock->isVisible();
@ -648,7 +646,7 @@ bool Macro::OnChangePreventedActionsRecently()
{
if (_onPreventedActionExecution) {
_onPreventedActionExecution = false;
return true;
return _matched ? _actions.size() > 0 : _elseActions.size() > 0;
}
return false;
}

View File

@ -26,7 +26,7 @@ public:
virtual ~Macro();
bool CeckMatch();
bool PerformActions(bool forceParallel = false,
bool ignorePause = false);
bool ignorePause = false, bool forceMatch = false);
bool Matched() const { return _matched; }
bool ShouldRunActions() const;
int64_t MsSinceLastCheck() const;
@ -121,8 +121,7 @@ private:
void SetupHotkeys();
void ClearHotkeys() const;
void SetHotkeysDesc() const;
void RunActions(bool &ret, bool ignorePause);
void RunActions(bool ignorePause);
void RunActions(bool &ret, bool ignorePause, bool forceMatch);
bool DockIsVisible() const;
void SetDockWidgetName() const;
void SaveDockSettings(obs_data_t *obj) const;