Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Core/GDCore/Project/EventsFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ void EventsFunction::SerializeTo(SerializerElement& element) const {
if (isAsync) {
element.SetBoolAttribute("async", isAsync);
}
if (!helpUrl.empty()) {
element.SetAttribute("helpUrl", helpUrl);
}
events.SerializeTo(element.AddChild("events"));

gd::String functionTypeStr = "Action";
Expand Down Expand Up @@ -116,6 +119,7 @@ void EventsFunction::UnserializeFrom(gd::Project& project,
getterName = element.GetStringAttribute("getterName");
isPrivate = element.GetBoolAttribute("private");
isAsync = element.GetBoolAttribute("async");
helpUrl = element.GetStringAttribute("helpUrl");
events.UnserializeFrom(project, element.GetChild("events"));

gd::String functionTypeStr = element.GetStringAttribute("functionType");
Expand Down
14 changes: 14 additions & 0 deletions Core/GDCore/Project/EventsFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ class GD_CORE_API EventsFunction {
return *this;
}

/**
* \brief Get the help URL for this function.
*/
const gd::String& GetHelpUrl() const { return helpUrl; }

/**
* \brief Set the help URL for this function.
*/
EventsFunction& SetHelpUrl(const gd::String& helpUrl_) {
helpUrl = helpUrl_;
return *this;
}

/**
* \brief Return the events.
*/
Expand Down Expand Up @@ -304,6 +317,7 @@ class GD_CORE_API EventsFunction {
gd::ObjectGroupsContainer objectGroups;
bool isPrivate = false;
bool isAsync = false;
gd::String helpUrl;
};

} // namespace gd
88 changes: 88 additions & 0 deletions Core/tests/EventsFunction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival ([email protected]). All rights
* reserved. This project is released under the MIT License.
*/
/**
* @file Tests covering EventsFunction
*/
#include "GDCore/Project/EventsFunction.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "catch.hpp"

TEST_CASE("EventsFunction", "[common]") {
SECTION("Basic properties") {
gd::EventsFunction eventsFunction;

eventsFunction.SetName("MyFunction");
eventsFunction.SetFullName("My Function");
eventsFunction.SetDescription("A test function");
eventsFunction.SetGroup("Test Group");
eventsFunction.SetSentence("Do something with _PARAM1_");

REQUIRE(eventsFunction.GetName() == "MyFunction");
REQUIRE(eventsFunction.GetFullName() == "My Function");
REQUIRE(eventsFunction.GetDescription() == "A test function");
REQUIRE(eventsFunction.GetGroup() == "Test Group");
REQUIRE(eventsFunction.GetSentence() == "Do something with _PARAM1_");
}

SECTION("Help URL") {
gd::EventsFunction eventsFunction;

// Default should be empty
REQUIRE(eventsFunction.GetHelpUrl() == "");

// Can set a help URL
eventsFunction.SetHelpUrl("https://example.com/help");
REQUIRE(eventsFunction.GetHelpUrl() == "https://example.com/help");

// Can clear the help URL
eventsFunction.SetHelpUrl("");
REQUIRE(eventsFunction.GetHelpUrl() == "");
}

SECTION("Serialization with help URL") {
gd::Project project;

gd::EventsFunction eventsFunction;
eventsFunction.SetName("MyFunction");
eventsFunction.SetFullName("My Function");
eventsFunction.SetDescription("A test function");
eventsFunction.SetHelpUrl("https://example.com/custom-help");

gd::SerializerElement element;
eventsFunction.SerializeTo(element);

gd::EventsFunction eventsFunction2;
eventsFunction2.UnserializeFrom(project, element);

REQUIRE(eventsFunction2.GetName() == "MyFunction");
REQUIRE(eventsFunction2.GetFullName() == "My Function");
REQUIRE(eventsFunction2.GetDescription() == "A test function");
REQUIRE(eventsFunction2.GetHelpUrl() == "https://example.com/custom-help");
}

SECTION("Serialization without help URL") {
gd::Project project;

gd::EventsFunction eventsFunction;
eventsFunction.SetName("MyFunction");
eventsFunction.SetFullName("My Function");
eventsFunction.SetDescription("A test function");
// No help URL set

gd::SerializerElement element;
eventsFunction.SerializeTo(element);

gd::EventsFunction eventsFunction2;
eventsFunction2.UnserializeFrom(project, element);

REQUIRE(eventsFunction2.GetName() == "MyFunction");
REQUIRE(eventsFunction2.GetFullName() == "My Function");
REQUIRE(eventsFunction2.GetDescription() == "A test function");
REQUIRE(eventsFunction2.GetHelpUrl() == "");
}
}

54 changes: 54 additions & 0 deletions GDJS/GDJS/Events/CodeGeneration/MetadataDeclarationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ MetadataDeclarationHelper::DeclareExpressionMetadata(
expressionAndCondition.AddCodeOnlyParameter("currentScene", "");
DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction,
expressionAndCondition, 0);
if (!eventsFunction.GetHelpUrl().empty()) {
expressionAndCondition.SetHelpPath(eventsFunction.GetHelpUrl());
}
expressionAndConditions.push_back(expressionAndCondition);
return expressionAndConditions.back();
} else {
Expand All @@ -555,6 +558,9 @@ MetadataDeclarationHelper::DeclareExpressionMetadata(
expression.AddCodeOnlyParameter("currentScene", "");
DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction,
expression, 0);
if (!eventsFunction.GetHelpUrl().empty()) {
expression.SetHelpPath(eventsFunction.GetHelpUrl());
}
return expression;
}
}
Expand All @@ -580,6 +586,9 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata(
condition.AddCodeOnlyParameter("currentScene", "");
DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction,
condition, 0);
if (!eventsFunction.GetHelpUrl().empty()) {
condition.SetHelpPath(eventsFunction.GetHelpUrl());
}
return condition;
} else if (functionType == gd::EventsFunction::ActionWithOperator) {
if (freeEventsFunctions.HasEventsFunctionNamed(
Expand All @@ -606,6 +615,9 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata(
action.AddCodeOnlyParameter("currentScene", "");
DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction,
action, 0);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
} else {

Expand All @@ -620,6 +632,9 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata(
action.AddCodeOnlyParameter("currentScene", "");
DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction,
action, 0);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
}
} else {
Expand All @@ -633,6 +648,9 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata(
action.AddCodeOnlyParameter("currentScene", "");
DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction,
action, 0);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
}
}
Expand Down Expand Up @@ -725,6 +743,9 @@ MetadataDeclarationHelper::DeclareBehaviorExpressionMetadata(
GetExtensionIconUrl(extension));
DeclareEventsFunctionParameters(eventsBasedBehavior.GetEventsFunctions(),
eventsFunction, expressionAndCondition, 2);
if (!eventsFunction.GetHelpUrl().empty()) {
expressionAndCondition.SetHelpPath(eventsFunction.GetHelpUrl());
}
expressionAndConditions.push_back(expressionAndCondition);
return expressionAndConditions.back();
} else {
Expand All @@ -750,6 +771,9 @@ MetadataDeclarationHelper::DeclareBehaviorExpressionMetadata(
GetExtensionIconUrl(extension));
DeclareEventsFunctionParameters(eventsBasedBehavior.GetEventsFunctions(),
eventsFunction, expression, 2);
if (!eventsFunction.GetHelpUrl().empty()) {
expression.SetHelpPath(eventsFunction.GetHelpUrl());
}
return expression;
}
}
Expand Down Expand Up @@ -778,6 +802,9 @@ MetadataDeclarationHelper::DeclareBehaviorInstructionMetadata(
GetExtensionIconUrl(extension), GetExtensionIconUrl(extension));
DeclareEventsFunctionParameters(eventsBasedBehavior.GetEventsFunctions(),
eventsFunction, condition, 2);
if (!eventsFunction.GetHelpUrl().empty()) {
condition.SetHelpPath(eventsFunction.GetHelpUrl());
}
return condition;
} else if (functionType == gd::EventsFunction::ActionWithOperator) {
auto &eventsFunctionsContainer = eventsBasedBehavior.GetEventsFunctions();
Expand All @@ -803,6 +830,9 @@ MetadataDeclarationHelper::DeclareBehaviorInstructionMetadata(

DeclareEventsFunctionParameters(eventsBasedBehavior.GetEventsFunctions(),
eventsFunction, action, 2);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
} else {
auto &action = behaviorMetadata.AddScopedAction(
Expand All @@ -816,6 +846,9 @@ MetadataDeclarationHelper::DeclareBehaviorInstructionMetadata(

DeclareEventsFunctionParameters(eventsBasedBehavior.GetEventsFunctions(),
eventsFunction, action, 2);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
}
} else {
Expand All @@ -833,6 +866,9 @@ MetadataDeclarationHelper::DeclareBehaviorInstructionMetadata(

DeclareEventsFunctionParameters(eventsBasedBehavior.GetEventsFunctions(),
eventsFunction, action, 2);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
}
}
Expand Down Expand Up @@ -899,6 +935,9 @@ MetadataDeclarationHelper::DeclareObjectExpressionMetadata(

DeclareEventsFunctionParameters(eventsBasedObject.GetEventsFunctions(),
eventsFunction, expressionAndCondition, 1);
if (!eventsFunction.GetHelpUrl().empty()) {
expressionAndCondition.SetHelpPath(eventsFunction.GetHelpUrl());
}
expressionAndConditions.push_back(expressionAndCondition);
return expressionAndConditions.back();
} else {
Expand All @@ -925,6 +964,9 @@ MetadataDeclarationHelper::DeclareObjectExpressionMetadata(

DeclareEventsFunctionParameters(eventsBasedObject.GetEventsFunctions(),
eventsFunction, expression, 1);
if (!eventsFunction.GetHelpUrl().empty()) {
expression.SetHelpPath(eventsFunction.GetHelpUrl());
}
return expression;
}
}
Expand Down Expand Up @@ -954,6 +996,9 @@ MetadataDeclarationHelper::DeclareObjectInstructionMetadata(

DeclareEventsFunctionParameters(eventsBasedObject.GetEventsFunctions(),
eventsFunction, condition, 1);
if (!eventsFunction.GetHelpUrl().empty()) {
condition.SetHelpPath(eventsFunction.GetHelpUrl());
}
return condition;
} else if (functionType == gd::EventsFunction::ActionWithOperator) {
auto &eventsFunctionsContainer = eventsBasedObject.GetEventsFunctions();
Expand All @@ -978,6 +1023,9 @@ MetadataDeclarationHelper::DeclareObjectInstructionMetadata(

DeclareEventsFunctionParameters(eventsBasedObject.GetEventsFunctions(),
eventsFunction, action, 1);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
} else {
auto &action = objectMetadata.AddScopedAction(
Expand All @@ -990,6 +1038,9 @@ MetadataDeclarationHelper::DeclareObjectInstructionMetadata(

DeclareEventsFunctionParameters(eventsBasedObject.GetEventsFunctions(),
eventsFunction, action, 1);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
}
} else {
Expand All @@ -1007,6 +1058,9 @@ MetadataDeclarationHelper::DeclareObjectInstructionMetadata(

DeclareEventsFunctionParameters(eventsBasedObject.GetEventsFunctions(),
eventsFunction, action, 1);
if (!eventsFunction.GetHelpUrl().empty()) {
action.SetHelpPath(eventsFunction.GetHelpUrl());
}
return action;
}
}
Expand Down
2 changes: 2 additions & 0 deletions GDevelop.js/Bindings/Bindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3165,6 +3165,8 @@ interface EventsFunction {
boolean IsPrivate();
[Ref] EventsFunction SetAsync(boolean isAsync);
boolean IsAsync();
[Ref] EventsFunction SetHelpUrl([Const] DOMString helpUrl);
[Const, Ref] DOMString GetHelpUrl();
boolean IsAction();
boolean IsExpression();
boolean IsCondition();
Expand Down
9 changes: 9 additions & 0 deletions GDevelop.js/__tests__/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4579,6 +4579,15 @@ describe('libGD.js', function () {
expect(eventsFunction.getDescription()).toBe('My description');
eventsFunction.delete();
});
it('can have a help URL', function () {
const eventsFunction = new gd.EventsFunction();
expect(eventsFunction.getHelpUrl()).toBe('');
eventsFunction.setHelpUrl('https://example.com/help');
expect(eventsFunction.getHelpUrl()).toBe('https://example.com/help');
eventsFunction.setHelpUrl('');
expect(eventsFunction.getHelpUrl()).toBe('');
eventsFunction.delete();
});
});

describe('gd.EventsFunctionsExtension', () => {
Expand Down
Loading