Skip to content

Commit

Permalink
Fix property name case in action sentences (#5977)
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H authored Nov 29, 2023
1 parent 3744e98 commit 8c50764
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Core/GDCore/Extensions/Metadata/InstructionMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ InstructionMetadata::UseStandardRelationalOperatorParameters(
gd::String templateSentence = _("<subject> of _PARAM0_ <operator> <value>");

sentence =
templateSentence.FindAndReplace("<subject>", sentence)
templateSentence.FindAndReplace("<subject>", sentence.CapitalizeFirstLetter())
.FindAndReplace(
"<operator>",
"_PARAM" + gd::String::From(operatorParamIndex) + "_")
Expand All @@ -200,7 +200,7 @@ InstructionMetadata::UseStandardRelationalOperatorParameters(
gd::String templateSentence = _("<subject> <operator> <value>");

sentence =
templateSentence.FindAndReplace("<subject>", sentence)
templateSentence.FindAndReplace("<subject>", sentence.CapitalizeFirstLetter())
.FindAndReplace(
"<operator>",
"_PARAM" + gd::String::From(operatorParamIndex) + "_")
Expand Down
5 changes: 5 additions & 0 deletions Core/GDCore/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ String String::LowerCase() const
return lowerCasedStr;
}

String String::CapitalizeFirstLetter() const
{
return size() < 1 ? *this : substr(0, 1).UpperCase() + substr(1);
}

String String::FindAndReplace(String search, String replacement, bool all) const
{
gd::String result(*this);
Expand Down
5 changes: 5 additions & 0 deletions Core/GDCore/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,11 @@ class GD_CORE_API String
*/
String LowerCase() const;

/**
* \brief Returns the string with the first letter in upper case.
*/
String CapitalizeFirstLetter() const;

/**
* \brief Searches a string for a specified substring and returns a new string where all occurrences of this substring is replaced.
* \param search The string that will be replaced by the new string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,12 +953,6 @@ MetadataDeclarationHelper::UncapitalizeFirstLetter(const gd::String &string) {
: string.substr(0, 1).LowerCase() + string.substr(1);
}

gd::String
MetadataDeclarationHelper::CapitalizeFirstLetter(const gd::String &string) {
return string.size() < 1 ? string
: string.substr(0, 1).UpperCase() + string.substr(1);
}

void MetadataDeclarationHelper::DeclarePropertyInstructionAndExpression(
gd::PlatformExtension &extension,
gd::InstructionOrExpressionContainerMetadata &entityMetadata,
Expand All @@ -975,7 +969,7 @@ void MetadataDeclarationHelper::DeclarePropertyInstructionAndExpression(
auto &propertyType = property.GetType();

auto uncapitalizedLabel =
UncapitalizeFirstLetter(property.GetLabel() || property.GetName());
UncapitalizeFirstLetter(property.GetLabel()) || property.GetName();
if (propertyType == "Boolean") {
auto &conditionMetadata = entityMetadata.AddScopedCondition(
conditionName, propertyLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ class MetadataDeclarationHelper {
static gd::String
GetStringifiedExtraInfo(const gd::PropertyDescriptor &property);

static gd::String CapitalizeFirstLetter(const gd::String &string);
static gd::String UncapitalizeFirstLetter(const gd::String &string);

std::vector<gd::MultipleInstructionMetadata> expressionAndConditions;
Expand Down
12 changes: 6 additions & 6 deletions GDevelop.js/__tests__/MetadataDeclarationHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('MetadataDeclarationHelper', () => {
expect(condition.getFullName()).toBe('Some value');
expect(condition.getDescription()).toBe('Compare some value.');
// The IDE fixes the first letter case.
expect(condition.getSentence()).toBe('some value _PARAM1_ _PARAM2_');
expect(condition.getSentence()).toBe('Some value _PARAM1_ _PARAM2_');

extension.delete();
project.delete();
Expand Down Expand Up @@ -486,7 +486,7 @@ describe('MetadataDeclarationHelper', () => {
expect(condition.getDescription()).toBe('Compare some value.');
// The IDE fixes the first letter case.
expect(condition.getSentence()).toBe(
'some value of _PARAM0_ _PARAM2_ _PARAM3_'
'Some value of _PARAM0_ _PARAM2_ _PARAM3_'
);

expect(condition.getParametersCount()).toBe(5);
Expand Down Expand Up @@ -635,7 +635,7 @@ describe('MetadataDeclarationHelper', () => {
);
// The IDE fixes the first letter case.
expect(condition.getSentence()).toBe(
'the property value for the some value of _PARAM0_ _PARAM2_ _PARAM3_'
'The property value for the some value of _PARAM0_ _PARAM2_ _PARAM3_'
);
expect(condition.isHidden()).toBe(false);
expect(condition.isPrivate()).toBe(true);
Expand Down Expand Up @@ -819,7 +819,7 @@ describe('MetadataDeclarationHelper', () => {
);
// The IDE fixes the first letter case.
expect(condition.getSentence()).toBe(
'the property value for the some value of _PARAM0_ _PARAM2_ _PARAM3_'
'The property value for the some value of _PARAM0_ _PARAM2_ _PARAM3_'
);
expect(condition.isHidden()).toBe(false);
expect(condition.isPrivate()).toBe(true);
Expand Down Expand Up @@ -1233,7 +1233,7 @@ describe('MetadataDeclarationHelper', () => {
expect(condition.getDescription()).toBe('Compare some value.');
// The IDE fixes the first letter case.
expect(condition.getSentence()).toBe(
'some value of _PARAM0_ _PARAM1_ _PARAM2_'
'Some value of _PARAM0_ _PARAM1_ _PARAM2_'
);

expect(condition.getParametersCount()).toBe(4);
Expand Down Expand Up @@ -1369,7 +1369,7 @@ describe('MetadataDeclarationHelper', () => {
);
// The IDE fixes the first letter case.
expect(condition.getSentence()).toBe(
'the property value for the some value of _PARAM0_ _PARAM1_ _PARAM2_'
'The property value for the some value of _PARAM0_ _PARAM1_ _PARAM2_'
);
expect(condition.isHidden()).toBe(false);
expect(condition.isPrivate()).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion newIDE/app/src/EventsSheet/EventsTree/Instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const Instruction = (props: Props) => {
/>
);
}
return <span key={i}>{i === 0 ? capitalize(value) : value}</span>;
return <span key={i}>{value}</span>;
}

const parameterMetadata = metadata.getParameter(parameterIndex);
Expand Down

0 comments on commit 8c50764

Please sign in to comment.