mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-07-02 00:22:10 -05:00
Remove switcher-data dependency from variables
This commit is contained in:
parent
d6c5fb149a
commit
953eca2732
|
|
@ -3,6 +3,7 @@
|
|||
#include "status-control.hpp"
|
||||
#include "file-selection.hpp"
|
||||
#include "filter-combo-box.hpp"
|
||||
#include "variable.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "version.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "macro-action-variable.hpp"
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "math-helpers.hpp"
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ void AdvSceneSwitcher::ExportMacros()
|
|||
obs_data_array_push_back(macroArray, obj);
|
||||
}
|
||||
obs_data_set_array(data, "macros", macroArray);
|
||||
switcher->SaveVariables(data);
|
||||
SaveVariables(data);
|
||||
obs_data_set_string(data, "version", g_GIT_TAG);
|
||||
auto json = obs_data_get_json(data);
|
||||
QString exportString(json);
|
||||
|
|
@ -382,7 +382,7 @@ static void importVariables(obs_data_t *obj)
|
|||
if (variableWithNameExists(var->Name())) {
|
||||
continue;
|
||||
}
|
||||
switcher->variables.emplace_back(var);
|
||||
GetVariables().emplace_back(var);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,14 +76,12 @@ public:
|
|||
/* --- Start of saving / loading section --- */
|
||||
|
||||
void SaveSettings(obs_data_t *obj);
|
||||
void SaveVariables(obs_data_t *obj);
|
||||
void SaveGeneralSettings(obs_data_t *obj);
|
||||
void SaveHotkeys(obs_data_t *obj);
|
||||
void SaveUISettings(obs_data_t *obj);
|
||||
void SaveVersion(obs_data_t *obj, const std::string ¤tVersion);
|
||||
|
||||
void LoadSettings(obs_data_t *obj);
|
||||
void LoadVariables(obs_data_t *obj);
|
||||
void LoadGeneralSettings(obs_data_t *obj);
|
||||
void LoadHotkeys(obs_data_t *obj);
|
||||
void LoadUISettings(obs_data_t *obj);
|
||||
|
|
@ -155,8 +153,6 @@ public:
|
|||
AudioFadeInfo masterAudioFade;
|
||||
std::unordered_map<std::string, AudioFadeInfo> activeAudioFades;
|
||||
|
||||
std::deque<std::shared_ptr<Item>> variables;
|
||||
|
||||
std::string lastTitle;
|
||||
std::string currentTitle;
|
||||
std::string currentForegroundProcess;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "variable-spinbox.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <QLayout>
|
||||
|
|
@ -175,7 +174,7 @@ void GenericVaraiableSpinbox::SetVisibilityInt()
|
|||
if (_numberInt.IsFixedType()) {
|
||||
_fixedValueInt->show();
|
||||
_variable->hide();
|
||||
_toggleType->setVisible(!switcher->variables.empty() &&
|
||||
_toggleType->setVisible(!GetVariables().empty() &&
|
||||
!_hideTypeToggle);
|
||||
} else {
|
||||
_fixedValueInt->hide();
|
||||
|
|
@ -191,7 +190,7 @@ void GenericVaraiableSpinbox::SetVisibilityDouble()
|
|||
if (_numberDouble.IsFixedType()) {
|
||||
_fixedValueDouble->show();
|
||||
_variable->hide();
|
||||
_toggleType->setVisible(!switcher->variables.empty() &&
|
||||
_toggleType->setVisible(!GetVariables().empty() &&
|
||||
!_hideTypeToggle);
|
||||
} else {
|
||||
_fixedValueDouble->hide();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
#include "variable-string.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
void StringVariable::Resolve() const
|
||||
{
|
||||
if (switcher && switcher->variables.empty()) {
|
||||
if (GetVariables().empty()) {
|
||||
_resolvedValue = _value;
|
||||
return;
|
||||
}
|
||||
|
|
@ -71,11 +70,7 @@ bool StringVariable::empty() const
|
|||
|
||||
std::string SubstitueVariables(std::string str)
|
||||
{
|
||||
if (!switcher) {
|
||||
return str;
|
||||
}
|
||||
|
||||
for (const auto &v : switcher->variables) {
|
||||
for (const auto &v : GetVariables()) {
|
||||
const auto &variable = std::dynamic_pointer_cast<Variable>(v);
|
||||
const std::string pattern = "${" + variable->Name() + "}";
|
||||
ReplaceAll(str, pattern, variable->Value());
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#include "variable-text-edit.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
|
||||
#include <obs-module.h>
|
||||
#include "obs-module-helper.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#include "variable.hpp"
|
||||
#include "switcher-data.hpp"
|
||||
#include "math-helpers.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
static std::deque<std::shared_ptr<Item>> variables;
|
||||
|
||||
// Keep track of the last time a variable was changed to save some work when
|
||||
// when resolving strings containing variables, etc.
|
||||
static std::chrono::high_resolution_clock::time_point lastVariableChange{};
|
||||
|
|
@ -70,9 +72,14 @@ void Variable::SetValue(double value)
|
|||
lastVariableChange = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
std::deque<std::shared_ptr<Item>> &GetVariables()
|
||||
{
|
||||
return variables;
|
||||
}
|
||||
|
||||
Variable *GetVariableByName(const std::string &name)
|
||||
{
|
||||
for (const auto &v : switcher->variables) {
|
||||
for (const auto &v : variables) {
|
||||
if (v->Name() == name) {
|
||||
return dynamic_cast<Variable *>(v.get());
|
||||
}
|
||||
|
|
@ -87,7 +94,7 @@ Variable *GetVariableByQString(const QString &name)
|
|||
|
||||
std::weak_ptr<Variable> GetWeakVariableByName(const std::string &name)
|
||||
{
|
||||
for (const auto &v : switcher->variables) {
|
||||
for (const auto &v : variables) {
|
||||
if (v->Name() == name) {
|
||||
std::weak_ptr<Variable> wp =
|
||||
std::dynamic_pointer_cast<Variable>(v);
|
||||
|
|
@ -105,7 +112,7 @@ std::weak_ptr<Variable> GetWeakVariableByQString(const QString &name)
|
|||
QStringList GetVariablesNameList()
|
||||
{
|
||||
QStringList list;
|
||||
for (const auto &var : switcher->variables) {
|
||||
for (const auto &var : variables) {
|
||||
list << QString::fromStdString(var->Name());
|
||||
}
|
||||
list.sort();
|
||||
|
|
@ -121,7 +128,7 @@ std::string GetWeakVariableName(std::weak_ptr<Variable> var_)
|
|||
return var->Name();
|
||||
}
|
||||
|
||||
void SwitcherData::SaveVariables(obs_data_t *obj)
|
||||
void SaveVariables(obs_data_t *obj)
|
||||
{
|
||||
obs_data_array_t *variablesArray = obs_data_array_create();
|
||||
for (const auto &v : variables) {
|
||||
|
|
@ -134,7 +141,7 @@ void SwitcherData::SaveVariables(obs_data_t *obj)
|
|||
obs_data_array_release(variablesArray);
|
||||
}
|
||||
|
||||
void SwitcherData::LoadVariables(obs_data_t *obj)
|
||||
void LoadVariables(obs_data_t *obj)
|
||||
{
|
||||
variables.clear();
|
||||
|
||||
|
|
@ -162,7 +169,7 @@ static void populateSaveActionSelection(QComboBox *list)
|
|||
|
||||
VariableSettingsDialog::VariableSettingsDialog(QWidget *parent,
|
||||
const Variable &settings)
|
||||
: ItemSettingsDialog(settings, switcher->variables,
|
||||
: ItemSettingsDialog(settings, variables,
|
||||
"AdvSceneSwitcher.variable.select",
|
||||
"AdvSceneSwitcher.variable.add",
|
||||
"AdvSceneSwitcher.item.nameNotAvailable", parent),
|
||||
|
|
@ -245,8 +252,7 @@ static bool AskForSettingsWrapper(QWidget *parent, Item &settings)
|
|||
}
|
||||
|
||||
VariableSelection::VariableSelection(QWidget *parent)
|
||||
: ItemSelection(switcher->variables, Variable::Create,
|
||||
AskForSettingsWrapper,
|
||||
: ItemSelection(variables, Variable::Create, AskForSettingsWrapper,
|
||||
"AdvSceneSwitcher.variable.select",
|
||||
"AdvSceneSwitcher.variable.add",
|
||||
"AdvSceneSwitcher.item.nameNotAvailable",
|
||||
|
|
|
|||
|
|
@ -43,14 +43,6 @@ private:
|
|||
friend VariableSettingsDialog;
|
||||
};
|
||||
|
||||
Variable *GetVariableByName(const std::string &name);
|
||||
Variable *GetVariableByQString(const QString &name);
|
||||
std::weak_ptr<Variable> GetWeakVariableByName(const std::string &name);
|
||||
std::weak_ptr<Variable> GetWeakVariableByQString(const QString &name);
|
||||
QStringList GetVariablesNameList();
|
||||
std::string GetWeakVariableName(std::weak_ptr<Variable>);
|
||||
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime();
|
||||
|
||||
class VariableSettingsDialog : public ItemSettingsDialog {
|
||||
Q_OBJECT
|
||||
|
||||
|
|
@ -76,4 +68,18 @@ public:
|
|||
void SetVariable(const std::weak_ptr<Variable> &);
|
||||
};
|
||||
|
||||
void SaveVariables(obs_data_t *obj);
|
||||
void LoadVariables(obs_data_t *obj);
|
||||
|
||||
std::deque<std::shared_ptr<Item>> &GetVariables();
|
||||
|
||||
Variable *GetVariableByName(const std::string &name);
|
||||
Variable *GetVariableByQString(const QString &name);
|
||||
std::weak_ptr<Variable> GetWeakVariableByName(const std::string &name);
|
||||
std::weak_ptr<Variable> GetWeakVariableByQString(const QString &name);
|
||||
std::string GetWeakVariableName(std::weak_ptr<Variable>);
|
||||
QStringList GetVariablesNameList();
|
||||
|
||||
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime();
|
||||
|
||||
} // namespace advss
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user