Skip to content

Commit

Permalink
Add temp variable support to date condition
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Nov 20, 2023
1 parent 30208fe commit 21ae1ec
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
8 changes: 8 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,14 @@ AdvSceneSwitcher.tempVar.timer.minutes="Minutes"
AdvSceneSwitcher.tempVar.timer.hours="Hours"
AdvSceneSwitcher.tempVar.timer.days="Days"

AdvSceneSwitcher.tempVar.date.year="Year"
AdvSceneSwitcher.tempVar.date.month="Month"
AdvSceneSwitcher.tempVar.date.day="Day"
AdvSceneSwitcher.tempVar.date.hour="Hour"
AdvSceneSwitcher.tempVar.date.minute="Minute"
AdvSceneSwitcher.tempVar.date.second="Second"
AdvSceneSwitcher.tempVar.date.dayOfWeek="Day of week"

AdvSceneSwitcher.selectScene="--select scene--"
AdvSceneSwitcher.selectPreviousScene="Previous Scene"
AdvSceneSwitcher.selectCurrentScene="Current Scene"
Expand Down
36 changes: 34 additions & 2 deletions src/macro-core/macro-condition-date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const static std::map<MacroConditionDate::Day, std::string> dayOfWeekNames = {
bool MacroConditionDate::CheckDayOfWeek(int64_t msSinceLastCheck)
{
QDateTime cur = QDateTime::currentDateTime();
SetVariableValue(cur.toString().toStdString());
SetVariables(cur);

if (_dayOfWeek != Day::ANY &&
cur.date().dayOfWeek() != static_cast<int>(_dayOfWeek)) {
return false;
Expand Down Expand Up @@ -133,7 +134,7 @@ bool MacroConditionDate::CheckRegularDate(int64_t msSinceLastCheck)
{
bool match = false;
QDateTime cur = QDateTime::currentDateTime();
SetVariableValue(cur.toString().toStdString());
SetVariables(cur);

if (_ignoreDate) {
_dateTime.setDate(cur.date());
Expand Down Expand Up @@ -304,6 +305,37 @@ QDateTime MacroConditionDate::GetNextMatchDateTime() const
return _dateTime;
}

void MacroConditionDate::SetVariables(const QDateTime &date)
{
SetVariableValue(date.toString().toStdString());

SetTempVarValue("year", std::to_string(date.date().year()));
SetTempVarValue("month", std::to_string(date.date().month()));
SetTempVarValue("day", std::to_string(date.date().day()));
SetTempVarValue("hour", std::to_string(date.time().hour()));
SetTempVarValue("minute", std::to_string(date.time().minute()));
SetTempVarValue("second", std::to_string(date.time().second()));
SetTempVarValue("dayOfWeek", std::to_string(date.date().dayOfWeek()));
}

void MacroConditionDate::SetupTempVars()
{
MacroCondition::SetupTempVars();
AddTempvar("year",
obs_module_text("AdvSceneSwitcher.tempVar.date.year"));
AddTempvar("month",
obs_module_text("AdvSceneSwitcher.tempVar.date.month"));
AddTempvar("day", obs_module_text("AdvSceneSwitcher.tempVar.date.day"));
AddTempvar("hour",
obs_module_text("AdvSceneSwitcher.tempVar.date.hour"));
AddTempvar("minute",
obs_module_text("AdvSceneSwitcher.tempVar.date.minute"));
AddTempvar("second",
obs_module_text("AdvSceneSwitcher.tempVar.date.second"));
AddTempvar("dayOfWeek",
obs_module_text("AdvSceneSwitcher.tempVar.date.dayOfWeek"));
}

static inline void populateDaySelection(QComboBox *list)
{
for (auto entry : dayOfWeekNames) {
Expand Down
2 changes: 2 additions & 0 deletions src/macro-core/macro-condition-date.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class MacroConditionDate : public MacroCondition {
bool CheckRegularDate(int64_t);
bool CheckBetween(const QDateTime &now);
bool CheckPattern(QDateTime now, int64_t secondsSinceLastCheck);
void SetVariables(const QDateTime &date);
void SetupTempVars();

QDateTime _dateTime = QDateTime::currentDateTime();
QDateTime _dateTime2 = QDateTime::currentDateTime();
Expand Down

0 comments on commit 21ae1ec

Please sign in to comment.