mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-22 01:44:49 -05:00
The "core" macro conditions and actions have been extracted out to the "base" plugin. The library now mostly contains functionality which is required across all plugins and (e.g. definitions for macro segments). The goal is to reduce the complexity and cross-dependencies and group the source files in a better way. This should relsove the "library limit of 65535 objects exceeded" build issue occuring in some Windows build environments.
85 lines
1.8 KiB
C++
85 lines
1.8 KiB
C++
#include "macro-ref.hpp"
|
|
#include "macro.hpp"
|
|
|
|
namespace advss {
|
|
|
|
MacroRef::MacroRef(std::string name)
|
|
{
|
|
_macro = GetWeakMacroByName(name.c_str());
|
|
}
|
|
|
|
void MacroRef::Save(obs_data_t *obj) const
|
|
{
|
|
if (auto macro = _macro.lock()) {
|
|
obs_data_set_string(obj, "macro", macro->Name().c_str());
|
|
}
|
|
}
|
|
void MacroRef::Load(obs_data_t *obj)
|
|
{
|
|
auto name = obs_data_get_string(obj, "macro");
|
|
_postLoadName = name;
|
|
_macro = GetWeakMacroByName(name);
|
|
}
|
|
|
|
void MacroRef::PostLoad()
|
|
{
|
|
_macro = GetWeakMacroByName(_postLoadName.c_str());
|
|
}
|
|
|
|
void MacroRef::operator=(const QString &name)
|
|
{
|
|
_macro = GetWeakMacroByName(name.toStdString().c_str());
|
|
}
|
|
|
|
void MacroRef::operator=(const std::shared_ptr<Macro> ¯o)
|
|
{
|
|
_macro = macro;
|
|
}
|
|
|
|
std::shared_ptr<Macro> MacroRef::GetMacro() const
|
|
{
|
|
return _macro.lock();
|
|
}
|
|
|
|
std::string MacroRef::Name() const
|
|
{
|
|
if (auto macro = GetMacro()) {
|
|
return macro->Name();
|
|
}
|
|
return "";
|
|
}
|
|
|
|
void SaveMacroList(obs_data_t *obj, const std::vector<MacroRef> ¯os,
|
|
const std::string &name)
|
|
{
|
|
obs_data_array_t *array = obs_data_array_create();
|
|
for (auto &m : macros) {
|
|
if (!m.GetMacro()) {
|
|
continue;
|
|
}
|
|
obs_data_t *array_obj = obs_data_create();
|
|
m.Save(array_obj);
|
|
obs_data_array_push_back(array, array_obj);
|
|
obs_data_release(array_obj);
|
|
}
|
|
obs_data_set_array(obj, name.c_str(), array);
|
|
obs_data_array_release(array);
|
|
}
|
|
|
|
void LoadMacroList(obs_data_t *obj, std::vector<MacroRef> ¯os,
|
|
const std::string &name)
|
|
{
|
|
obs_data_array_t *array = obs_data_get_array(obj, name.c_str());
|
|
size_t count = obs_data_array_count(array);
|
|
for (size_t i = 0; i < count; i++) {
|
|
obs_data_t *array_obj = obs_data_array_item(array, i);
|
|
MacroRef ref;
|
|
ref.Load(array_obj);
|
|
macros.push_back(ref);
|
|
obs_data_release(array_obj);
|
|
}
|
|
obs_data_array_release(array);
|
|
}
|
|
|
|
} // namespace advss
|