mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Unify "Push" actions of objects.
This commit is contained in:
@@ -791,6 +791,47 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
|
||||
.AddParameter("string", _("Variable"))
|
||||
.SetHidden(); // Deprecated.
|
||||
|
||||
obj.AddAction(
|
||||
"PushStringToObjectVariable",
|
||||
_("Add text variable"),
|
||||
_("Adds a text (string) to the end of an object array variable."),
|
||||
_("Add value _PARAM2_ to array variable _PARAM1_ of _PARAM0_"),
|
||||
_("Variables/Arrays and structures"),
|
||||
"res/actions/var24.png",
|
||||
"res/actions/var.png")
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("objectvar", _("Array variable"))
|
||||
.AddParameter("string", _("Text to add"))
|
||||
.MarkAsAdvanced()
|
||||
.SetRelevantForLayoutEventsOnly();
|
||||
|
||||
obj.AddAction("PushNumberToObjectVariable",
|
||||
_("Add variable array value"),
|
||||
_("Adds a number to the end of an object array variable."),
|
||||
_("Add value _PARAM2_ to array variable _PARAM1_ of _PARAM0_"),
|
||||
_("Variables/Arrays and structures"),
|
||||
"res/actions/var24.png",
|
||||
"res/actions/var.png")
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("objectvar", _("Array variable"))
|
||||
.AddParameter("expression", _("Number to add"))
|
||||
.MarkAsAdvanced()
|
||||
.SetRelevantForLayoutEventsOnly();
|
||||
|
||||
obj.AddAction(
|
||||
"PushBooleanToObjectVariable",
|
||||
_("Add boolean variable"),
|
||||
_("Adds a boolean to the end of an object array variable."),
|
||||
_("Add value _PARAM2_ to array variable _PARAM1_ of _PARAM0_"),
|
||||
_("Variables/Arrays and structures"),
|
||||
"res/actions/var24.png",
|
||||
"res/actions/var.png")
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("objectvar", _("Array variable"))
|
||||
.AddParameter("trueorfalse", _("Boolean to add"))
|
||||
.MarkAsAdvanced()
|
||||
.SetRelevantForLayoutEventsOnly();
|
||||
|
||||
obj.AddAction(
|
||||
"ObjectVariablePush",
|
||||
_("Add existing variable"),
|
||||
@@ -818,7 +859,8 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("objectvar", _("Array variable"))
|
||||
.AddParameter("string", _("Text to add"))
|
||||
.MarkAsAdvanced();
|
||||
.MarkAsAdvanced()
|
||||
.SetRelevantForFunctionEventsOnly();
|
||||
|
||||
obj.AddAction("ObjectVariablePushNumber",
|
||||
_("Add number variable"),
|
||||
@@ -830,7 +872,8 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("objectvar", _("Array variable"))
|
||||
.AddParameter("expression", _("Number to add"))
|
||||
.MarkAsAdvanced();
|
||||
.MarkAsAdvanced()
|
||||
.SetRelevantForFunctionEventsOnly();
|
||||
|
||||
obj.AddAction(
|
||||
"ObjectVariablePushBool",
|
||||
@@ -843,7 +886,8 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
|
||||
.AddParameter("object", _("Object"))
|
||||
.AddParameter("objectvar", _("Array variable"))
|
||||
.AddParameter("trueorfalse", _("Boolean to add"))
|
||||
.MarkAsAdvanced();
|
||||
.MarkAsAdvanced()
|
||||
.SetRelevantForFunctionEventsOnly();
|
||||
|
||||
obj.AddAction(
|
||||
"ObjectVariableRemoveAt",
|
||||
|
@@ -209,7 +209,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsVariablesExtension(
|
||||
|
||||
extension
|
||||
.AddAction("PushNumber",
|
||||
_("Add array value"),
|
||||
_("Add variable array value"),
|
||||
_("Adds a number at the end of an array variable."),
|
||||
_("Add the value _PARAM1_ to array variable _PARAM0_"),
|
||||
_("Arrays and structures"),
|
||||
|
@@ -15,6 +15,7 @@ const gd::String VariableInstructionSwitcher::variableSetterIdentifier = "SetNum
|
||||
const gd::String VariableInstructionSwitcher::variablePushIdentifier = "PushNumber";
|
||||
const gd::String VariableInstructionSwitcher::objectVariableGetterIdentifier = "NumberObjectVariable";
|
||||
const gd::String VariableInstructionSwitcher::objectVariableSetterIdentifier = "SetNumberObjectVariable";
|
||||
const gd::String VariableInstructionSwitcher::objectVariablePushIdentifier = "PushNumberToObjectVariable";
|
||||
const gd::String VariableInstructionSwitcher::unknownInstructionIdentifier = "";
|
||||
|
||||
bool VariableInstructionSwitcher::IsSwitchableVariableInstruction(
|
||||
@@ -37,7 +38,11 @@ bool VariableInstructionSwitcher::IsSwitchableVariableInstruction(
|
||||
|
||||
instructionType == "SetNumberObjectVariable" ||
|
||||
instructionType == "SetStringObjectVariable" ||
|
||||
instructionType == "SetBooleanObjectVariable";
|
||||
instructionType == "SetBooleanObjectVariable" ||
|
||||
|
||||
instructionType == "PushNumberToObjectVariable" ||
|
||||
instructionType == "PushStringToObjectVariable" ||
|
||||
instructionType == "PushBooleanToObjectVariable";
|
||||
}
|
||||
|
||||
const gd::String &
|
||||
@@ -68,6 +73,11 @@ VariableInstructionSwitcher::GetSwitchableVariableInstructionIdentifier(
|
||||
instructionType == "SetBooleanObjectVariable"
|
||||
? VariableInstructionSwitcher::objectVariableSetterIdentifier :
|
||||
|
||||
instructionType == "PushNumberToObjectVariable" ||
|
||||
instructionType == "PushStringToObjectVariable" ||
|
||||
instructionType == "PushBooleanToObjectVariable"
|
||||
? VariableInstructionSwitcher::objectVariablePushIdentifier :
|
||||
|
||||
VariableInstructionSwitcher::unknownInstructionIdentifier;
|
||||
}
|
||||
|
||||
@@ -77,21 +87,24 @@ VariableInstructionSwitcher::GetSwitchableInstructionVariableType(const gd::Stri
|
||||
instructionType == "SetNumberVariable" ||
|
||||
instructionType == "PushNumber" ||
|
||||
instructionType == "NumberObjectVariable" ||
|
||||
instructionType == "SetNumberObjectVariable"
|
||||
instructionType == "SetNumberObjectVariable" ||
|
||||
instructionType == "PushNumberToObjectVariable"
|
||||
? gd::Variable::Number :
|
||||
|
||||
instructionType == "StringVariable" ||
|
||||
instructionType == "SetStringVariable" ||
|
||||
instructionType == "PushString" ||
|
||||
instructionType == "StringObjectVariable" ||
|
||||
instructionType == "SetStringObjectVariable"
|
||||
instructionType == "SetStringObjectVariable" ||
|
||||
instructionType == "PushStringToObjectVariable"
|
||||
? gd::Variable::String :
|
||||
|
||||
instructionType == "BooleanVariable" ||
|
||||
instructionType == "SetBooleanVariable" ||
|
||||
instructionType == "PushBoolean" ||
|
||||
instructionType == "BooleanObjectVariable" ||
|
||||
instructionType == "SetBooleanObjectVariable"
|
||||
instructionType == "SetBooleanObjectVariable" ||
|
||||
instructionType == "PushBooleanToObjectVariable"
|
||||
? gd::Variable::Boolean :
|
||||
|
||||
gd::Variable::Unknown;
|
||||
@@ -164,6 +177,19 @@ void VariableInstructionSwitcher::SwitchVariableInstructionType(
|
||||
instruction.SetType("SetBooleanObjectVariable");
|
||||
}
|
||||
}
|
||||
else if (instruction.GetType() == "PushNumberToObjectVariable" ||
|
||||
instruction.GetType() == "PushStringToObjectVariable" ||
|
||||
instruction.GetType() == "PushBooleanToObjectVariable") {
|
||||
if (variableType == gd::Variable::Type::Number) {
|
||||
instruction.SetType("PushNumberToObjectVariable");
|
||||
}
|
||||
else if (variableType == gd::Variable::Type::String) {
|
||||
instruction.SetType("PushStringToObjectVariable");
|
||||
}
|
||||
else if (variableType == gd::Variable::Type::Boolean) {
|
||||
instruction.SetType("PushBooleanToObjectVariable");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gd
|
||||
|
@@ -55,6 +55,7 @@ private:
|
||||
static const gd::String variablePushIdentifier;
|
||||
static const gd::String objectVariableGetterIdentifier;
|
||||
static const gd::String objectVariableSetterIdentifier;
|
||||
static const gd::String objectVariablePushIdentifier;
|
||||
static const gd::String unknownInstructionIdentifier;
|
||||
};
|
||||
} // namespace gd
|
||||
|
@@ -286,6 +286,9 @@ BaseObjectExtension::BaseObjectExtension() {
|
||||
objectActions["ObjectVariablePushString"].SetFunctionName("valuePush");
|
||||
objectActions["ObjectVariablePushNumber"].SetFunctionName("valuePush");
|
||||
objectActions["ObjectVariablePushBool"].SetFunctionName("valuePush");
|
||||
objectActions["PushStringToObjectVariable"].SetFunctionName("valuePush");
|
||||
objectActions["PushNumberToObjectVariable"].SetFunctionName("valuePush");
|
||||
objectActions["PushBooleanToObjectVariable"].SetFunctionName("valuePush");
|
||||
objectActions["ObjectVariableRemoveAt"].SetFunctionName("variableRemoveAt");
|
||||
objectConditions["ObjectVariableChildCount"].SetFunctionName(
|
||||
"getVariableChildCount");
|
||||
|
@@ -71,12 +71,21 @@ const getVariableTypeFromParameters = (
|
||||
) {
|
||||
const objectName = instruction.getParameter(0).getPlainString();
|
||||
|
||||
return gd.ExpressionVariableTypeFinder.getVariableType(
|
||||
const variableType = gd.ExpressionVariableTypeFinder.getVariableType(
|
||||
platform,
|
||||
projectScopedContainers,
|
||||
instruction.getParameter(1).getRootNode(),
|
||||
objectName
|
||||
);
|
||||
return variableType === gd.Variable.Array
|
||||
? // "Push" actions need the child type to be able to switch.
|
||||
gd.ExpressionVariableTypeFinder.getArrayVariableType(
|
||||
platform,
|
||||
projectScopedContainers,
|
||||
instruction.getParameter(1).getRootNode(),
|
||||
objectName
|
||||
)
|
||||
: variableType;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
Reference in New Issue
Block a user