feat: Add 'repeat' option to 'Lua Script' special function (#3338)

* Add support for the '1x' repeat option for 'Play Script' special functions.

* Add Companion and B&W radio support.

* Fix B&W radio logic and layout.

* Add translation hooks.
This commit is contained in:
philmoz
2023-04-10 11:00:50 +10:00
committed by GitHub
parent 6138f29da6
commit 227780d784
11 changed files with 123 additions and 52 deletions
@@ -394,6 +394,19 @@ AbstractStaticItemModel * CustomFunctionData::repeatItemModel()
return mdl;
}
// static
AbstractStaticItemModel * CustomFunctionData::repeatLuaItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("customfunctiondata.repeatLua");
mdl->appendToItemList(tr("On"), 0);
mdl->appendToItemList(tr("1x"), 1);
mdl->loadItemList();
return mdl;
}
// static
AbstractStaticItemModel * CustomFunctionData::playSoundItemModel()
{
@@ -136,6 +136,7 @@ class CustomFunctionData {
static QStringList gvarAdjustModeStringList();
static QString gvarAdjustModeToString(const int value);
static AbstractStaticItemModel * repeatItemModel();
static AbstractStaticItemModel * repeatLuaItemModel();
static AbstractStaticItemModel * playSoundItemModel();
static AbstractStaticItemModel * harpicItemModel();
static AbstractStaticItemModel * gvarAdjustModeItemModel();
@@ -37,7 +37,8 @@ static bool fnHasRepeat(AssignFunc fn)
|| (fn == FuncPlayValue)
|| (fn == FuncPlayHaptic)
|| (fn == FuncPlaySound)
|| (fn == FuncSetScreen);
|| (fn == FuncSetScreen)
|| (fn == FuncPlayScript);
}
static const YamlLookupTable customFnLut = {
@@ -225,7 +226,9 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
if (add_comma) {
def += ",";
}
if (rhs.repeatParam == 0) {
if (rhs.func == FuncPlayScript) {
def += ((rhs.repeatParam == 0) ? "On" : "1x");
} else if (rhs.repeatParam == 0) {
def += "1x";
} else if (rhs.repeatParam == -1) {
def += "!1x";
@@ -374,7 +377,9 @@ bool convert<CustomFunctionData>::decode(const Node& node,
} else if(fnHasRepeat(rhs.func)) {
std::string repeat;
getline(def, repeat);
if (repeat == "1x") {
if (rhs.func == FuncPlayScript) {
rhs.repeatParam = (repeat == "1x") ? 1 : 0;
} else if (repeat == "1x") {
rhs.repeatParam = 0;
} else if (repeat == "!1x") {
rhs.repeatParam = -1;