diff --git a/lib/macro/macro-action-variable.cpp b/lib/macro/macro-action-variable.cpp index 4bcdd308..dee31c4f 100644 --- a/lib/macro/macro-action-variable.cpp +++ b/lib/macro/macro-action-variable.cpp @@ -546,10 +546,8 @@ bool MacroActionVariable::PerformAction() bool MacroActionVariable::Save(obs_data_t *obj) const { MacroAction::Save(obj); - obs_data_set_string(obj, "variableName", - GetWeakVariableName(_variable).c_str()); - obs_data_set_string(obj, "variable2Name", - GetWeakVariableName(_variable2).c_str()); + _variable.Save(obj, "variableName"); + _variable2.Save(obj, "variable2Name"); _strValue.Save(obj, "strValue"); _numValue.Save(obj, "numValue"); obs_data_set_int(obj, "condition", static_cast(_action)); @@ -595,10 +593,8 @@ bool MacroActionVariable::Save(obs_data_t *obj) const bool MacroActionVariable::Load(obs_data_t *obj) { MacroAction::Load(obj); - _variable = - GetWeakVariableByName(obs_data_get_string(obj, "variableName")); - _variable2 = GetWeakVariableByName( - obs_data_get_string(obj, "variable2Name")); + _variable.Load(obj, "variableName"); + _variable2.Load(obj, "variable2Name"); _strValue.Load(obj, "strValue"); _action = static_cast(obs_data_get_int(obj, "condition")); _segmentIdxLoadValue = obs_data_get_int(obj, "segmentIdx"); diff --git a/lib/macro/macro-action-variable.hpp b/lib/macro/macro-action-variable.hpp index ce91fd70..a9303259 100644 --- a/lib/macro/macro-action-variable.hpp +++ b/lib/macro/macro-action-variable.hpp @@ -9,6 +9,7 @@ #include "string-list.hpp" #include "value-input.hpp" #include "variable-line-edit.hpp" +#include "variable-ref.hpp" #include "variable-text-edit.hpp" #include "variable-spinbox.hpp" @@ -63,8 +64,8 @@ public: }; Action _action = Action::SET_VALUE; - std::weak_ptr _variable; - std::weak_ptr _variable2; + VariableRef _variable; + VariableRef _variable2; StringVariable _strValue = ""; DoubleVariable _numValue = 0; IntVariable _subStringStart = 0; diff --git a/lib/macro/macro-condition-tempvar.cpp b/lib/macro/macro-condition-tempvar.cpp index fd6caca5..a6cf52e2 100644 --- a/lib/macro/macro-condition-tempvar.cpp +++ b/lib/macro/macro-condition-tempvar.cpp @@ -164,8 +164,7 @@ bool MacroConditionTempVar::Save(obs_data_t *obj) const { MacroCondition::Save(obj); _tempVar.Save(obj, GetMacro()); - obs_data_set_string(obj, "variableName", - GetWeakVariableName(_variable2).c_str()); + _variable2.Save(obj, "variableName"); _strValue.Save(obj, "strValue"); obs_data_set_double(obj, "numValue", _numValue); obs_data_set_int(obj, "condition", static_cast(_type)); @@ -177,8 +176,7 @@ bool MacroConditionTempVar::Load(obs_data_t *obj) { MacroCondition::Load(obj); _tempVar.Load(obj, GetMacro()); - _variable2 = - GetWeakVariableByName(obs_data_get_string(obj, "variableName")); + _variable2.Load(obj, "variableName"); _strValue.Load(obj, "strValue"); _numValue = obs_data_get_double(obj, "numValue"); _type = static_cast(obs_data_get_int(obj, "condition")); diff --git a/lib/macro/macro-condition-tempvar.hpp b/lib/macro/macro-condition-tempvar.hpp index 681a8935..00183034 100644 --- a/lib/macro/macro-condition-tempvar.hpp +++ b/lib/macro/macro-condition-tempvar.hpp @@ -1,6 +1,7 @@ #pragma once #include "macro-condition-edit.hpp" #include "resizing-text-edit.hpp" +#include "variable-ref.hpp" #include "variable.hpp" #include "regex-config.hpp" #include "variable-text-edit.hpp" @@ -40,7 +41,7 @@ public: Condition _type = Condition::EQUALS; TempVariableRef _tempVar; - std::weak_ptr _variable2; + VariableRef _variable2; StringVariable _strValue = ""; double _numValue = 0; RegexConfig _regex; diff --git a/lib/macro/macro-condition-variable.cpp b/lib/macro/macro-condition-variable.cpp index 54b84c09..271ea63f 100644 --- a/lib/macro/macro-condition-variable.cpp +++ b/lib/macro/macro-condition-variable.cpp @@ -129,10 +129,8 @@ bool MacroConditionVariable::CheckCondition() bool MacroConditionVariable::Save(obs_data_t *obj) const { MacroCondition::Save(obj); - obs_data_set_string(obj, "variableName", - GetWeakVariableName(_variable).c_str()); - obs_data_set_string(obj, "variable2Name", - GetWeakVariableName(_variable2).c_str()); + _variable.Save(obj, "variableName"); + _variable2.Save(obj, "variable2Name"); _strValue.Save(obj, "strValue"); obs_data_set_double(obj, "numValue", _numValue); obs_data_set_int(obj, "condition", static_cast(_type)); @@ -143,10 +141,8 @@ bool MacroConditionVariable::Save(obs_data_t *obj) const bool MacroConditionVariable::Load(obs_data_t *obj) { MacroCondition::Load(obj); - _variable = - GetWeakVariableByName(obs_data_get_string(obj, "variableName")); - _variable2 = GetWeakVariableByName( - obs_data_get_string(obj, "variable2Name")); + _variable.Load(obj, "variableName"); + _variable2.Load(obj, "variable2Name"); _strValue.Load(obj, "strValue"); _numValue = obs_data_get_double(obj, "numValue"); _type = static_cast(obs_data_get_int(obj, "condition")); diff --git a/lib/macro/macro-condition-variable.hpp b/lib/macro/macro-condition-variable.hpp index 237a7221..e72b03cc 100644 --- a/lib/macro/macro-condition-variable.hpp +++ b/lib/macro/macro-condition-variable.hpp @@ -1,6 +1,7 @@ #pragma once #include "macro-condition-edit.hpp" #include "resizing-text-edit.hpp" +#include "variable-ref.hpp" #include "variable.hpp" #include "regex-config.hpp" #include "variable-text-edit.hpp" @@ -38,8 +39,8 @@ public: }; Condition _type = Condition::EQUALS; - std::weak_ptr _variable; - std::weak_ptr _variable2; + VariableRef _variable; + VariableRef _variable2; StringVariable _strValue = ""; double _numValue = 0; RegexConfig _regex; diff --git a/lib/macro/macro-input.cpp b/lib/macro/macro-input.cpp index 527cdca9..d8d6f087 100644 --- a/lib/macro/macro-input.cpp +++ b/lib/macro/macro-input.cpp @@ -14,12 +14,10 @@ void MacroInputVariables::Save(obs_data_t *obj) const OBSDataArrayAutoRelease array = obs_data_array_create(); for (auto &var : _inputVariables) { OBSDataAutoRelease arrayObj = obs_data_create(); - auto variable = var.lock(); - if (variable) { - obs_data_set_string(arrayObj, "variableName", - variable->Name().c_str()); - } else { + if (var.expired()) { obs_data_set_bool(arrayObj, "invalidVariable", true); + } else { + var.Save(arrayObj, "variableName"); } obs_data_array_push_back(array, arrayObj); } diff --git a/lib/macro/macro-input.hpp b/lib/macro/macro-input.hpp index 3aa650db..e6804a70 100644 --- a/lib/macro/macro-input.hpp +++ b/lib/macro/macro-input.hpp @@ -1,6 +1,7 @@ #pragma once #include "list-editor.hpp" #include "string-list.hpp" +#include "variable-ref.hpp" #include "variable.hpp" #include @@ -16,7 +17,7 @@ public: void SetValues(const StringList &values); private: - std::vector> _inputVariables; + std::vector _inputVariables; friend class MacroInputSelection; friend class MacroInputEdit; }; diff --git a/lib/macro/macro-segment.cpp b/lib/macro/macro-segment.cpp index 7de29628..0f04c66c 100644 --- a/lib/macro/macro-segment.cpp +++ b/lib/macro/macro-segment.cpp @@ -107,9 +107,7 @@ bool MacroSegment::Save(obs_data_t *obj) const for (const auto &mapping : _varMappings) { OBSDataAutoRelease item = obs_data_create(); mapping.tempVar.Save(item, GetMacro(), "tempVar"); - obs_data_set_string( - item, "variable", - GetWeakVariableName(mapping.variable).c_str()); + mapping.variable.Save(item, "variable"); obs_data_array_push_back(mappingsArray, item); } obs_data_set_array(data, "varMappings", mappingsArray); @@ -147,8 +145,7 @@ bool MacroSegment::Load(obs_data_t *obj) for (size_t i = 0; i < count; i++) { OBSDataAutoRelease item = obs_data_array_item(mappingsArray, i); VarMapping mapping; - mapping.variable = GetWeakVariableByName( - obs_data_get_string(item, "variable")); + mapping.variable.Load(item, "variable"); _varMappings.push_back(std::move(mapping)); _varMappings.back().tempVar.Load(item, GetMacro(), "tempVar"); } diff --git a/lib/macro/macro-segment.hpp b/lib/macro/macro-segment.hpp index e275a84f..ac9a579e 100644 --- a/lib/macro/macro-segment.hpp +++ b/lib/macro/macro-segment.hpp @@ -6,6 +6,7 @@ #include "obs-module-helper.hpp" #include "sync-helpers.hpp" #include "temp-variable.hpp" +#include "variable-ref.hpp" #include @@ -26,7 +27,7 @@ class Variable; struct VarMapping { TempVariableRef tempVar; - std::weak_ptr variable; + VariableRef variable; }; class EXPORT MacroSegment : public Lockable { diff --git a/lib/utils/scene-selection.cpp b/lib/utils/scene-selection.cpp index 1ef35e1d..61b7f138 100644 --- a/lib/utils/scene-selection.cpp +++ b/lib/utils/scene-selection.cpp @@ -32,15 +32,9 @@ void SceneSelection::Save(obs_data_t *obj) const obs_data_set_string(data, nameSaveName.data(), _group->name.c_str()); break; - case Type::VARIABLE: { - auto var = _variable.lock(); - if (!var) { - break; - } - obs_data_set_string(data, nameSaveName.data(), - var->Name().c_str()); + case Type::VARIABLE: + _variable.Save(data, nameSaveName.data()); break; - } default: break; } diff --git a/lib/utils/scene-selection.hpp b/lib/utils/scene-selection.hpp index f9e39061..b11e4d61 100644 --- a/lib/utils/scene-selection.hpp +++ b/lib/utils/scene-selection.hpp @@ -1,5 +1,6 @@ #pragma once #include "canvas-helpers.hpp" +#include "variable-ref.hpp" namespace advss { @@ -32,7 +33,7 @@ private: OBSWeakSource _scene; OBSWeakCanvas _canvas = GetMainCanvas(); SceneGroup *_group = nullptr; - std::weak_ptr _variable; + VariableRef _variable; Type _type = Type::SCENE; friend class SceneSelectionWidget; }; diff --git a/lib/utils/source-selection.cpp b/lib/utils/source-selection.cpp index 0dd55470..e1f0adc9 100644 --- a/lib/utils/source-selection.cpp +++ b/lib/utils/source-selection.cpp @@ -19,15 +19,9 @@ void SourceSelection::Save(obs_data_t *obj, const char *name) const obs_data_set_string(data, nameSaveName.data(), GetWeakSourceName(_source).c_str()); break; - case Type::VARIABLE: { - auto var = _variable.lock(); - if (!var) { - break; - } - obs_data_set_string(data, nameSaveName.data(), - var->Name().c_str()); + case Type::VARIABLE: + _variable.Save(data, nameSaveName.data()); break; - } default: break; } diff --git a/lib/utils/source-selection.hpp b/lib/utils/source-selection.hpp index 9e34e6af..f20ccca0 100644 --- a/lib/utils/source-selection.hpp +++ b/lib/utils/source-selection.hpp @@ -1,6 +1,7 @@ #pragma once #include "filter-combo-box.hpp" #include "obs.hpp" +#include "variable-ref.hpp" namespace advss { @@ -30,7 +31,7 @@ private: void LoadFallback(obs_data_t *obj, const char *name); OBSWeakSource _source; - std::weak_ptr _variable; + VariableRef _variable; Type _type = Type::SOURCE; friend class SourceSelectionWidget; }; diff --git a/lib/variables/variable-color.cpp b/lib/variables/variable-color.cpp index 8b5e478a..983a18bb 100644 --- a/lib/variables/variable-color.cpp +++ b/lib/variables/variable-color.cpp @@ -11,9 +11,8 @@ void ColorVariable::Save(obs_data_t *obj, const char *name) const OBSDataAutoRelease data = obs_data_create(); obs_data_set_int(data, "version", 1); obs_data_set_int(data, "type", static_cast(_type)); - auto var = _variable.lock(); - if (var) { - obs_data_set_string(data, "variable", var->Name().c_str()); + if (_type == Type::VARIABLE) { + _variable.Save(data, "variable"); } obs_data_set_int(data, "red", _value.red()); obs_data_set_int(data, "green", _value.green()); @@ -32,8 +31,7 @@ void ColorVariable::Load(obs_data_t *obj, const char *name) _type = Type::FIXED_VALUE; return; } - auto variableName = obs_data_get_string(data, "variable"); - _variable = GetWeakVariableByName(variableName); + _variable.Load(data, "variable"); _type = static_cast(obs_data_get_int(data, "type")); } diff --git a/lib/variables/variable-color.hpp b/lib/variables/variable-color.hpp index fe4ff003..b7298583 100644 --- a/lib/variables/variable-color.hpp +++ b/lib/variables/variable-color.hpp @@ -1,4 +1,5 @@ #pragma once +#include "variable-ref.hpp" #include "variable.hpp" #include @@ -27,7 +28,7 @@ public: private: Type _type = Type::FIXED_VALUE; QColor _value = Qt::black; - std::weak_ptr _variable; + VariableRef _variable; friend class VariableColorButton; }; diff --git a/lib/variables/variable-number.hpp b/lib/variables/variable-number.hpp index 17baf3c4..ac712da8 100644 --- a/lib/variables/variable-number.hpp +++ b/lib/variables/variable-number.hpp @@ -1,4 +1,5 @@ #pragma once +#include "variable-ref.hpp" #include "variable.hpp" namespace advss { @@ -27,7 +28,7 @@ public: private: Type _type = Type::FIXED_VALUE; T _value = {}; - std::weak_ptr _variable; + VariableRef _variable; friend class GenericVariableSpinbox; friend class VariableSpinBox; diff --git a/lib/variables/variable-number.tpp b/lib/variables/variable-number.tpp index cf87f70d..7abd15d4 100644 --- a/lib/variables/variable-number.tpp +++ b/lib/variables/variable-number.tpp @@ -18,9 +18,8 @@ void NumberVariable::Save(obs_data_t *obj, const char *name) const } else { assert(false); } - auto var = _variable.lock(); - if (var) { - obs_data_set_string(data, "variable", var->Name().c_str()); + if (_type == Type::VARIABLE) { + _variable.Save(data, "variable"); } obs_data_set_int(data, "type", static_cast(_type)); obs_data_set_obj(obj, name, data); @@ -38,8 +37,7 @@ void NumberVariable::Load(obs_data_t *obj, const char *name) } else { assert(false); } - auto variableName = obs_data_get_string(data, "variable"); - _variable = GetWeakVariableByName(variableName); + _variable.Load(data, "variable"); _type = static_cast(obs_data_get_int(data, "type")); obs_data_release(data); } diff --git a/lib/variables/variable-string.cpp b/lib/variables/variable-string.cpp index 31f5c2c0..f9907651 100644 --- a/lib/variables/variable-string.cpp +++ b/lib/variables/variable-string.cpp @@ -1,5 +1,6 @@ #include "variable-string.hpp" #include "utility.hpp" +#include "variable-ref.hpp" namespace advss { @@ -50,6 +51,7 @@ void StringVariable::Load(obs_data_t *obj, const char *name) void StringVariable::Save(obs_data_t *obj, const char *name) const { obs_data_set_string(obj, name, _value.c_str()); + ReportVariableRefsInText(_value); } void StringVariable::ResolveVariables() diff --git a/plugins/base/macro-action-screenshot.cpp b/plugins/base/macro-action-screenshot.cpp index 844770fa..496ac8a9 100644 --- a/plugins/base/macro-action-screenshot.cpp +++ b/plugins/base/macro-action-screenshot.cpp @@ -116,8 +116,7 @@ bool MacroActionScreenshot::Save(obs_data_t *obj) const obs_data_set_int(obj, "saveType", static_cast(_saveType)); obs_data_set_int(obj, "targetType", static_cast(_targetType)); _path.Save(obj, "savePath"); - obs_data_set_string(obj, "variable", - GetWeakVariableName(_variable).c_str()); + _variable.Save(obj, "variable"); obs_data_set_int(obj, "version", 1); return true; } @@ -131,7 +130,7 @@ bool MacroActionScreenshot::Load(obs_data_t *obj) _targetType = static_cast(obs_data_get_int(obj, "targetType")); _path.Load(obj, "savePath"); - _variable = GetWeakVariableByName(obs_data_get_string(obj, "variable")); + _variable.Load(obj, "variable"); // TODO: Remove fallback for older versions if (!obs_data_has_user_value(obj, "version")) { diff --git a/plugins/base/macro-action-screenshot.hpp b/plugins/base/macro-action-screenshot.hpp index 9fee1ce8..4305f96c 100644 --- a/plugins/base/macro-action-screenshot.hpp +++ b/plugins/base/macro-action-screenshot.hpp @@ -4,6 +4,7 @@ #include "scene-selection.hpp" #include "screenshot-helper.hpp" #include "source-selection.hpp" +#include "variable-ref.hpp" #include "variable.hpp" #include @@ -31,7 +32,7 @@ public: SceneSelection _scene; SourceSelection _source; StringVariable _path = obs_module_text("AdvSceneSwitcher.enterPath"); - std::weak_ptr _variable; + VariableRef _variable; private: void FrontendScreenshot(OBSWeakSource &) const; diff --git a/plugins/base/macro-action-wait.cpp b/plugins/base/macro-action-wait.cpp index 112438f1..0873aed5 100644 --- a/plugins/base/macro-action-wait.cpp +++ b/plugins/base/macro-action-wait.cpp @@ -176,8 +176,7 @@ bool MacroActionWait::Save(obs_data_t *obj) const obs_data_set_int(obj, "version", 1); _duration.Save(obj); _duration2.Save(obj, "duration2"); - obs_data_set_string(obj, "variableName", - GetWeakVariableName(_variable).c_str()); + _variable.Save(obj, "variableName"); obs_data_set_int(obj, "condition", static_cast(_condition)); _strValue.Save(obj, "strValue"); _numValue.Save(obj, "numValue"); @@ -200,8 +199,7 @@ bool MacroActionWait::Load(obs_data_t *obj) obs_data_get_int(obj, "displayUnit2"))); } _duration.Load(obj); - _variable = - GetWeakVariableByName(obs_data_get_string(obj, "variableName")); + _variable.Load(obj, "variableName"); _condition = static_cast(obs_data_get_int(obj, "condition")); _strValue.Load(obj, "strValue"); _numValue.Load(obj, "numValue"); diff --git a/plugins/base/macro-action-wait.hpp b/plugins/base/macro-action-wait.hpp index 71276d3d..51f5b097 100644 --- a/plugins/base/macro-action-wait.hpp +++ b/plugins/base/macro-action-wait.hpp @@ -2,6 +2,7 @@ #include "macro-action-edit.hpp" #include "duration-control.hpp" #include "regex-config.hpp" +#include "variable-ref.hpp" #include "variable-spinbox.hpp" #include "variable-text-edit.hpp" #include "variable.hpp" @@ -44,7 +45,7 @@ public: LESS_THAN, GREATER_THAN, }; - std::weak_ptr _variable; + VariableRef _variable; Condition _condition = Condition::EQUALS; StringVariable _strValue = ""; DoubleVariable _numValue = 0.0; diff --git a/plugins/base/utils/filter-selection.cpp b/plugins/base/utils/filter-selection.cpp index e1c406ee..b9c619b6 100644 --- a/plugins/base/utils/filter-selection.cpp +++ b/plugins/base/utils/filter-selection.cpp @@ -20,15 +20,9 @@ void FilterSelection::Save(obs_data_t *obj, const char *name) const _filter ? GetWeakSourceName(_filter).c_str() : _filterName.c_str()); break; - case Type::VARIABLE: { - auto var = _variable.lock(); - if (!var) { - break; - } - obs_data_set_string(data, nameSaveName.data(), - var->Name().c_str()); + case Type::VARIABLE: + _variable.Save(data, nameSaveName.data()); break; - } default: break; } diff --git a/plugins/base/utils/filter-selection.hpp b/plugins/base/utils/filter-selection.hpp index 4544a89d..ecc0541b 100644 --- a/plugins/base/utils/filter-selection.hpp +++ b/plugins/base/utils/filter-selection.hpp @@ -1,6 +1,7 @@ #pragma once #include "source-selection.hpp" #include "filter-combo-box.hpp" +#include "variable-ref.hpp" namespace advss { @@ -32,7 +33,7 @@ private: // Storing the name separately as depending on the source selection // the filter source might not be available at the moment. std::string _filterName = ""; - std::weak_ptr _variable; + VariableRef _variable; Type _type = Type::SOURCE; friend class FilterSelectionWidget; }; diff --git a/plugins/base/utils/scene-item-selection.cpp b/plugins/base/utils/scene-item-selection.cpp index f4a91b69..a7325bc6 100644 --- a/plugins/base/utils/scene-item-selection.cpp +++ b/plugins/base/utils/scene-item-selection.cpp @@ -205,14 +205,9 @@ void SceneItemSelection::Save(obs_data_t *obj, const char *name) const obs_data_set_string(data, itemSaveName.data(), GetWeakSourceName(_source).c_str()); break; - case SceneItemSelection::Type::VARIABLE_NAME: { - auto var = _variable.lock(); - if (var) { - obs_data_set_string(data, itemSaveName.data(), - var->Name().c_str()); - } + case SceneItemSelection::Type::VARIABLE_NAME: + _variable.Save(data, itemSaveName.data()); break; - } case SceneItemSelection::Type::SOURCE_NAME_PATTERN: _pattern.Save(data, patternSaveName.data()); _regex.Save(data); diff --git a/plugins/base/utils/scene-item-selection.hpp b/plugins/base/utils/scene-item-selection.hpp index bfa98952..4eb8aaad 100644 --- a/plugins/base/utils/scene-item-selection.hpp +++ b/plugins/base/utils/scene-item-selection.hpp @@ -3,6 +3,7 @@ #include "filter-combo-box.hpp" #include "variable-spinbox.hpp" #include "variable-line-edit.hpp" +#include "variable-ref.hpp" #include "variable-string.hpp" #include "regex-config.hpp" @@ -77,7 +78,7 @@ private: Type _type = Type::SOURCE_NAME; OBSWeakSource _source; - std::weak_ptr _variable; + VariableRef _variable; IntVariable _index = 1; IntVariable _indexEnd = 1; NameConflictSelection _nameConflictSelectionType = diff --git a/plugins/twitch/macro-action-twitch.cpp b/plugins/twitch/macro-action-twitch.cpp index 571c9f66..e2851489 100644 --- a/plugins/twitch/macro-action-twitch.cpp +++ b/plugins/twitch/macro-action-twitch.cpp @@ -1292,8 +1292,7 @@ bool MacroActionTwitch::Save(obs_data_t *obj) const obs_data_set_int(obj, "pollEndStatus", static_cast(_pollEndStatus)); _pointsReward.Save(obj); - obs_data_set_string(obj, "rewardVariable", - GetWeakVariableName(_rewardVariable).c_str()); + _rewardVariable.Save(obj, "rewardVariable"); obs_data_set_bool(obj, "useVariableForRewardSelection", _useVariableForRewardSelection); @@ -1334,8 +1333,7 @@ bool MacroActionTwitch::Load(obs_data_t *obj) _pollEndStatus = static_cast( obs_data_get_int(obj, "pollEndStatus")); _pointsReward.Load(obj); - _rewardVariable = GetWeakVariableByName( - obs_data_get_string(obj, "rewardVariable")); + _rewardVariable.Load(obj, "rewardVariable"); _useVariableForRewardSelection = obs_data_get_bool(obj, "useVariableForRewardSelection"); diff --git a/plugins/twitch/macro-action-twitch.hpp b/plugins/twitch/macro-action-twitch.hpp index 90f6e788..45ad4341 100644 --- a/plugins/twitch/macro-action-twitch.hpp +++ b/plugins/twitch/macro-action-twitch.hpp @@ -10,6 +10,7 @@ #include "tag-selection.hpp" #include +#include #include #include #include @@ -197,7 +198,7 @@ public: DoubleVariable _userId = 0; StringVariable _banReason = ""; TwitchPointsReward _pointsReward; - std::weak_ptr _rewardVariable; + VariableRef _rewardVariable; bool _useVariableForRewardSelection = false; StringVariable _pollTitle = "Poll question"; StringVariable _pollChoices = "Choice 1\nChoice 2"; diff --git a/tests/test-variable.cpp b/tests/test-variable.cpp index 10442cb2..c9c4a12a 100644 --- a/tests/test-variable.cpp +++ b/tests/test-variable.cpp @@ -1,6 +1,8 @@ #include "catch.hpp" +#include #include +#include #include #include @@ -118,5 +120,39 @@ TEST_CASE("VariableRef", "[variable]") REQUIRE(outer.Counts().at("var") == 1); } + SECTION("Number variable reports only when using a variable") + { + OBSDataAutoRelease data = obs_data_create(); + OBSDataAutoRelease numberData = obs_data_create(); + obs_data_set_string(numberData, "variable", "var"); + obs_data_set_int(numberData, "type", 1); + obs_data_set_obj(data, "number", numberData); + + advss::IntVariable number; + number.Load(data, "number"); + { + advss::VariableRefCollector collector; + number.Save(data, "number"); + REQUIRE(collector.Counts().at("var") == 1); + } + + obs_data_set_int(numberData, "type", 0); + obs_data_set_obj(data, "number", numberData); + number.Load(data, "number"); + advss::VariableRefCollector collector; + number.Save(data, "number"); + REQUIRE(collector.Counts().empty()); + } + + SECTION("String variable reports text references") + { + advss::StringVariable text = "${var} and ${var2}"; + advss::VariableRefCollector collector; + OBSDataAutoRelease data = obs_data_create(); + text.Save(data, "text"); + REQUIRE(collector.Counts().at("var") == 1); + REQUIRE(collector.Counts().at("var2") == 1); + } + advss::GetVariables().clear(); }