mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-11-17 23:25:15 -06:00
Add separate input variable to JSON variable actions
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "macro-action-variable-json.hpp"
|
||||
#include "json-helpers.hpp"
|
||||
|
||||
#include <QCheckBox>
|
||||
|
||||
namespace advss {
|
||||
|
||||
using Action = MacroActionVariable::Action;
|
||||
@@ -10,13 +12,13 @@ static bool registered = RegisterVariableActionGroup(
|
||||
{
|
||||
{Action::EXTRACT_JSON,
|
||||
"AdvSceneSwitcher.action.variable.type.extractJsonField",
|
||||
"AdvSceneSwitcher.action.variable.layout.strValue", true},
|
||||
"AdvSceneSwitcher.action.variable.layout.jsonField", true},
|
||||
{Action::QUERY_JSON,
|
||||
"AdvSceneSwitcher.action.variable.type.queryJson",
|
||||
"AdvSceneSwitcher.action.variable.layout.queryJson", true},
|
||||
"AdvSceneSwitcher.action.variable.layout.jsonQuery", true},
|
||||
{Action::ARRAY_JSON,
|
||||
"AdvSceneSwitcher.action.variable.type.accessJsonArray",
|
||||
"AdvSceneSwitcher.action.variable.layout.accessJsonArray"},
|
||||
"AdvSceneSwitcher.action.variable.layout.jsonIndex"},
|
||||
{Action::JSON_ARRAY_LENGTH,
|
||||
"AdvSceneSwitcher.action.variable.type.jsonArrayLength",
|
||||
"AdvSceneSwitcher.action.variable.layout.jsonArrayLength"},
|
||||
@@ -42,7 +44,7 @@ void VariableActionJson::Save(obs_data_t *obj,
|
||||
_jsonValue.Save(obj, "jsonValue");
|
||||
}
|
||||
|
||||
void VariableActionJson::Load(obs_data_t *obj, MacroActionVariable &)
|
||||
void VariableActionJson::Load(obs_data_t *obj, MacroActionVariable &action)
|
||||
{
|
||||
_jsonQuery.Load(obj, "jsonQuery");
|
||||
_jsonIndex.Load(obj, "jsonIndex");
|
||||
@@ -51,6 +53,14 @@ void VariableActionJson::Load(obs_data_t *obj, MacroActionVariable &)
|
||||
if (obs_data_has_user_value(obj, "jsonValue")) {
|
||||
_jsonValue.Load(obj, "jsonValue");
|
||||
}
|
||||
|
||||
// Old settings modified _variable in place
|
||||
const bool modifiedInPlace = action._action == Action::EXTRACT_JSON ||
|
||||
action._action == Action::QUERY_JSON ||
|
||||
action._action == Action::ARRAY_JSON;
|
||||
if (modifiedInPlace && obs_data_get_int(obj, "version") < 2) {
|
||||
action._variable2 = action._variable;
|
||||
}
|
||||
}
|
||||
|
||||
void VariableActionJson::ResolveVariables()
|
||||
@@ -66,7 +76,11 @@ bool VariableActionJson::Perform(MacroActionVariable &action,
|
||||
{
|
||||
switch (type) {
|
||||
case Action::EXTRACT_JSON: {
|
||||
auto value = GetJsonField(var.Value(), action._strValue);
|
||||
auto input = action._variable2.lock();
|
||||
if (!input) {
|
||||
return true;
|
||||
}
|
||||
auto value = GetJsonField(input->Value(), action._strValue);
|
||||
if (!value.has_value()) {
|
||||
return true;
|
||||
}
|
||||
@@ -74,7 +88,11 @@ bool VariableActionJson::Perform(MacroActionVariable &action,
|
||||
return true;
|
||||
}
|
||||
case Action::QUERY_JSON: {
|
||||
auto value = QueryJson(var.Value(), _jsonQuery);
|
||||
auto input = action._variable2.lock();
|
||||
if (!input) {
|
||||
return true;
|
||||
}
|
||||
auto value = QueryJson(input->Value(), _jsonQuery);
|
||||
if (!value.has_value()) {
|
||||
return true;
|
||||
}
|
||||
@@ -93,7 +111,11 @@ bool VariableActionJson::Perform(MacroActionVariable &action,
|
||||
return true;
|
||||
}
|
||||
case Action::ARRAY_JSON: {
|
||||
auto value = AccessJsonArrayIndex(var.Value(), _jsonIndex);
|
||||
auto input = action._variable2.lock();
|
||||
if (!input) {
|
||||
return true;
|
||||
}
|
||||
auto value = AccessJsonArrayIndex(input->Value(), _jsonIndex);
|
||||
if (!value.has_value()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "variable-line-edit.hpp"
|
||||
#include "variable-spinbox.hpp"
|
||||
|
||||
class QCheckBox;
|
||||
|
||||
namespace advss {
|
||||
|
||||
class VariableActionJson : public VariableActionGroup {
|
||||
|
||||
@@ -67,7 +67,7 @@ bool MacroActionVariable::Save(obs_data_t *obj) const
|
||||
for (const auto &group : _groups) {
|
||||
group->Save(obj, *this);
|
||||
}
|
||||
obs_data_set_int(obj, "version", 1);
|
||||
obs_data_set_int(obj, "version", 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ MacroActionVariableEdit::MacroActionVariableEdit(
|
||||
_variables2(new VariableSelection(this)),
|
||||
_actions(new FilterComboBox(this)),
|
||||
_strValue(new VariableTextEdit(this, 5, 1, 1)),
|
||||
_entryLayout(new QHBoxLayout())
|
||||
_entryLayout(new QVBoxLayout())
|
||||
{
|
||||
populateActionSelection(_actions);
|
||||
|
||||
@@ -242,25 +242,28 @@ void MacroActionVariableEdit::SetWidgetVisibility()
|
||||
}
|
||||
|
||||
const auto widgets = GetInlineWidgets();
|
||||
for (const auto &[_, widget] : widgets) {
|
||||
_entryLayout->removeWidget(widget);
|
||||
for (int i = 0; i < _entryLayout->count(); i++) {
|
||||
auto row = _entryLayout->itemAt(i)->layout();
|
||||
for (const auto &[_, widget] : widgets) {
|
||||
row->removeWidget(widget);
|
||||
}
|
||||
}
|
||||
ClearLayout(_entryLayout);
|
||||
|
||||
const std::string layoutString = obs_module_text(option->layout);
|
||||
PlaceWidgets(layoutString, _entryLayout, widgets);
|
||||
const auto rows = QString::fromStdString(layoutString).split('\n');
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
auto row = new QHBoxLayout();
|
||||
_entryLayout->addLayout(row);
|
||||
const bool expandRow = option->expandInlineRow && i == 0;
|
||||
PlaceWidgets(rows[i].toStdString(), row, widgets, !expandRow);
|
||||
}
|
||||
|
||||
for (const auto &[placeholder, widget] : widgets) {
|
||||
widget->setVisible(layoutString.find(placeholder) !=
|
||||
std::string::npos);
|
||||
}
|
||||
|
||||
if (option->expandInlineRow) {
|
||||
RemoveStretchIfPresent(_entryLayout);
|
||||
} else {
|
||||
AddStretchIfNecessary(_entryLayout);
|
||||
}
|
||||
|
||||
for (const auto &groupEdit : _groupEdits) {
|
||||
groupEdit->SetWidgetVisibility(_entryData->_action);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ private:
|
||||
VariableSelection *_variables2;
|
||||
FilterComboBox *_actions;
|
||||
VariableTextEdit *_strValue;
|
||||
QHBoxLayout *_entryLayout;
|
||||
QVBoxLayout *_entryLayout;
|
||||
std::vector<VariableActionGroupEdit *> _groupEdits;
|
||||
|
||||
std::shared_ptr<MacroActionVariable> _entryData;
|
||||
|
||||
Reference in New Issue
Block a user