mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Remove EventsFunctionsExtension inheritance to EventsFunctionsContainer (#7326)
- developer changelog only
This commit is contained in:
@@ -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()
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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(
|
||||
|
@@ -33,6 +33,17 @@ public:
|
||||
|
||||
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.
|
||||
*
|
||||
|
@@ -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"));
|
||||
|
||||
|
@@ -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<gd::DependencyMetadata> dependencies;
|
||||
std::vector<gd::SourceFileMetadata> sourceFiles;
|
||||
|
||||
gd::EventsFunctionsContainer eventsFunctionsContainer;
|
||||
gd::VariablesContainer globalVariables;
|
||||
gd::VariablesContainer sceneVariables;
|
||||
};
|
||||
|
@@ -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;
|
||||
};
|
||||
|
@@ -52,7 +52,7 @@ VariablesContainersList::MakeNewVariablesContainersListForFreeEventsFunction(
|
||||
variablesContainersList.Push(extension.GetSceneVariables());
|
||||
|
||||
gd::EventsFunctionTools::ParametersToVariablesContainer(
|
||||
eventsFunction.GetParametersForEvents(extension),
|
||||
eventsFunction.GetParametersForEvents(extension.GetEventsFunctions()),
|
||||
parameterVariablesContainer);
|
||||
variablesContainersList.Push(parameterVariablesContainer);
|
||||
|
||||
|
@@ -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");
|
||||
|
@@ -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");
|
||||
}
|
||||
}
|
||||
|
@@ -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<gd::StandardEvent &>(function.GetEvents().InsertNewEvent(
|
||||
project, "BuiltinCommonInstructions::Standard"));
|
||||
|
@@ -269,8 +269,9 @@ const std::vector<const gd::EventsList *> 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");
|
||||
|
@@ -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,
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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(
|
||||
|
@@ -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();
|
||||
|
@@ -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
|
||||
);
|
||||
|
@@ -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');
|
||||
|
||||
|
10
GDevelop.js/types.d.ts
vendored
10
GDevelop.js/types.d.ts
vendored
@@ -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 {}
|
||||
|
@@ -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;
|
||||
};
|
@@ -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,
|
||||
|
@@ -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) {
|
||||
|
@@ -115,8 +115,9 @@ const getExtensionIncludeFiles = (
|
||||
eventsFunctionsExtension: gdEventsFunctionsExtension,
|
||||
options: Options
|
||||
): Array<string> => {
|
||||
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,
|
||||
|
@@ -1144,14 +1144,15 @@ const EventsFunctionsList = React.forwardRef<
|
||||
icon: <Add />,
|
||||
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<TreeViewItem> {
|
||||
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
|
||||
)
|
||||
)
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user