Skip to content

Commit

Permalink
Adapt extension properties to new sentences + various changes
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed Dec 27, 2019
1 parent df2185a commit 5df3afd
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Core/GDCore/Extensions/Builtin/BaseObjectExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
"MettreXY",
_("Position of an object"),
_("Change the position of an object."),
_("Do _PARAM1__PARAM2_;_PARAM3__PARAM4_ to the position of _PARAM0_"),
_("Change the position of _PARAM0_: _PARAM1_ _PARAM2_ (x axis), _PARAM3_ _PARAM4_ (y axis)"),
_("Position"),
"res/actions/position24.png",
"res/actions/position.png")
Expand Down
53 changes: 39 additions & 14 deletions Core/GDCore/Extensions/Metadata/InstructionMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,31 @@ InstructionMetadata& InstructionMetadata::UseStandardOperatorParameters(
SetManipulatedType(type);

AddParameter("operator", _("Modification's sign"));
AddParameter(type == "number" ? "expression" : type, _("TODO"));
AddParameter(type == "number" ? "expression" : type, _("Value"));
size_t operatorParamIndex = parameters.size() - 2;
size_t valueParamIndex = parameters.size() - 1;

if (isObjectInstruction || isBehaviorInstruction) {
sentence = "Change " + sentence + " of _PARAM0_: _PARAM" +
gd::String::From(operatorParamIndex) + "_ _PARAM" +
gd::String::From(valueParamIndex) + "_"; // TODO: translation
gd::String templateSentence =
_("Change <subject> of _PARAM0_: <operator> <value>");

sentence =
templateSentence.FindAndReplace("<subject>", sentence)
.FindAndReplace(
"<operator>",
"_PARAM" + gd::String::From(operatorParamIndex) + "_")
.FindAndReplace("<value>",
"_PARAM" + gd::String::From(valueParamIndex) + "_");
} else {
sentence = "Change " + sentence + ": _PARAM" +
gd::String::From(operatorParamIndex) + "_ _PARAM" +
gd::String::From(valueParamIndex) + "_"; // TODO: translation
gd::String templateSentence = _("Change <subject>: <operator> <value>");

sentence =
templateSentence.FindAndReplace("<subject>", sentence)
.FindAndReplace(
"<operator>",
"_PARAM" + gd::String::From(operatorParamIndex) + "_")
.FindAndReplace("<value>",
"_PARAM" + gd::String::From(valueParamIndex) + "_");
}

return *this;
Expand All @@ -116,18 +129,30 @@ InstructionMetadata::UseStandardRelationalOperatorParameters(
SetManipulatedType(type);

AddParameter("relationalOperator", _("Sign of the test"));
AddParameter("expression", _("TODO"));
AddParameter(type == "number" ? "expression" : type, _("Value to compare"));
size_t operatorParamIndex = parameters.size() - 2;
size_t valueParamIndex = parameters.size() - 1;

if (isObjectInstruction || isBehaviorInstruction) {
sentence = sentence + " of _PARAM0_ _PARAM" +
gd::String::From(operatorParamIndex) + "_ _PARAM" +
gd::String::From(valueParamIndex) + "_"; // TODO: translation
gd::String templateSentence = _("<subject> of _PARAM0_ <operator> <value>");

sentence =
templateSentence.FindAndReplace("<subject>", sentence)
.FindAndReplace(
"<operator>",
"_PARAM" + gd::String::From(operatorParamIndex) + "_")
.FindAndReplace("<value>",
"_PARAM" + gd::String::From(valueParamIndex) + "_");
} else {
sentence = sentence + " _PARAM" + gd::String::From(operatorParamIndex) +
"_ _PARAM" + gd::String::From(valueParamIndex) +
"_"; // TODO: translation
gd::String templateSentence = _("<subject> <operator> <value>");

sentence =
templateSentence.FindAndReplace("<subject>", sentence)
.FindAndReplace(
"<operator>",
"_PARAM" + gd::String::From(operatorParamIndex) + "_")
.FindAndReplace("<value>",
"_PARAM" + gd::String::From(valueParamIndex) + "_");
}

return *this;
Expand Down
46 changes: 33 additions & 13 deletions Core/GDCore/Extensions/Metadata/InstructionMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ class GD_CORE_API ParameterMetadata {
///< i.e. must not be shown in editor
private:
gd::String longDescription; ///< Long description shown in the editor.
gd::String defaultValue; ///< Used as a default value in editor or if an
///< optional parameter is empty.
gd::String name; ///< The name of the parameter to be used in code
///< generation. Optional.
gd::String defaultValue; ///< Used as a default value in editor or if an
///< optional parameter is empty.
gd::String name; ///< The name of the parameter to be used in code
///< generation. Optional.
};

/**
Expand Down Expand Up @@ -355,10 +355,10 @@ class GD_CORE_API InstructionMetadata {
* \brief Add a parameter not displayed in editor.
*
* \param type One of the type handled by GDevelop. This will also determine
* the type of the argument used when calling the function in the generated code.
* \param supplementaryInformation Depends on `type`. For example, when `type ==
* "inlineCode"`, the content of supplementaryInformation is inserted in the
* generated code.
* the type of the argument used when calling the function in the generated
* code. \param supplementaryInformation Depends on `type`. For example, when
* `type == "inlineCode"`, the content of supplementaryInformation is inserted
* in the generated code.
*
* \see EventsCodeGenerator::GenerateParametersCodes
*/
Expand All @@ -371,30 +371,50 @@ class GD_CORE_API InstructionMetadata {
*
* \see AddParameter
*/
InstructionMetadata &SetDefaultValue(gd::String defaultValue_) {
InstructionMetadata &SetDefaultValue(const gd::String &defaultValue_) {
if (!parameters.empty()) parameters.back().SetDefaultValue(defaultValue_);
return *this;
};

/**
* \brief Set the long description shown in the editor for the last added parameter.
* \brief Set the long description shown in the editor for the last added
* parameter.
*
* \see AddParameter
*/
InstructionMetadata &SetParameterLongDescription(gd::String longDescription) {
if (!parameters.empty()) parameters.back().SetLongDescription(longDescription);
InstructionMetadata &SetParameterLongDescription(
const gd::String &longDescription) {
if (!parameters.empty())
parameters.back().SetLongDescription(longDescription);
return *this;
};

/**
* \brief Add the default parameters for an instruction manipulating the
* specified type ("string", "number") with the default operators.
*/
InstructionMetadata &UseStandardOperatorParameters(const gd::String &type);

InstructionMetadata &UseStandardRelationalOperatorParameters(const gd::String &type);
/**
* \brief Add the default parameters for an instruction comparing the
* specified type ("string", "number") with the default relational operators.
*/
InstructionMetadata &UseStandardRelationalOperatorParameters(
const gd::String &type);

/**
* \brief Mark the instruction as an object instruction. Automatically called
* when using `AddAction`/`AddCondition` on an `ObjectMetadata`.
*/
InstructionMetadata &SetIsObjectInstruction() {
isObjectInstruction = true;
return *this;
}

/**
* \brief Mark the instruction as a behavior instruction. Automatically called
* when using `AddAction`/`AddCondition` on a `BehaviorMetadata`.
*/
InstructionMetadata &SetIsBehaviorInstruction() {
isBehaviorInstruction = true;
return *this;
Expand Down
12 changes: 6 additions & 6 deletions Extensions/ParticleSystem/ExtensionSubDeclaration1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void ExtensionSubDeclaration1(gd::ObjectMetadata& obj) {
obj.AddAction("ParticleGravityX",
_("Gravity value on X axis"),
_("Change value of the gravity on X axis."),
_("Do _PARAM1__PARAM2_ to the value of gravity on X axis "
_("Do _PARAM1__PARAM2_ to the gravity on X axis "
"of _PARAM0_"),
_("Advanced"),
"CppPlatform/Extensions/particleSystemicon24.png",
Expand All @@ -338,7 +338,7 @@ void ExtensionSubDeclaration1(gd::ObjectMetadata& obj) {
"ParticleGravityX",
_("Gravity value on X axis"),
_("Compare value of the gravity on X axis."),
_("Value of gravity on X axis of _PARAM0_ is _PARAM1__PARAM2_"),
_("Gravity on X axis of _PARAM0_ is _PARAM1__PARAM2_"),
_("Advanced"),
"CppPlatform/Extensions/particleSystemicon24.png",
"CppPlatform/Extensions/particleSystemicon16.png")
Expand All @@ -350,7 +350,7 @@ void ExtensionSubDeclaration1(gd::ObjectMetadata& obj) {
obj.AddAction("ParticleGravityY",
_("Gravity value on Y axis"),
_("Change value of the gravity on Y axis."),
_("Do _PARAM1__PARAM2_ to the value of gravity on Y axis "
_("Do _PARAM1__PARAM2_ to the gravity on Y axis "
"of _PARAM0_"),
_("Advanced"),
"CppPlatform/Extensions/particleSystemicon24.png",
Expand All @@ -364,7 +364,7 @@ void ExtensionSubDeclaration1(gd::ObjectMetadata& obj) {
"ParticleGravityY",
_("Gravity value on Y axis"),
_("Compare value of the gravity on Y axis."),
_("Value of gravity on Y axis of _PARAM0_ is _PARAM1__PARAM2_"),
_("Gravity on Y axis of _PARAM0_ is _PARAM1__PARAM2_"),
_("Advanced"),
"CppPlatform/Extensions/particleSystemicon24.png",
"CppPlatform/Extensions/particleSystemicon16.png")
Expand All @@ -376,7 +376,7 @@ void ExtensionSubDeclaration1(gd::ObjectMetadata& obj) {
obj.AddAction("ParticleGravityZ",
_("Z Gravity"),
_("Change value of the gravity on Z axis."),
_("Do _PARAM1__PARAM2_ to the direction of gravity on Z axis "
_("Do _PARAM1__PARAM2_ to gravity direction on Z axis "
"of_PARAM0_"),
_("Advanced"),
"CppPlatform/Extensions/particleSystemicon24.png",
Expand All @@ -390,7 +390,7 @@ void ExtensionSubDeclaration1(gd::ObjectMetadata& obj) {
"ParticleGravityZ",
_("Direction of gravity on Z axis"),
_("Test the direction of gravity on Z axis"),
_("Direction of gravity on Z axis of _PARAM0_ is _PARAM1__PARAM2_"),
_("Gravity direction on Z axis of _PARAM0_ is _PARAM1__PARAM2_"),
_("Advanced"),
"CppPlatform/Extensions/particleSystemicon24.png",
"CppPlatform/Extensions/particleSystemicon16.png")
Expand Down
2 changes: 1 addition & 1 deletion Extensions/PlatformBehavior/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void DeclarePlatformBehaviorExtension(gd::PlatformExtension& extension) {
_("Gravity"),
_("Change the gravity applied on an object (in pixels per "
"second per second)."),
_("Do _PARAM2__PARAM3_ to the gravity applied on _PARAM0_"),
_("Do _PARAM2__PARAM3_ to the gravity of _PARAM0_"),
_("Options"),
"CppPlatform/Extensions/platformerobjecticon24.png",
"CppPlatform/Extensions/platformerobjecticon16.png")
Expand Down
4 changes: 4 additions & 0 deletions GDevelop.js/Bindings/Bindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,10 @@ interface InstructionMetadata {
[Const] DOMString type, [Const] DOMString supplementaryInformation);
[Ref] InstructionMetadata SetDefaultValue([Const] DOMString defaultValue);
[Ref] InstructionMetadata SetParameterLongDescription([Const] DOMString longDescription);

[Ref] InstructionMetadata UseStandardOperatorParameters([Const] DOMString type);
[Ref] InstructionMetadata UseStandardRelationalOperatorParameters([Const] DOMString type);

[Ref] InstructionMetadata MarkAsSimple();
[Ref] InstructionMetadata MarkAsAdvanced();
[Ref] InstructionMetadata MarkAsComplex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,36 +331,26 @@ export const declareBehaviorPropertiesInstructionAndExpressions = (
gd.EventsBasedBehavior.getPropertyConditionName(propertyName),
propertyLabel,
i18n._(t`Compare the content of ${propertyLabel}`),
i18n._(t`Property ${propertyName} of _PARAM0_ is _PARAM2__PARAM3_`),
i18n._(t`the property ${propertyName}`),
eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
'res/function.png'
)
)
.addParameter(
'relationalOperator',
i18n._(t`Sign of the test`),
'',
false
)
.addParameter('string', i18n._(t`String to compare against`), '', false)
.useStandardRelationalOperatorParameters('string')
.getCodeExtraInformation()
.setFunctionName(getterName)
.setManipulatedType('string');
.setFunctionName(getterName);

addObjectAndBehaviorParameters(
behaviorMetadata.addScopedAction(
gd.EventsBasedBehavior.getPropertyActionName(propertyName),
propertyLabel,
i18n._(t`Update the content of ${propertyLabel}`),
i18n._(
t`Do _PARAM2__PARAM3_ to property ${propertyName} of _PARAM0_`
),
i18n._(t`Change the content of ${propertyLabel}`),
i18n._(t`the property ${propertyName}`),
eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
'res/function.png'
)
)
.addParameter('operator', i18n._(t`Modification's sign`), '', false)
.addParameter('string', i18n._(t`New value`), '', false)
.useStandardOperatorParameters('string')
.getCodeExtraInformation()
.setFunctionName(setterName)
.setManipulatedType('string')
Expand All @@ -383,44 +373,28 @@ export const declareBehaviorPropertiesInstructionAndExpressions = (
gd.EventsBasedBehavior.getPropertyConditionName(propertyName),
propertyLabel,
i18n._(t`Compare the value of ${propertyLabel}`),
i18n._(t`Property ${propertyName} of _PARAM0_ is _PARAM2__PARAM3_`),
i18n._(t`the property ${propertyName}`),
eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
'res/function.png'
)
)
.addParameter(
'relationalOperator',
i18n._(t`Sign of the test`),
'',
false
)
.addParameter(
'expression',
i18n._(t`Value to compare against`),
'',
false
)
.useStandardRelationalOperatorParameters('number')
.getCodeExtraInformation()
.setFunctionName(getterName)
.setManipulatedType('number');
.setFunctionName(getterName);

addObjectAndBehaviorParameters(
behaviorMetadata.addScopedAction(
gd.EventsBasedBehavior.getPropertyActionName(propertyName),
propertyLabel,
i18n._(t`Update the value of ${propertyLabel}`),
i18n._(
t`Do _PARAM2__PARAM3_ to property ${propertyName} of _PARAM0_`
),
i18n._(t`Change the value of ${propertyLabel}`),
i18n._(t`the property ${propertyName}`),
eventsBasedBehavior.getFullName() || eventsBasedBehavior.getName(),
'res/function.png'
)
)
.addParameter('operator', i18n._(t`Modification's sign`), '', false)
.addParameter('expression', i18n._(t`New value`), '', false)
.useStandardOperatorParameters('number')
.getCodeExtraInformation()
.setFunctionName(setterName)
.setManipulatedType('number')
.setGetter(getterName);
} else if (propertyType === 'Boolean') {
addObjectAndBehaviorParameters(
Expand Down

0 comments on commit 5df3afd

Please sign in to comment.