From 60e36f37b1495505d0cef0cac2b8b52deb822dc6 Mon Sep 17 00:00:00 2001 From: D8H Date: Mon, 20 Jan 2025 11:29:55 +0100 Subject: [PATCH] Remove EventsFunctionsExtension inheritance to EventsFunctionsContainer (#7326) - developer changelog only --- Core/GDCore/IDE/ProjectBrowserHelper.cpp | 8 +- Core/GDCore/IDE/ProjectStripper.cpp | 2 +- Core/GDCore/IDE/WholeProjectRefactorer.cpp | 18 +++-- .../GDCore/Project/EventsFunctionsContainer.h | 11 +++ .../Project/EventsFunctionsExtension.cpp | 13 ++-- .../GDCore/Project/EventsFunctionsExtension.h | 18 ++++- .../Project/ProjectScopedContainers.cpp | 6 +- .../Project/VariablesContainersList.cpp | 2 +- Core/tests/ArbitraryResourceWorker.cpp | 10 ++- Core/tests/EventsFunctionsExtension.cpp | 36 ++++----- ...-ApplyRefactoringForVariablesContainer.cpp | 3 +- Core/tests/WholeProjectRefactorer.cpp | 75 ++++++++++++------- .../CodeGeneration/EventsCodeGenerator.cpp | 17 ++--- .../MetadataDeclarationHelper.cpp | 20 ++--- GDevelop.js/Bindings/Bindings.idl | 12 +-- .../TestUtils/CodeGenerationHelpers.js | 5 +- GDevelop.js/__tests__/Core.js | 13 ++-- ...eFunctionCodeGenerationIntegrationTests.js | 9 ++- .../__tests__/MetadataDeclarationHelper.js | 34 ++++++--- GDevelop.js/types.d.ts | 10 +-- .../types/gdeventsfunctionsextension.js | 10 +-- .../scripts/extract-extensions-document.js | 5 +- .../EventsFunctionsExtensionEditor/index.js | 5 +- .../EventsFunctionsExtensionsLoader/index.js | 42 ++++++----- newIDE/app/src/EventsFunctionsList/index.js | 14 ++-- .../EventsFunctionExtractorDialog.js | 5 +- newIDE/app/src/fixtures/TestProject.js | 12 +-- 27 files changed, 240 insertions(+), 175 deletions(-) diff --git a/Core/GDCore/IDE/ProjectBrowserHelper.cpp b/Core/GDCore/IDE/ProjectBrowserHelper.cpp index b4e45b36e9c0..d40545dd0522 100644 --- a/Core/GDCore/IDE/ProjectBrowserHelper.cpp +++ b/Core/GDCore/IDE/ProjectBrowserHelper.cpp @@ -147,7 +147,8 @@ void ProjectBrowserHelper::ExposeEventsFunctionsExtensionEvents( gd::Project &project, const gd::EventsFunctionsExtension &eventsFunctionsExtension, gd::ArbitraryEventsWorker &worker) { // Add (free) events functions - for (auto &&eventsFunction : eventsFunctionsExtension.GetInternalVector()) { + for (auto &&eventsFunction : + eventsFunctionsExtension.GetEventsFunctions().GetInternalVector()) { worker.Launch(eventsFunction->GetEvents()); } @@ -169,7 +170,8 @@ void ProjectBrowserHelper::ExposeEventsFunctionsExtensionEvents( gd::Project &project, const gd::EventsFunctionsExtension &eventsFunctionsExtension, gd::ArbitraryEventsWorkerWithContext &worker) { // Add (free) events functions - for (auto &&eventsFunction : eventsFunctionsExtension.GetInternalVector()) { + for (auto &&eventsFunction : + eventsFunctionsExtension.GetEventsFunctions().GetInternalVector()) { gd::ObjectsContainer parameterObjectsContainer( gd::ObjectsContainer::SourceType::Function); gd::VariablesContainer parameterVariablesContainer( @@ -324,7 +326,7 @@ void ProjectBrowserHelper::ExposeProjectFunctions( for (std::size_t e = 0; e < project.GetEventsFunctionsExtensionsCount(); e++) { auto &eventsFunctionsExtension = project.GetEventsFunctionsExtension(e); - worker.Launch(eventsFunctionsExtension); + worker.Launch(eventsFunctionsExtension.GetEventsFunctions()); for (auto &&eventsBasedBehavior : eventsFunctionsExtension.GetEventsBasedBehaviors() diff --git a/Core/GDCore/IDE/ProjectStripper.cpp b/Core/GDCore/IDE/ProjectStripper.cpp index 1421ff966cdc..82d094da357a 100644 --- a/Core/GDCore/IDE/ProjectStripper.cpp +++ b/Core/GDCore/IDE/ProjectStripper.cpp @@ -63,7 +63,7 @@ void GD_CORE_API ProjectStripper::StripProjectForExport(gd::Project &project) { eventsBasedObject.GetPropertyDescriptors().GetInternalVector().clear(); } extension.GetEventsBasedBehaviors().Clear(); - extension.ClearEventsFunctions(); + extension.GetEventsFunctions().ClearEventsFunctions(); } } diff --git a/Core/GDCore/IDE/WholeProjectRefactorer.cpp b/Core/GDCore/IDE/WholeProjectRefactorer.cpp index 67e7317522ef..edf91d162555 100644 --- a/Core/GDCore/IDE/WholeProjectRefactorer.cpp +++ b/Core/GDCore/IDE/WholeProjectRefactorer.cpp @@ -600,7 +600,8 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( // instructions after they are renamed. // Free expressions - for (auto &&eventsFunction : eventsFunctionsExtension.GetInternalVector()) { + for (auto &&eventsFunction : + eventsFunctionsExtension.GetEventsFunctions().GetInternalVector()) { if (eventsFunction->IsExpression()) { renameEventsFunction(*eventsFunction); } @@ -617,7 +618,8 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( } // Free instructions - for (auto &&eventsFunction : eventsFunctionsExtension.GetInternalVector()) { + for (auto &&eventsFunction : + eventsFunctionsExtension.GetEventsFunctions().GetInternalVector()) { if (eventsFunction->IsAction() || eventsFunction->IsCondition()) { renameEventsFunction(*eventsFunction); } @@ -697,11 +699,12 @@ void WholeProjectRefactorer::RenameEventsFunction( gd::Project &project, const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::String &oldFunctionName, const gd::String &newFunctionName) { - if (!eventsFunctionsExtension.HasEventsFunctionNamed(oldFunctionName)) + const auto &eventsFunctions = eventsFunctionsExtension.GetEventsFunctions(); + if (!eventsFunctions.HasEventsFunctionNamed(oldFunctionName)) return; const gd::EventsFunction &eventsFunction = - eventsFunctionsExtension.GetEventsFunction(oldFunctionName); + eventsFunctions.GetEventsFunction(oldFunctionName); const WholeProjectBrowser wholeProjectExposer; DoRenameEventsFunction( @@ -714,7 +717,7 @@ void WholeProjectRefactorer::RenameEventsFunction( if (eventsFunction.GetFunctionType() == gd::EventsFunction::ExpressionAndCondition) { - for (auto &&otherFunction : eventsFunctionsExtension.GetInternalVector()) { + for (auto &&otherFunction : eventsFunctions.GetInternalVector()) { if (otherFunction->GetFunctionType() == gd::EventsFunction::ActionWithOperator && otherFunction->GetGetterName() == oldFunctionName) { @@ -884,11 +887,12 @@ void WholeProjectRefactorer::MoveEventsFunctionParameter( const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::String &functionName, std::size_t oldIndex, std::size_t newIndex) { - if (!eventsFunctionsExtension.HasEventsFunctionNamed(functionName)) + const auto &eventsFunctions = eventsFunctionsExtension.GetEventsFunctions(); + if (!eventsFunctions.HasEventsFunctionNamed(functionName)) return; const gd::EventsFunction &eventsFunction = - eventsFunctionsExtension.GetEventsFunction(functionName); + eventsFunctions.GetEventsFunction(functionName); const gd::String &eventsFunctionType = gd::PlatformExtension::GetEventsFunctionFullType( diff --git a/Core/GDCore/Project/EventsFunctionsContainer.h b/Core/GDCore/Project/EventsFunctionsContainer.h index 38430b54ce44..05a9791b5363 100644 --- a/Core/GDCore/Project/EventsFunctionsContainer.h +++ b/Core/GDCore/Project/EventsFunctionsContainer.h @@ -33,6 +33,17 @@ class GD_CORE_API EventsFunctionsContainer EventsFunctionsContainer(FunctionOwner source_) : owner(source_) {} + EventsFunctionsContainer(const EventsFunctionsContainer &other) { + Init(other); + } + + EventsFunctionsContainer &operator=(const EventsFunctionsContainer &other) { + if (this != &other) + Init(other); + + return *this; + } + /** * \brief Get the source of the function container. * diff --git a/Core/GDCore/Project/EventsFunctionsExtension.cpp b/Core/GDCore/Project/EventsFunctionsExtension.cpp index f25a2005446a..7436819fe6ac 100644 --- a/Core/GDCore/Project/EventsFunctionsExtension.cpp +++ b/Core/GDCore/Project/EventsFunctionsExtension.cpp @@ -15,14 +15,13 @@ namespace gd { EventsFunctionsExtension::EventsFunctionsExtension() : - gd::EventsFunctionsContainer( - gd::EventsFunctionsContainer::FunctionOwner::Extension), + eventsFunctionsContainer(gd::EventsFunctionsContainer::FunctionOwner::Extension), globalVariables(gd::VariablesContainer::SourceType::ExtensionGlobal), sceneVariables(gd::VariablesContainer::SourceType::ExtensionScene) {} EventsFunctionsExtension::EventsFunctionsExtension( const EventsFunctionsExtension& other) : - gd::EventsFunctionsContainer( + eventsFunctionsContainer( gd::EventsFunctionsContainer::FunctionOwner::Extension) { Init(other); } @@ -48,7 +47,7 @@ void EventsFunctionsExtension::Init(const gd::EventsFunctionsExtension& other) { previewIconUrl = other.previewIconUrl; iconUrl = other.iconUrl; helpPath = other.helpPath; - EventsFunctionsContainer::Init(other); + eventsFunctionsContainer = other.eventsFunctionsContainer; eventsBasedBehaviors = other.eventsBasedBehaviors; eventsBasedObjects = other.eventsBasedObjects; globalVariables = other.GetGlobalVariables(); @@ -97,7 +96,8 @@ void EventsFunctionsExtension::SerializeTo(SerializerElement& element) const { GetGlobalVariables().SerializeTo(element.AddChild("globalVariables")); GetSceneVariables().SerializeTo(element.AddChild("sceneVariables")); - SerializeEventsFunctionsTo(element.AddChild("eventsFunctions")); + eventsFunctionsContainer.SerializeEventsFunctionsTo( + element.AddChild("eventsFunctions")); eventsBasedBehaviors.SerializeElementsTo( "eventsBasedBehavior", element.AddChild("eventsBasedBehaviors")); eventsBasedObjects.SerializeElementsTo( @@ -205,7 +205,8 @@ void EventsFunctionsExtension::UnserializeExtensionDeclarationFrom( void EventsFunctionsExtension::UnserializeExtensionImplementationFrom( gd::Project& project, const SerializerElement& element) { - UnserializeEventsFunctionsFrom(project, element.GetChild("eventsFunctions")); + eventsFunctionsContainer.UnserializeEventsFunctionsFrom( + project, element.GetChild("eventsFunctions")); eventsBasedBehaviors.UnserializeElementsFrom( "eventsBasedBehavior", project, element.GetChild("eventsBasedBehaviors")); diff --git a/Core/GDCore/Project/EventsFunctionsExtension.h b/Core/GDCore/Project/EventsFunctionsExtension.h index f61a48010d02..6d9a4599a446 100644 --- a/Core/GDCore/Project/EventsFunctionsExtension.h +++ b/Core/GDCore/Project/EventsFunctionsExtension.h @@ -36,7 +36,7 @@ namespace gd { * * \ingroup PlatformDefinition */ -class GD_CORE_API EventsFunctionsExtension : public EventsFunctionsContainer { +class GD_CORE_API EventsFunctionsExtension { public: EventsFunctionsExtension(); EventsFunctionsExtension(const EventsFunctionsExtension&); @@ -181,6 +181,21 @@ class GD_CORE_API EventsFunctionsExtension : public EventsFunctionsContainer { return originIdentifier; } + /** + * \brief Return a reference to the functions of the events based behavior or object. + */ + EventsFunctionsContainer& GetEventsFunctions() { + return eventsFunctionsContainer; + } + + /** + * \brief Return a const reference to the functions of the events based + * behavior or object. + */ + const EventsFunctionsContainer& GetEventsFunctions() const { + return eventsFunctionsContainer; + } + /** \name Dependencies */ ///@{ @@ -375,6 +390,7 @@ class GD_CORE_API EventsFunctionsExtension : public EventsFunctionsContainer { std::vector dependencies; std::vector sourceFiles; + gd::EventsFunctionsContainer eventsFunctionsContainer; gd::VariablesContainer globalVariables; gd::VariablesContainer sceneVariables; }; diff --git a/Core/GDCore/Project/ProjectScopedContainers.cpp b/Core/GDCore/Project/ProjectScopedContainers.cpp index 75d293bff6b3..7af198b64358 100644 --- a/Core/GDCore/Project/ProjectScopedContainers.cpp +++ b/Core/GDCore/Project/ProjectScopedContainers.cpp @@ -77,7 +77,7 @@ ProjectScopedContainers::MakeNewProjectScopedContainersForFreeEventsFunction( gd::VariablesContainer ¶meterVariablesContainer) { gd::EventsFunctionTools::FreeEventsFunctionToObjectsContainer( - project, eventsFunctionsExtension, eventsFunction, + project, eventsFunctionsExtension.GetEventsFunctions(), eventsFunction, parameterObjectsContainer); ProjectScopedContainers projectScopedContainers( @@ -91,8 +91,8 @@ ProjectScopedContainers::MakeNewProjectScopedContainersForFreeEventsFunction( &eventsFunctionsExtension.GetSceneVariables(), PropertiesContainersList::MakeNewEmptyPropertiesContainersList()); - projectScopedContainers.AddParameters( - eventsFunction.GetParametersForEvents(eventsFunctionsExtension)); + projectScopedContainers.AddParameters(eventsFunction.GetParametersForEvents( + eventsFunctionsExtension.GetEventsFunctions())); return projectScopedContainers; }; diff --git a/Core/GDCore/Project/VariablesContainersList.cpp b/Core/GDCore/Project/VariablesContainersList.cpp index a810ca5c164b..683663ae7405 100644 --- a/Core/GDCore/Project/VariablesContainersList.cpp +++ b/Core/GDCore/Project/VariablesContainersList.cpp @@ -52,7 +52,7 @@ VariablesContainersList::MakeNewVariablesContainersListForFreeEventsFunction( variablesContainersList.Push(extension.GetSceneVariables()); gd::EventsFunctionTools::ParametersToVariablesContainer( - eventsFunction.GetParametersForEvents(extension), + eventsFunction.GetParametersForEvents(extension.GetEventsFunctions()), parameterVariablesContainer); variablesContainersList.Push(parameterVariablesContainer); diff --git a/Core/tests/ArbitraryResourceWorker.cpp b/Core/tests/ArbitraryResourceWorker.cpp index cf56423f5c01..91923557aeda 100644 --- a/Core/tests/ArbitraryResourceWorker.cpp +++ b/Core/tests/ArbitraryResourceWorker.cpp @@ -268,8 +268,9 @@ TEST_CASE("ArbitraryResourceWorker", "[common][resources]") { ArbitraryResourceWorkerTest worker(project.GetResourcesManager()); auto& extension = project.InsertNewEventsFunctionsExtension("MyEventExtension", 0); - auto& function = extension.InsertNewEventsFunction("MyFreeFunction", 0); - + auto &function = extension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeFunction", 0); + gd::StandardEvent standardEvent; gd::Instruction instruction; instruction.SetType("MyExtension::DoSomethingWithResources"); @@ -777,8 +778,9 @@ TEST_CASE("ArbitraryResourceWorker", "[common][resources]") { ArbitraryResourceWorkerTest worker(project.GetResourcesManager()); auto& extension = project.InsertNewEventsFunctionsExtension("MyEventExtension", 0); - auto& function = extension.InsertNewEventsFunction("MyFreeFunction", 0); - + auto &function = extension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeFunction", 0); + gd::StandardEvent standardEvent; gd::Instruction instruction; instruction.SetType("MyExtension::DoSomethingWithResources"); diff --git a/Core/tests/EventsFunctionsExtension.cpp b/Core/tests/EventsFunctionsExtension.cpp index e14785e4d8b8..7d546230bbc1 100644 --- a/Core/tests/EventsFunctionsExtension.cpp +++ b/Core/tests/EventsFunctionsExtension.cpp @@ -11,9 +11,10 @@ TEST_CASE("EventsFunctionsExtension", "[common]") { SECTION("Sanity checks") { gd::EventsFunctionsExtension eventsFunctionExtension; - eventsFunctionExtension.InsertNewEventsFunction("Function1", 0); - eventsFunctionExtension.InsertNewEventsFunction("Function2", 1); - eventsFunctionExtension.InsertNewEventsFunction("Function3", 2); + auto &freeEventsFunctions = eventsFunctionExtension.GetEventsFunctions(); + freeEventsFunctions.InsertNewEventsFunction("Function1", 0); + freeEventsFunctions.InsertNewEventsFunction("Function2", 1); + freeEventsFunctions.InsertNewEventsFunction("Function3", 2); eventsFunctionExtension.GetEventsBasedBehaviors().InsertNew("MyBehavior", 0); eventsFunctionExtension.GetEventsBasedBehaviors().InsertNew("MyBehavior2", @@ -22,12 +23,13 @@ TEST_CASE("EventsFunctionsExtension", "[common]") { // Check that copy operator is working gd::EventsFunctionsExtension eventsFunctionExtension2 = eventsFunctionExtension; - REQUIRE(eventsFunctionExtension2.GetEventsFunctionsCount() == 3); - REQUIRE(eventsFunctionExtension2.GetEventsFunction(0).GetName() == + auto &freeEventsFunctions2 = eventsFunctionExtension2.GetEventsFunctions(); + REQUIRE(freeEventsFunctions2.GetEventsFunctionsCount() == 3); + REQUIRE(freeEventsFunctions2.GetEventsFunction(0).GetName() == "Function1"); - REQUIRE(eventsFunctionExtension2.GetEventsFunction(1).GetName() == + REQUIRE(freeEventsFunctions2.GetEventsFunction(1).GetName() == "Function2"); - REQUIRE(eventsFunctionExtension2.GetEventsFunction(2).GetName() == + REQUIRE(freeEventsFunctions2.GetEventsFunction(2).GetName() == "Function3"); REQUIRE(eventsFunctionExtension2.GetEventsBasedBehaviors().GetCount() == 2); REQUIRE( @@ -39,21 +41,21 @@ TEST_CASE("EventsFunctionsExtension", "[common]") { // Check that the copy has not somehow shared the same pointers // to the events functions. - eventsFunctionExtension.GetEventsFunction(1).SetName("Function2.x"); - eventsFunctionExtension2.GetEventsFunction(0).SetName("Function1.y"); - REQUIRE(eventsFunctionExtension.GetEventsFunctionsCount() == 3); - REQUIRE(eventsFunctionExtension.GetEventsFunction(0).GetName() == + freeEventsFunctions.GetEventsFunction(1).SetName("Function2.x"); + freeEventsFunctions2.GetEventsFunction(0).SetName("Function1.y"); + REQUIRE(freeEventsFunctions.GetEventsFunctionsCount() == 3); + REQUIRE(freeEventsFunctions.GetEventsFunction(0).GetName() == "Function1"); - REQUIRE(eventsFunctionExtension.GetEventsFunction(1).GetName() == + REQUIRE(freeEventsFunctions.GetEventsFunction(1).GetName() == "Function2.x"); - REQUIRE(eventsFunctionExtension.GetEventsFunction(2).GetName() == + REQUIRE(freeEventsFunctions.GetEventsFunction(2).GetName() == "Function3"); - REQUIRE(eventsFunctionExtension2.GetEventsFunctionsCount() == 3); - REQUIRE(eventsFunctionExtension2.GetEventsFunction(0).GetName() == + REQUIRE(freeEventsFunctions2.GetEventsFunctionsCount() == 3); + REQUIRE(freeEventsFunctions2.GetEventsFunction(0).GetName() == "Function1.y"); - REQUIRE(eventsFunctionExtension2.GetEventsFunction(1).GetName() == + REQUIRE(freeEventsFunctions2.GetEventsFunction(1).GetName() == "Function2"); - REQUIRE(eventsFunctionExtension2.GetEventsFunction(2).GetName() == + REQUIRE(freeEventsFunctions2.GetEventsFunction(2).GetName() == "Function3"); } } diff --git a/Core/tests/WholeProjectRefactorer-ApplyRefactoringForVariablesContainer.cpp b/Core/tests/WholeProjectRefactorer-ApplyRefactoringForVariablesContainer.cpp index c4c6284e0725..4d9e87e8dd86 100644 --- a/Core/tests/WholeProjectRefactorer-ApplyRefactoringForVariablesContainer.cpp +++ b/Core/tests/WholeProjectRefactorer-ApplyRefactoringForVariablesContainer.cpp @@ -1722,7 +1722,8 @@ TEST_CASE("WholeProjectRefactorer::ApplyRefactoringForVariablesContainer", auto &extension = project.InsertNewEventsFunctionsExtension("Extension", 0); extension.GetSceneVariables().InsertNew("MySceneVariable").SetValue(123); - auto &function = extension.InsertNewEventsFunction("MyFunction", 0); + auto &function = + extension.GetEventsFunctions().InsertNewEventsFunction("MyFunction", 0); gd::StandardEvent &event = dynamic_cast(function.GetEvents().InsertNewEvent( project, "BuiltinCommonInstructions::Standard")); diff --git a/Core/tests/WholeProjectRefactorer.cpp b/Core/tests/WholeProjectRefactorer.cpp index 87594a7dc959..5b6018774724 100644 --- a/Core/tests/WholeProjectRefactorer.cpp +++ b/Core/tests/WholeProjectRefactorer.cpp @@ -269,8 +269,9 @@ const std::vector GetEventsListsNotAssociatedToScene(gd: .GetEventsFunctions() .GetEventsFunction("MyBehaviorEventsFunction") .GetEvents(); - auto &freeFunctionEvents = - eventsExtension.GetEventsFunction("MyOtherEventsFunction").GetEvents(); + auto &freeFunctionEvents = eventsExtension.GetEventsFunctions() + .GetEventsFunction("MyOtherEventsFunction") + .GetEvents(); eventLists.push_back(&objectFunctionEvents); eventLists.push_back(&behaviorFunctionEvents); eventLists.push_back(&freeFunctionEvents); @@ -1197,8 +1198,9 @@ SetupProjectWithEventsFunctionExtension(gd::Project &project) { // Add (free) functions and a (free) expression { + auto &freeEventsFunctions = eventsExtension.GetEventsFunctions(); auto &action = - eventsExtension.InsertNewEventsFunction("MyEventsFunction", 0); + freeEventsFunctions.InsertNewEventsFunction("MyEventsFunction", 0); action.GetParameters() .InsertNewParameter("currentScene", 0) .SetType("") @@ -1213,21 +1215,21 @@ SetupProjectWithEventsFunctionExtension(gd::Project &project) { .SetExtraInfo("MyEventsExtension::MyEventsBasedBehavior"); auto &expression = - eventsExtension.InsertNewEventsFunction("MyEventsFunctionExpression", 1) + freeEventsFunctions.InsertNewEventsFunction("MyEventsFunctionExpression", 1) .SetFunctionType(gd::EventsFunction::Expression); expression.GetParameters() .InsertNewParameter("currentScene", 0) .SetType("") .SetCodeOnly(true); - auto &freeExpressionAndCondition = eventsExtension.InsertNewEventsFunction("MyEventsFunctionExpressionAndCondition", 2) + auto &freeExpressionAndCondition = freeEventsFunctions.InsertNewEventsFunction("MyEventsFunctionExpressionAndCondition", 2) .SetFunctionType(gd::EventsFunction::ExpressionAndCondition); freeExpressionAndCondition.GetParameters().InsertNewParameter("Value1", 0) .SetType("expression"); freeExpressionAndCondition.GetParameters().InsertNewParameter("Value2", 1) .SetType("expression"); - eventsExtension.InsertNewEventsFunction("MyEventsFunctionActionWithOperator", 2) + freeEventsFunctions.InsertNewEventsFunction("MyEventsFunctionActionWithOperator", 2) .SetFunctionType(gd::EventsFunction::ActionWithOperator) .SetGetterName("MyEventsFunctionExpressionAndCondition"); } @@ -1236,8 +1238,8 @@ SetupProjectWithEventsFunctionExtension(gd::Project &project) { // object and behavior. { // Add functions, and parameters that should be there by convention. - auto &action = - eventsExtension.InsertNewEventsFunction("MyOtherEventsFunction", 0); + auto &action = eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyOtherEventsFunction", 0); // Define the same objects as in the layout to be consistent with events. action.GetParameters() .InsertNewParameter("ObjectWithMyBehavior", 0) @@ -1299,7 +1301,8 @@ SetupProjectWithEventsFunctionExtension(gd::Project &project) { .GetEventsFunctions() .GetEventsFunction("MyBehaviorEventsFunction") .GetEvents()); - SetupEvents(eventsExtension.GetEventsFunction("MyOtherEventsFunction") + SetupEvents(eventsExtension.GetEventsFunctions() + .GetEventsFunction("MyOtherEventsFunction") .GetEvents()); } @@ -1651,7 +1654,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { // Add a (free) function with an object group gd::EventsFunction &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyEventsFunction", 0); gd::ObjectGroup &objectGroup = eventsFunction.GetObjectGroups().InsertNew("MyGroup", 0); objectGroup.AddObject("Object1"); @@ -1688,7 +1692,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { SetupProjectWithDummyPlatform(project, platform); auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.GetEventsFunction("MyOtherEventsFunction"); + eventsExtension.GetEventsFunctions().GetEventsFunction( + "MyOtherEventsFunction"); // Create the objects container for the events function gd::ObjectsContainer parametersObjectsContainer( @@ -1940,7 +1945,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { // Add a (free) function with an object group gd::EventsFunction &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyEventsFunction", 0); gd::ObjectGroup &objectGroup = eventsFunction.GetObjectGroups().InsertNew("MyGroup", 0); objectGroup.AddObject("Object1"); @@ -2138,7 +2144,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { // Add the function used by the instruction that is checked in this test. // When the function doesn't exist the destination extension, the // instruction keeps pointing to the old extension. - destinationExtension.InsertNewEventsFunction("MyEventsFunction", 0); + destinationExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyEventsFunction", 0); auto &duplicatedBehavior = destinationExtension.GetEventsBasedBehaviors().InsertNew( @@ -2180,7 +2187,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { // Add the function used by the instruction that is checked in this test. // When the function doesn't exist the destination extension, the // instruction keeps pointing to the old extension. - destinationExtension.InsertNewEventsFunction("MyEventsFunction", 0); + destinationExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyEventsFunction", 0); auto &duplicatedObject = destinationExtension.GetEventsBasedObjects().InsertNew( @@ -2289,6 +2297,7 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { // Free function auto &myEventsFunction = project.GetEventsFunctionsExtension("MyEventsExtension") + .GetEventsFunctions() .GetEventsFunction("MyEventsFunction"); REQUIRE(myEventsFunction.GetParameters().GetParameter(1).GetExtraInfo() == "MyRenamedExtension::MyEventsBasedObject"); @@ -2405,8 +2414,10 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { "MyEventsExtension::MyRenamedFunctionExpressionAndCondition"); // Check that the action still refer to the right ExpressionAndCondition. - REQUIRE(eventsExtension.GetEventsFunction("MyEventsFunctionActionWithOperator") - .GetGetterName() == "MyRenamedFunctionExpressionAndCondition"); + REQUIRE(eventsExtension.GetEventsFunctions() + .GetEventsFunction("MyEventsFunctionActionWithOperator") + .GetGetterName() == + "MyRenamedFunctionExpressionAndCondition"); } } @@ -2417,7 +2428,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyParameter") .GetValueTypeMetadata() @@ -2453,7 +2465,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyParameter") .GetValueTypeMetadata() @@ -2484,7 +2497,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyParameter") .GetValueTypeMetadata() @@ -2515,7 +2529,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyParameter") .GetValueTypeMetadata() @@ -2546,7 +2561,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyParameter") .GetValueTypeMetadata() @@ -2577,7 +2593,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyParameter") .GetValueTypeMetadata() @@ -2615,7 +2632,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyObject") .GetValueTypeMetadata() @@ -2656,7 +2674,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyObject") .GetValueTypeMetadata() @@ -2695,7 +2714,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyObject") .GetValueTypeMetadata() @@ -2741,7 +2761,8 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project); auto &eventsFunction = - eventsExtension.InsertNewEventsFunction("MyFreeEventsFunction", 0); + eventsExtension.GetEventsFunctions().InsertNewEventsFunction( + "MyFreeEventsFunction", 0); eventsFunction.GetParameters() .AddNewParameter("MyObject") .GetValueTypeMetadata() @@ -2935,6 +2956,7 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { // Free function auto &myEventsFunction = project.GetEventsFunctionsExtension("MyEventsExtension") + .GetEventsFunctions() .GetEventsFunction("MyEventsFunction"); REQUIRE(myEventsFunction.GetParameters().GetParameter(2).GetExtraInfo() == "MyEventsExtension::MyRenamedEventsBasedBehavior"); @@ -3045,6 +3067,7 @@ TEST_CASE("WholeProjectRefactorer", "[common]") { // Free function auto &myEventsFunction = project.GetEventsFunctionsExtension("MyEventsExtension") + .GetEventsFunctions() .GetEventsFunction("MyEventsFunction"); REQUIRE(myEventsFunction.GetParameters().GetParameter(1).GetExtraInfo() == "MyEventsExtension::MyRenamedEventsBasedObject"); diff --git a/GDJS/GDJS/Events/CodeGeneration/EventsCodeGenerator.cpp b/GDJS/GDJS/Events/CodeGeneration/EventsCodeGenerator.cpp index 935a9661b0ad..bd062712b344 100644 --- a/GDJS/GDJS/Events/CodeGeneration/EventsCodeGenerator.cpp +++ b/GDJS/GDJS/Events/CodeGeneration/EventsCodeGenerator.cpp @@ -146,18 +146,15 @@ gd::String EventsCodeGenerator::GenerateEventsFunctionCode( codeGenerator.SetDiagnosticReport(&diagnosticReport); gd::String output = GenerateEventsListCompleteFunctionCode( - codeGenerator, - codeGenerator.GetCodeNamespaceAccessor() + "func", + codeGenerator, codeGenerator.GetCodeNamespaceAccessor() + "func", codeGenerator.GenerateEventsFunctionParameterDeclarationsList( - eventsFunction.GetParametersForEvents(eventsFunctionsExtension), - 0, - true), + eventsFunction.GetParametersForEvents( + eventsFunctionsExtension.GetEventsFunctions()), + 0, true), codeGenerator.GenerateFreeEventsFunctionContext( - eventsFunctionsExtension, - eventsFunction, + eventsFunctionsExtension, eventsFunction, "runtimeScene.getOnceTriggers()"), - eventsFunction.GetEvents(), - "", + eventsFunction.GetEvents(), "", codeGenerator.GenerateEventsFunctionReturn(eventsFunction)); // TODO: the editor should pass the diagnostic report and display it to the @@ -387,7 +384,7 @@ gd::String EventsCodeGenerator::GenerateFreeEventsFunctionContext( gd::String objectArraysMap; gd::String behaviorNamesMap; return GenerateEventsFunctionContext(eventsFunctionsExtension, - eventsFunctionsExtension, + eventsFunctionsExtension.GetEventsFunctions(), eventsFunction, onceTriggersVariable, objectsGettersMap, diff --git a/GDJS/GDJS/Events/CodeGeneration/MetadataDeclarationHelper.cpp b/GDJS/GDJS/Events/CodeGeneration/MetadataDeclarationHelper.cpp index ec783669c438..79b4fdb4780b 100644 --- a/GDJS/GDJS/Events/CodeGeneration/MetadataDeclarationHelper.cpp +++ b/GDJS/GDJS/Events/CodeGeneration/MetadataDeclarationHelper.cpp @@ -517,6 +517,7 @@ MetadataDeclarationHelper::DeclareExpressionMetadata( const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsFunction &eventsFunction) { auto functionType = eventsFunction.GetFunctionType(); + auto &freeEventsFunctions = eventsFunctionsExtension.GetEventsFunctions(); if (functionType == gd::EventsFunction::ExpressionAndCondition) { auto expressionAndCondition = extension.AddExpressionAndCondition( gd::ValueTypeMetadata::GetPrimitiveValueType( @@ -530,7 +531,7 @@ MetadataDeclarationHelper::DeclareExpressionMetadata( eventsFunction.GetGroup(), GetExtensionIconUrl(extension)); // By convention, first parameter is always the Runtime Scene. expressionAndCondition.AddCodeOnlyParameter("currentScene", ""); - DeclareEventsFunctionParameters(eventsFunctionsExtension, eventsFunction, + DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction, expressionAndCondition, 0); expressionAndConditions.push_back(expressionAndCondition); return expressionAndConditions.back(); @@ -551,7 +552,7 @@ MetadataDeclarationHelper::DeclareExpressionMetadata( eventsFunction.GetGroup(), GetExtensionIconUrl(extension)); // By convention, first parameter is always the Runtime Scene. expression.AddCodeOnlyParameter("currentScene", ""); - DeclareEventsFunctionParameters(eventsFunctionsExtension, eventsFunction, + DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction, expression, 0); return expression; } @@ -566,6 +567,7 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata( const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsFunction &eventsFunction) { auto functionType = eventsFunction.GetFunctionType(); + auto &freeEventsFunctions = eventsFunctionsExtension.GetEventsFunctions(); if (functionType == gd::EventsFunction::Condition) { auto &condition = extension.AddCondition( eventsFunction.GetName(), @@ -575,14 +577,14 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata( GetExtensionIconUrl(extension), GetExtensionIconUrl(extension)); // By convention, first parameter is always the Runtime Scene. condition.AddCodeOnlyParameter("currentScene", ""); - DeclareEventsFunctionParameters(eventsFunctionsExtension, eventsFunction, + DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction, condition, 0); return condition; } else if (functionType == gd::EventsFunction::ActionWithOperator) { - if (eventsFunctionsExtension.HasEventsFunctionNamed( + if (freeEventsFunctions.HasEventsFunctionNamed( eventsFunction.GetGetterName())) { - auto &getterFunction = eventsFunctionsExtension.GetEventsFunction( - eventsFunction.GetGetterName()); + auto &getterFunction = + freeEventsFunctions.GetEventsFunction(eventsFunction.GetGetterName()); auto &action = extension.AddAction( eventsFunction.GetName(), @@ -601,7 +603,7 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata( getterFunction)); // By convention, first parameter is always the Runtime Scene. action.AddCodeOnlyParameter("currentScene", ""); - DeclareEventsFunctionParameters(eventsFunctionsExtension, eventsFunction, + DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction, action, 0); return action; } else { @@ -615,7 +617,7 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata( GetExtensionIconUrl(extension)); // By convention, first parameter is always the Runtime Scene. action.AddCodeOnlyParameter("currentScene", ""); - DeclareEventsFunctionParameters(eventsFunctionsExtension, eventsFunction, + DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction, action, 0); return action; } @@ -628,7 +630,7 @@ gd::InstructionMetadata &MetadataDeclarationHelper::DeclareInstructionMetadata( GetExtensionIconUrl(extension), GetExtensionIconUrl(extension)); // By convention, first parameter is always the Runtime Scene. action.AddCodeOnlyParameter("currentScene", ""); - DeclareEventsFunctionParameters(eventsFunctionsExtension, eventsFunction, + DeclareEventsFunctionParameters(freeEventsFunctions, eventsFunction, action, 0); return action; } diff --git a/GDevelop.js/Bindings/Bindings.idl b/GDevelop.js/Bindings/Bindings.idl index 126f5049ee01..845cc7eb43d8 100644 --- a/GDevelop.js/Bindings/Bindings.idl +++ b/GDevelop.js/Bindings/Bindings.idl @@ -3218,6 +3218,7 @@ interface EventsFunctionsExtension { void RemoveSourceFileAt(unsigned long index); [Ref] VectorSourceFileMetadata GetAllSourceFiles(); + [Ref] EventsFunctionsContainer GetEventsFunctions(); [Ref] VariablesContainer GetGlobalVariables(); [Ref] VariablesContainer GetSceneVariables(); @@ -3228,17 +3229,6 @@ interface EventsFunctionsExtension { void UnserializeFrom([Ref] Project project, [Const, Ref] SerializerElement element); boolean STATIC_IsExtensionLifecycleEventsFunction([Const] DOMString eventsFunctionName); - - // Inherited from EventsFunctionsContainer: - [Ref] EventsFunction InsertNewEventsFunction([Const] DOMString name, unsigned long pos); - [Ref] EventsFunction InsertEventsFunction([Const, Ref] EventsFunction eventsFunction, unsigned long pos); - boolean HasEventsFunctionNamed([Const] DOMString name); - [Ref] EventsFunction GetEventsFunction([Const] DOMString name); - [Ref] EventsFunction GetEventsFunctionAt(unsigned long pos); - void RemoveEventsFunction([Const] DOMString name); - void MoveEventsFunction(unsigned long oldIndex, unsigned long newIndex); - unsigned long GetEventsFunctionsCount(); - unsigned long GetEventsFunctionPosition([Const, Ref] EventsFunction eventsFunction); }; interface AbstractFileSystem { diff --git a/GDevelop.js/TestUtils/CodeGenerationHelpers.js b/GDevelop.js/TestUtils/CodeGenerationHelpers.js index 34dabcbbd150..545703e499a3 100644 --- a/GDevelop.js/TestUtils/CodeGenerationHelpers.js +++ b/GDevelop.js/TestUtils/CodeGenerationHelpers.js @@ -265,8 +265,9 @@ function generateCompiledEventsForSerializedEventsBasedExtension( const eventsFunctionsExtensionCodeGenerator = new gd.EventsFunctionsExtensionCodeGenerator( project ); - for (let i = 0; i < extension.getEventsFunctionsCount(); i++) { - const eventsFunction = extension.getEventsFunctionAt(i); + const freeEventsFunctions = extension.getEventsFunctions(); + for (let i = 0; i < freeEventsFunctions.getEventsFunctionsCount(); i++) { + const eventsFunction = freeEventsFunctions.getEventsFunctionAt(i); generatedExtensionModule.freeFunctions[ eventsFunction.getName() ] = generatedEventsCodeToJSFunction( diff --git a/GDevelop.js/__tests__/Core.js b/GDevelop.js/__tests__/Core.js index 3348c89666dd..76cf50be374f 100644 --- a/GDevelop.js/__tests__/Core.js +++ b/GDevelop.js/__tests__/Core.js @@ -4596,22 +4596,23 @@ describe('libGD.js', function () { 'http://resources.gdevelop-app.com/test' ); - const eventsFunction = eventsFunctionsExtension.insertNewEventsFunction( + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + const eventsFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); expect( - eventsFunctionsExtension.hasEventsFunctionNamed('MyFunction') + freeEventsFunctions.hasEventsFunctionNamed('MyFunction') ).toBe(true); expect( - eventsFunctionsExtension.hasEventsFunctionNamed('MyNotExistingFunction') + freeEventsFunctions.hasEventsFunctionNamed('MyNotExistingFunction') ).toBe(false); - expect(eventsFunctionsExtension.getEventsFunctionsCount()).toBe(1); - expect(eventsFunctionsExtension.getEventsFunctionAt(0).getName()).toBe( + expect(freeEventsFunctions.getEventsFunctionsCount()).toBe(1); + expect(freeEventsFunctions.getEventsFunctionAt(0).getName()).toBe( 'MyFunction' ); expect( - eventsFunctionsExtension.getEventsFunction('MyFunction').getName() + freeEventsFunctions.getEventsFunction('MyFunction').getName() ).toBe('MyFunction'); eventsFunctionsExtension.delete(); diff --git a/GDevelop.js/__tests__/GDJSFreeFunctionCodeGenerationIntegrationTests.js b/GDevelop.js/__tests__/GDJSFreeFunctionCodeGenerationIntegrationTests.js index 0aa52564326b..4273d7f50301 100644 --- a/GDevelop.js/__tests__/GDJSFreeFunctionCodeGenerationIntegrationTests.js +++ b/GDevelop.js/__tests__/GDJSFreeFunctionCodeGenerationIntegrationTests.js @@ -42,7 +42,8 @@ describe('libGD.js - GDJS Free Function Code Generation integration tests', func ], }, ]); - const eventsFunction = eventsFunctionsExtension.insertNewEventsFunction( + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + const eventsFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); @@ -117,7 +118,8 @@ describe('libGD.js - GDJS Free Function Code Generation integration tests', func ], }, ]); - const eventsFunction = eventsFunctionsExtension.insertNewEventsFunction( + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + const eventsFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); @@ -199,7 +201,8 @@ describe('libGD.js - GDJS Free Function Code Generation integration tests', func ], }, ]); - const eventsFunction = eventsFunctionsExtension.insertNewEventsFunction( + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + const eventsFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); diff --git a/GDevelop.js/__tests__/MetadataDeclarationHelper.js b/GDevelop.js/__tests__/MetadataDeclarationHelper.js index b818b601062b..9b7dd78cb2c5 100644 --- a/GDevelop.js/__tests__/MetadataDeclarationHelper.js +++ b/GDevelop.js/__tests__/MetadataDeclarationHelper.js @@ -14,7 +14,8 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction( + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); @@ -50,7 +51,8 @@ describe('MetadataDeclarationHelper', () => { 'My🧩Extension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction( + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction( 'My_📝Function', 0 ); @@ -83,7 +85,8 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction( + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); @@ -119,7 +122,8 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction( + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); @@ -153,7 +157,8 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction('Value', 0); + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction('Value', 0); eventFunction.setFunctionType(gd.EventsFunction.ExpressionAndCondition); eventFunction.setFullName('Some value'); eventFunction.setDescription('some value.'); @@ -192,14 +197,15 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); + const freeEventsFunctions = eventExtension.getEventsFunctions(); - const getter = eventExtension.insertNewEventsFunction('Value', 0); + const getter = freeEventsFunctions.insertNewEventsFunction('Value', 0); getter.setFunctionType(gd.EventsFunction.ExpressionAndConditions); getter.setFullName('Some value'); getter.setDescription('some value.'); getter.setSentence('some value'); - const eventFunction = eventExtension.insertNewEventsFunction('SetValue', 0); + const eventFunction = freeEventsFunctions.insertNewEventsFunction('SetValue', 0); eventFunction.setFunctionType(gd.EventsFunction.ActionWithOperator); eventFunction.setGetterName('Value'); @@ -1682,7 +1688,8 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction( + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); @@ -1723,7 +1730,8 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction( + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction( 'MyFunction', 0 ); @@ -1764,7 +1772,8 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); - const eventFunction = eventExtension.insertNewEventsFunction('Value', 0); + const freeEventsFunctions = eventExtension.getEventsFunctions(); + const eventFunction = freeEventsFunctions.insertNewEventsFunction('Value', 0); eventFunction.setFunctionType(gd.EventsFunction.ExpressionAndCondition); eventFunction.setFullName(''); eventFunction.setDescription(''); @@ -1807,8 +1816,9 @@ describe('MetadataDeclarationHelper', () => { 'MyExtension', 0 ); + const freeEventsFunctions = eventExtension.getEventsFunctions(); - const getter = eventExtension.insertNewEventsFunction('Value', 0); + const getter = freeEventsFunctions.insertNewEventsFunction('Value', 0); getter.setFunctionType(gd.EventsFunction.ExpressionAndConditions); getter.setFullName(''); getter.setDescription(''); @@ -1819,7 +1829,7 @@ describe('MetadataDeclarationHelper', () => { .addNewParameter('Parameter') .setType('number'); - const eventFunction = eventExtension.insertNewEventsFunction('SetValue', 0); + const eventFunction = freeEventsFunctions.insertNewEventsFunction('SetValue', 0); eventFunction.setFunctionType(gd.EventsFunction.ActionWithOperator); eventFunction.setGetterName('Value'); diff --git a/GDevelop.js/types.d.ts b/GDevelop.js/types.d.ts index ba989d177ef0..6c480b6921d1 100644 --- a/GDevelop.js/types.d.ts +++ b/GDevelop.js/types.d.ts @@ -2343,6 +2343,7 @@ export class EventsFunctionsExtension extends EmscriptenObject { addSourceFile(): SourceFileMetadata; removeSourceFileAt(index: number): void; getAllSourceFiles(): VectorSourceFileMetadata; + getEventsFunctions(): EventsFunctionsContainer; getGlobalVariables(): VariablesContainer; getSceneVariables(): VariablesContainer; getEventsBasedBehaviors(): EventsBasedBehaviorsList; @@ -2350,15 +2351,6 @@ export class EventsFunctionsExtension extends EmscriptenObject { serializeTo(element: SerializerElement): void; unserializeFrom(project: Project, element: SerializerElement): void; static isExtensionLifecycleEventsFunction(eventsFunctionName: string): boolean; - insertNewEventsFunction(name: string, pos: number): EventsFunction; - insertEventsFunction(eventsFunction: EventsFunction, pos: number): EventsFunction; - hasEventsFunctionNamed(name: string): boolean; - getEventsFunction(name: string): EventsFunction; - getEventsFunctionAt(pos: number): EventsFunction; - removeEventsFunction(name: string): void; - moveEventsFunction(oldIndex: number, newIndex: number): void; - getEventsFunctionsCount(): number; - getEventsFunctionPosition(eventsFunction: EventsFunction): number; } export class AbstractFileSystem extends EmscriptenObject {} diff --git a/GDevelop.js/types/gdeventsfunctionsextension.js b/GDevelop.js/types/gdeventsfunctionsextension.js index 8c5a62c1d427..d4f8f9ea15d4 100644 --- a/GDevelop.js/types/gdeventsfunctionsextension.js +++ b/GDevelop.js/types/gdeventsfunctionsextension.js @@ -34,6 +34,7 @@ declare class gdEventsFunctionsExtension extends gdEventsFunctionsContainer { addSourceFile(): gdSourceFileMetadata; removeSourceFileAt(index: number): void; getAllSourceFiles(): gdVectorSourceFileMetadata; + getEventsFunctions(): gdEventsFunctionsContainer; getGlobalVariables(): gdVariablesContainer; getSceneVariables(): gdVariablesContainer; getEventsBasedBehaviors(): gdEventsBasedBehaviorsList; @@ -41,15 +42,6 @@ declare class gdEventsFunctionsExtension extends gdEventsFunctionsContainer { serializeTo(element: gdSerializerElement): void; unserializeFrom(project: gdProject, element: gdSerializerElement): void; static isExtensionLifecycleEventsFunction(eventsFunctionName: string): boolean; - insertNewEventsFunction(name: string, pos: number): gdEventsFunction; - insertEventsFunction(eventsFunction: gdEventsFunction, pos: number): gdEventsFunction; - hasEventsFunctionNamed(name: string): boolean; - getEventsFunction(name: string): gdEventsFunction; - getEventsFunctionAt(pos: number): gdEventsFunction; - removeEventsFunction(name: string): void; - moveEventsFunction(oldIndex: number, newIndex: number): void; - getEventsFunctionsCount(): number; - getEventsFunctionPosition(eventsFunction: gdEventsFunction): number; delete(): void; ptr: number; }; \ No newline at end of file diff --git a/newIDE/app/scripts/extract-extensions-document.js b/newIDE/app/scripts/extract-extensions-document.js index ff6ca6db39b2..d6ca67d88cf1 100644 --- a/newIDE/app/scripts/extract-extensions-document.js +++ b/newIDE/app/scripts/extract-extensions-document.js @@ -326,8 +326,9 @@ const generateEventsFunctionExtensionMetadata = ( ); // Generate all free functions const metadataDeclarationHelper = new gd.MetadataDeclarationHelper(); - mapFor(0, eventsFunctionsExtension.getEventsFunctionsCount(), i => { - const eventsFunction = eventsFunctionsExtension.getEventsFunctionAt(i); + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + mapFor(0, freeEventsFunctions.getEventsFunctionsCount(), i => { + const eventsFunction = freeEventsFunctions.getEventsFunctionAt(i); metadataDeclarationHelper.generateFreeFunctionMetadata( project, extension, diff --git a/newIDE/app/src/EventsFunctionsExtensionEditor/index.js b/newIDE/app/src/EventsFunctionsExtensionEditor/index.js index 09299a176526..623a21f36de2 100644 --- a/newIDE/app/src/EventsFunctionsExtensionEditor/index.js +++ b/newIDE/app/src/EventsFunctionsExtensionEditor/index.js @@ -1255,12 +1255,13 @@ export default class EventsFunctionsExtensionEditor extends React.Component< } } else { const { eventsFunctionsExtension } = this.props; + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); for ( let index = 0; - index < eventsFunctionsExtension.getEventsFunctionsCount(); + index < freeEventsFunctions.getEventsFunctionsCount(); index++ ) { - const groupName = eventsFunctionsExtension + const groupName = freeEventsFunctions .getEventsFunctionAt(index) .getGroup(); if (groupName) { diff --git a/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js b/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js index 72dcb908f287..1cd2032e1bc9 100644 --- a/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js +++ b/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js @@ -115,8 +115,9 @@ const getExtensionIncludeFiles = ( eventsFunctionsExtension: gdEventsFunctionsExtension, options: Options ): Array => { - return mapFor(0, eventsFunctionsExtension.getEventsFunctionsCount(), i => { - const eventsFunction = eventsFunctionsExtension.getEventsFunctionAt(i); + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + return mapFor(0, freeEventsFunctions.getEventsFunctionsCount(), i => { + const eventsFunction = freeEventsFunctions.getEventsFunctionAt(i); const functionName = gd.MetadataDeclarationHelper.getFreeFunctionCodeName( eventsFunctionsExtension, @@ -192,19 +193,25 @@ const generateEventsFunctionExtension = ( .then(() => // Generate all free functions Promise.all( - mapFor(0, eventsFunctionsExtension.getEventsFunctionsCount(), i => { - const eventsFunction = eventsFunctionsExtension.getEventsFunctionAt( - i - ); - return generateFreeFunction( - project, - extension, - eventsFunctionsExtension, - eventsFunction, - options, - codeGenerationContext - ); - }) + mapFor( + 0, + eventsFunctionsExtension + .getEventsFunctions() + .getEventsFunctionsCount(), + i => { + const eventsFunction = eventsFunctionsExtension + .getEventsFunctions() + .getEventsFunctionAt(i); + return generateFreeFunction( + project, + extension, + eventsFunctionsExtension, + eventsFunction, + options, + codeGenerationContext + ); + } + ) ) ) .then(functionInfos => { @@ -278,8 +285,9 @@ const generateEventsFunctionExtensionMetadata = ( ); // Generate all free functions const metadataDeclarationHelper = new gd.MetadataDeclarationHelper(); - mapFor(0, eventsFunctionsExtension.getEventsFunctionsCount(), i => { - const eventsFunction = eventsFunctionsExtension.getEventsFunctionAt(i); + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + mapFor(0, freeEventsFunctions.getEventsFunctionsCount(), i => { + const eventsFunction = freeEventsFunctions.getEventsFunctionAt(i); return generateFreeFunctionMetadata( project, extension, diff --git a/newIDE/app/src/EventsFunctionsList/index.js b/newIDE/app/src/EventsFunctionsList/index.js index 42b3bdf1a9a1..b31a8d07569f 100644 --- a/newIDE/app/src/EventsFunctionsList/index.js +++ b/newIDE/app/src/EventsFunctionsList/index.js @@ -1144,14 +1144,15 @@ const EventsFunctionsList = React.forwardRef< icon: , label: i18n._(t`Add a function`), click: () => { + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); const index = !selectedEventsBasedBehavior && !selectedEventsBasedObject && selectedEventsFunction - ? eventsFunctionsExtension.getEventsFunctionPosition( + ? freeEventsFunctions.getEventsFunctionPosition( selectedEventsFunction ) + 1 - : eventsFunctionsExtension.getEventsFunctionsCount(); + : freeEventsFunctions.getEventsFunctionsCount(); addNewEventsFunction({ itemContent: null, eventsBasedBehavior: null, @@ -1162,7 +1163,8 @@ const EventsFunctionsList = React.forwardRef< } ), getChildren(i18n: I18nType): ?Array { - if (eventsFunctionsExtension.getEventsFunctionsCount() === 0) { + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); + if (freeEventsFunctions.getEventsFunctionsCount() === 0) { return [ new PlaceHolderTreeViewItem( extensionFunctionsEmptyPlaceholderId, @@ -1171,16 +1173,16 @@ const EventsFunctionsList = React.forwardRef< ]; } const freeFunctionProps = { - eventsFunctionsContainer: eventsFunctionsExtension, + eventsFunctionsContainer: freeEventsFunctions, ...eventFunctionCommonProps, }; return mapFor( 0, - eventsFunctionsExtension.getEventsFunctionsCount(), + freeEventsFunctions.getEventsFunctionsCount(), i => new LeafTreeViewItem( new EventsFunctionTreeViewItemContent( - eventsFunctionsExtension.getEventsFunctionAt(i), + freeEventsFunctions.getEventsFunctionAt(i), freeFunctionProps ) ) diff --git a/newIDE/app/src/EventsSheet/EventsFunctionExtractor/EventsFunctionExtractorDialog.js b/newIDE/app/src/EventsSheet/EventsFunctionExtractor/EventsFunctionExtractorDialog.js index 0e15de6f21e3..e30486fc37af 100644 --- a/newIDE/app/src/EventsSheet/EventsFunctionExtractor/EventsFunctionExtractorDialog.js +++ b/newIDE/app/src/EventsSheet/EventsFunctionExtractor/EventsFunctionExtractorDialog.js @@ -114,12 +114,13 @@ export default class EventsFunctionExtractorDialog extends React.Component< const eventsFunctionsExtension = project.getEventsFunctionsExtension( extensionName ); + const freeEventsFunctions = eventsFunctionsExtension.getEventsFunctions(); for ( let index = 0; - index < eventsFunctionsExtension.getEventsFunctionsCount(); + index < freeEventsFunctions.getEventsFunctionsCount(); index++ ) { - const groupName = eventsFunctionsExtension + const groupName = freeEventsFunctions .getEventsFunctionAt(index) .getGroup(); if (groupName) { diff --git a/newIDE/app/src/fixtures/TestProject.js b/newIDE/app/src/fixtures/TestProject.js index 61cc87c0b880..21eec4a22ef5 100644 --- a/newIDE/app/src/fixtures/TestProject.js +++ b/newIDE/app/src/fixtures/TestProject.js @@ -658,10 +658,9 @@ export const makeTestProject = (gd /*: libGDevelop */) /*: TestProject */ => { testEventsFunctionsExtension.setDescription('My description'); // Events function - const testEventsFunction = testEventsFunctionsExtension.insertNewEventsFunction( - 'MyTestFunction', - 0 - ); + const testEventsFunction = testEventsFunctionsExtension + .getEventsFunctions() + .insertNewEventsFunction('MyTestFunction', 0); testEventsFunction .getParameters() @@ -688,8 +687,11 @@ export const makeTestProject = (gd /*: libGDevelop */) /*: TestProject */ => { .getEvents() .insertNewEvent(project, 'BuiltinCommonInstructions::Standard', 0); - testEventsFunctionsExtension.insertNewEventsFunction('MyTestFunction2', 1); testEventsFunctionsExtension + .getEventsFunctions() + .insertNewEventsFunction('MyTestFunction2', 1); + testEventsFunctionsExtension + .getEventsFunctions() .insertNewEventsFunction('MyPrivateTestFunction3', 2) .setPrivate(true);