From e6e4d9048f5bb19ed30233fc7abc0f70c1d62736 Mon Sep 17 00:00:00 2001
From: AlexandreS <32449369+AlexandreSi@users.noreply.github.com>
Date: Mon, 2 Sep 2024 16:25:41 +0200
Subject: [PATCH] Add action to set Text object font (#6911)
---
.vscode/GDevelopExtensions.code-snippets | 2 +-
Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp | 8 ++++----
Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.h | 4 ++--
Core/GDCore/IDE/Project/ArbitraryResourceWorker.cpp | 4 +---
Extensions/TextObject/Extension.cpp | 2 +-
Extensions/TextObject/JsExtension.cpp | 5 +++--
newIDE/app/src/EventsSheet/ParameterRenderingService.js | 1 -
7 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/.vscode/GDevelopExtensions.code-snippets b/.vscode/GDevelopExtensions.code-snippets
index 3f153bd39..db5ce5c38 100644
--- a/.vscode/GDevelopExtensions.code-snippets
+++ b/.vscode/GDevelopExtensions.code-snippets
@@ -107,7 +107,7 @@
"description": "Define a parameter in a GDevelop extension definition.",
"prefix": "gdparam",
"body": [
- ".addParameter('${1|string,expression,object,behavior,yesorno,stringWithSelector,scenevar,globalvar,objectvar,objectList,objectListWithoutPicking,color,key,sceneName,file,layer,relationalOperator,operator,trueorfalse,musicfile,soundfile,police,mouse,passwordjoyaxis,camera,objectPtr,forceMultiplier|}', '${2:Parameter description}', '${3:Optional parameter data}', /*parameterIsOptional=*/${4|false,true|})"
+ ".addParameter('${1|string,expression,object,behavior,yesorno,stringWithSelector,scenevar,globalvar,objectvar,objectList,objectListWithoutPicking,color,key,sceneName,file,layer,relationalOperator,operator,trueorfalse,musicfile,soundfile,mouse,passwordjoyaxis,camera,objectPtr,forceMultiplier|}', '${2:Parameter description}', '${3:Optional parameter data}', /*parameterIsOptional=*/${4|false,true|})"
]
},
"Add code only parameter": {
diff --git a/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp b/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp
index 185f87bec..cb2aaa73b 100644
--- a/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp
+++ b/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp
@@ -77,11 +77,11 @@ gd::String EventsCodeGenerator::GenerateRelationalOperatorCall(
/**
* @brief Generate a relational operation
- *
+ *
* @param relationalOperator the operator
* @param lhs the left hand operand
* @param rhs the right hand operand
- * @return gd::String
+ * @return gd::String
*/
gd::String EventsCodeGenerator::GenerateRelationalOperation(
const gd::String& relationalOperator,
@@ -828,7 +828,7 @@ gd::String EventsCodeGenerator::GenerateParameterCodes(
metadata.GetType() == "spineResource" ||
// Deprecated, old parameter names:
metadata.GetType() == "password" || metadata.GetType() == "musicfile" ||
- metadata.GetType() == "soundfile" || metadata.GetType() == "police") {
+ metadata.GetType() == "soundfile") {
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
} else if (metadata.GetType() == "mouse") {
argOutput = "\"" + ConvertToString(parameter.GetPlainString()) + "\"";
@@ -1007,7 +1007,7 @@ gd::String EventsCodeGenerator::GenerateEventsListCode(
output += "\n" + scopeBegin + "\n" + declarationsCode + "\n" +
eventCoreCode + "\n" + scopeEnd + "\n";
-
+
if (event.HasVariables()) {
GetProjectScopedContainers().GetVariablesContainersList().Pop();
}
diff --git a/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.h b/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.h
index 9351cd00c..bc942c59a 100644
--- a/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.h
+++ b/Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.h
@@ -528,7 +528,7 @@ protected:
parameter -> string
* - operator : Used to update a value using a setter and a getter -> string
* - key, mouse, objectvar, scenevar, globalvar, password, musicfile,
- soundfile, police -> string
+ soundfile -> string
* - trueorfalse, yesorno -> boolean ( See GenerateTrue/GenerateFalse ).
*
*
@@ -849,7 +849,7 @@ protected:
instructionUniqueIds; ///< The unique ids generated for instructions.
size_t eventsListNextUniqueId; ///< The next identifier to use for an events
///< list function name.
-
+
gd::DiagnosticReport* diagnosticReport;
};
diff --git a/Core/GDCore/IDE/Project/ArbitraryResourceWorker.cpp b/Core/GDCore/IDE/Project/ArbitraryResourceWorker.cpp
index 03c5efb5d..198ee881d 100644
--- a/Core/GDCore/IDE/Project/ArbitraryResourceWorker.cpp
+++ b/Core/GDCore/IDE/Project/ArbitraryResourceWorker.cpp
@@ -225,9 +225,7 @@ bool ResourceWorkerInEventsWorker::DoVisitInstruction(gd::Instruction& instructi
size_t parameterIndex,
const gd::String& lastObjectName) {
const String& parameterValue = parameterExpression.GetPlainString();
- if (parameterMetadata.GetType() ==
- "police" || // Should be renamed fontResource
- parameterMetadata.GetType() == "fontResource") {
+ if (parameterMetadata.GetType() == "fontResource") {
gd::String updatedParameterValue = parameterValue;
worker.ExposeFont(updatedParameterValue);
instruction.SetParameter(parameterIndex, updatedParameterValue);
diff --git a/Extensions/TextObject/Extension.cpp b/Extensions/TextObject/Extension.cpp
index 1dd0143cb..bd668dbd5 100644
--- a/Extensions/TextObject/Extension.cpp
+++ b/Extensions/TextObject/Extension.cpp
@@ -49,7 +49,7 @@ void DeclareTextObjectExtension(gd::PlatformExtension& extension) {
"res/actions/font.png")
.AddParameter("object", _("Object"), "Text")
- .AddParameter("police", _("Font"))
+ .AddParameter("fontResource", _("Font resource name"))
.SetFunctionName("ChangeFont");
obj.AddAction(
diff --git a/Extensions/TextObject/JsExtension.cpp b/Extensions/TextObject/JsExtension.cpp
index 50fb98d72..7901ae5be 100644
--- a/Extensions/TextObject/JsExtension.cpp
+++ b/Extensions/TextObject/JsExtension.cpp
@@ -38,6 +38,9 @@ class TextObjectJsExtension : public gd::PlatformExtension {
GetAllExpressionsForObject("TextObject::Text")["FontSize"]
.SetFunctionName("getCharacterSize");
+ GetAllActionsForObject("TextObject::Text")["TextObject::Font"]
+ .SetFunctionName("setFontName");
+
GetAllActionsForObject("TextObject::Text")["TextObject::SetBold"]
.SetFunctionName("setBold");
GetAllConditionsForObject("TextObject::Text")["TextObject::IsBold"]
@@ -188,8 +191,6 @@ class TextObjectJsExtension : public gd::PlatformExtension {
.SetFunctionName("setShadow");
// Unimplemented actions and conditions:
- GetAllActionsForObject("TextObject::Text")["TextObject::Font"]
- .SetFunctionName("");
GetAllActionsForObject("TextObject::Text")["TextObject::SetUnderlined"]
.SetFunctionName("");
GetAllConditionsForObject("TextObject::Text")["TextObject::IsUnderlined"]
diff --git a/newIDE/app/src/EventsSheet/ParameterRenderingService.js b/newIDE/app/src/EventsSheet/ParameterRenderingService.js
index 66c8d92df..ad70e1de3 100644
--- a/newIDE/app/src/EventsSheet/ParameterRenderingService.js
+++ b/newIDE/app/src/EventsSheet/ParameterRenderingService.js
@@ -103,7 +103,6 @@ const components = {
atlasResource: AtlasResourceField,
spineResource: SpineResourceField,
color: ColorExpressionField,
- police: DefaultField, //TODO
forceMultiplier: ForceMultiplierField,
sceneName: SceneNameField,
layerEffectName: LayerEffectNameField,