Add option to round variable to nearest integer

This commit is contained in:
WarmUpTill
2023-01-28 00:59:47 +01:00
committed by WarmUpTill
parent d094c189d3
commit fc80d0b5f3
3 changed files with 11 additions and 0 deletions

View File

@@ -25,6 +25,8 @@ static std::map<MacroActionVariable::Type, std::string> actionTypes = {
"AdvSceneSwitcher.action.variable.type.setConditionValue"},
{MacroActionVariable::Type::SET_ACTION_VALUE,
"AdvSceneSwitcher.action.variable.type.setActionValue"},
{MacroActionVariable::Type::ROUND_TO_INT,
"AdvSceneSwitcher.action.variable.type.roundToInt"},
};
static void apppend(Variable &var, const std::string &value)
@@ -95,6 +97,13 @@ bool MacroActionVariable::PerformAction()
var->SetValue(segment->GetVariableValue());
break;
}
case Type::ROUND_TO_INT: {
double curValue;
if (!var->DoubleValue(curValue)) {
return true;
}
var->SetValue(std::to_string(int(std::round(curValue))));
}
}
return true;

View File

@@ -28,6 +28,7 @@ public:
DECREMENT,
SET_CONDITION_VALUE,
SET_ACTION_VALUE,
ROUND_TO_INT,
};
Type _type = Type::SET_FIXED_VALUE;