From 21ae1ec9c4684d1774f626450b6cc87c71f5e92e Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 18 Nov 2023 00:20:30 +0100 Subject: [PATCH] Add temp variable support to date condition --- data/locale/en-US.ini | 8 ++++++ src/macro-core/macro-condition-date.cpp | 36 +++++++++++++++++++++++-- src/macro-core/macro-condition-date.hpp | 2 ++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index f0098ec04..ae93d2156 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -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" diff --git a/src/macro-core/macro-condition-date.cpp b/src/macro-core/macro-condition-date.cpp index 8741bb85e..2ed9dfe1f 100644 --- a/src/macro-core/macro-condition-date.cpp +++ b/src/macro-core/macro-condition-date.cpp @@ -60,7 +60,8 @@ const static std::map 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(_dayOfWeek)) { return false; @@ -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()); @@ -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) { diff --git a/src/macro-core/macro-condition-date.hpp b/src/macro-core/macro-condition-date.hpp index 42d5434b2..6658ccbaf 100644 --- a/src/macro-core/macro-condition-date.hpp +++ b/src/macro-core/macro-condition-date.hpp @@ -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();