GDevelop JS Platform
Platform for developing HTML5/Javascript based games with GDevelop
MetadataDeclarationHelper.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2023 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include "GDCore/String.h"
9 #include <functional>
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 
15 namespace gd {
16 class PlatformExtension;
17 class Project;
18 class EventsFunctionsExtension;
19 class EventsBasedBehavior;
20 class BehaviorMetadata;
21 class EventsBasedObject;
22 class ObjectMetadata;
23 class EventsFunction;
24 class PropertyDescriptor;
25 class EventsFunctionsContainer;
26 class AbstractFunctionMetadata;
27 class InstructionOrExpressionContainerMetadata;
28 class AbstractEventsBasedEntity;
29 class NamedPropertyDescriptor;
30 class ParameterMetadata;
31 class InstructionMetadata;
32 class ExpressionMetadata;
33 class MultipleInstructionMetadata;
34 } // namespace gd
35 
36 namespace gdjs {
37 
48 public:
50  virtual ~MetadataDeclarationHelper(){};
51 
52  gd::AbstractFunctionMetadata &GenerateFreeFunctionMetadata(
53  const gd::Project &project, gd::PlatformExtension &extension,
54  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
55  const gd::EventsFunction &eventsFunction);
56 
57  static gd::BehaviorMetadata &GenerateBehaviorMetadata(
58  const gd::Project &project, gd::PlatformExtension &extension,
59  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
60  const gd::EventsBasedBehavior &eventsBasedBehavior,
61  std::map<gd::String, gd::String> &behaviorMethodMangledNames);
62 
63  static gd::ObjectMetadata &GenerateObjectMetadata(
64  gd::Project &project, gd::PlatformExtension &extension,
65  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
66  const gd::EventsBasedObject &eventsBasedObject,
67  std::map<gd::String, gd::String> &objectMethodMangledNames);
68 
70  static gd::String GetExtensionCodeNamespacePrefix(
71  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
72 
74  static gd::String GetFreeFunctionCodeName(
75  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
76  const gd::EventsFunction &eventsFunction);
77 
79  static gd::String
80  GetFreeFunctionCodeNamespace(const gd::EventsFunction &eventsFunction,
81  const gd::String &codeNamespacePrefix);
82 
84  static gd::String GetBehaviorFunctionCodeNamespace(
85  const gd::EventsBasedBehavior &eventsBasedBehavior,
86  const gd::String &codeNamespacePrefix);
87 
89  static gd::String
90  GetObjectFunctionCodeNamespace(const gd::EventsBasedObject &eventsBasedObject,
91  const gd::String &codeNamespacePrefix);
92 
96  static void DeclareExtension(
97  gd::PlatformExtension &extension,
98  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
99 
105  static bool IsBehaviorLifecycleEventsFunction(const gd::String &functionName);
106 
112  static bool IsObjectLifecycleEventsFunction(const gd::String &functionName);
113 
119  static bool
120  IsExtensionLifecycleEventsFunction(const gd::String &functionName);
121 
122  static gd::String ShiftSentenceParamIndexes(const gd::String &sentence,
123  const int offset);
124 
125 private:
126  static const gd::String &
127  GetExtensionIconUrl(gd::PlatformExtension &extension);
128 
132  static void DeclareExtensionDependencies(
133  gd::PlatformExtension &extension,
134  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
135 
140  static void DeclarePropertyInstructionAndExpression(
141  gd::PlatformExtension &extension,
142  gd::InstructionOrExpressionContainerMetadata &entityMetadata,
143  const gd::AbstractEventsBasedEntity &eventsBasedEntity,
144  const gd::NamedPropertyDescriptor &property,
145  const gd::String &propertyLabel, const gd::String &expressionName,
146  const gd::String &conditionName, const gd::String &actionName,
147  const gd::String &toggleActionName, const gd::String &setterName,
148  const gd::String &getterName, const gd::String &toggleFunctionName,
149  const int valueParameterIndex,
150  std::function<gd::AbstractFunctionMetadata &(
151  gd::AbstractFunctionMetadata &instructionOrExpression)>
152  addObjectAndBehaviorParameters,
153  bool isSharedProperty);
154 
161  static void DeclareBehaviorPropertiesInstructionAndExpressions(
162  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
163  const gd::EventsBasedBehavior &eventsBasedBehavior);
164 
171  static void DeclareObjectPropertiesInstructionAndExpressions(
172  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
173  const gd::EventsBasedObject &eventsBasedObject);
174 
181  static void DeclareObjectInternalInstructions(
182  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
183  const gd::EventsBasedObject &eventsBasedObject);
184 
185  static const gd::String defaultExtensionIconPath;
186 
191  static gd::BehaviorMetadata &
192  DeclareBehaviorMetadata(const gd::Project &project,
193  gd::PlatformExtension &extension,
194  const gd::EventsBasedBehavior &eventsBasedBehavior);
195 
200  static gd::ObjectMetadata &
201  DeclareObjectMetadata(gd::PlatformExtension &extension,
202  const gd::EventsBasedObject &eventsBasedObject);
203 
204  static void
205  AddParameter(gd::AbstractFunctionMetadata &instructionOrExpression,
206  const gd::ParameterMetadata &parameter);
207 
212  gd::AbstractFunctionMetadata &DeclareInstructionOrExpressionMetadata(
213  gd::PlatformExtension &extension,
214  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
215  const gd::EventsFunction &eventsFunction);
216 
221  gd::AbstractFunctionMetadata &DeclareExpressionMetadata(
222  gd::PlatformExtension &extension,
223  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
224  const gd::EventsFunction &eventsFunction);
225 
230  static gd::InstructionMetadata &DeclareInstructionMetadata(
231  gd::PlatformExtension &extension,
232  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
233  const gd::EventsFunction &eventsFunction);
234 
239  gd::AbstractFunctionMetadata &DeclareBehaviorInstructionOrExpressionMetadata(
240  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
241  const gd::EventsBasedBehavior &eventsBasedBehavior,
242  const gd::EventsFunction &eventsFunction,
243  std::map<gd::String, gd::String> &objectMethodMangledNames);
244 
249  gd::AbstractFunctionMetadata &DeclareBehaviorExpressionMetadata(
250  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
251  const gd::EventsBasedBehavior &eventsBasedBehavior,
252  const gd::EventsFunction &eventsFunction);
253 
258  static gd::InstructionMetadata &DeclareBehaviorInstructionMetadata(
259  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
260  const gd::EventsBasedBehavior &eventsBasedBehavior,
261  const gd::EventsFunction &eventsFunction);
262 
267  gd::AbstractFunctionMetadata &DeclareObjectInstructionOrExpressionMetadata(
268  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
269  const gd::EventsBasedObject &eventsBasedObject,
270  const gd::EventsFunction &eventsFunction,
271  std::map<gd::String, gd::String> &objectMethodMangledNames);
272 
277  gd::AbstractFunctionMetadata &DeclareObjectExpressionMetadata(
278  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
279  const gd::EventsBasedObject &eventsBasedObject,
280  const gd::EventsFunction &eventsFunction);
281 
286  static gd::InstructionMetadata &DeclareObjectInstructionMetadata(
287  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
288  const gd::EventsBasedObject &eventsBasedObject,
289  const gd::EventsFunction &eventsFunction);
290 
295  static void DeclareEventsFunctionParameters(
296  const gd::EventsFunctionsContainer &eventsFunctionsContainer,
297  const gd::EventsFunction &eventsFunction,
298  gd::ExpressionMetadata &expression,
299  const int userDefinedFirstParameterIndex);
300 
305  static void DeclareEventsFunctionParameters(
306  const gd::EventsFunctionsContainer &eventsFunctionsContainer,
307  const gd::EventsFunction &eventsFunction,
308  gd::InstructionMetadata &instruction,
309  const int userDefinedFirstParameterIndex);
310 
315  static void DeclareEventsFunctionParameters(
316  const gd::EventsFunctionsContainer &eventsFunctionsContainer,
317  const gd::EventsFunction &eventsFunction,
318  gd::MultipleInstructionMetadata &multipleInstructionMetadata,
319  const int userDefinedFirstParameterIndex);
320 
321  static void
322  UpdateCustomObjectDefaultBehaviors(gd::Project &project,
323  const gd::ObjectMetadata &objectMetadata);
324 
325  static gd::String RemoveTrailingDot(const gd::String &description);
326 
327  static gd::String
328  GetStringifiedExtraInfo(const gd::PropertyDescriptor &property);
329 
330  static gd::String UncapitalizeFirstLetter(const gd::String &string);
331 
332  static gd::String GetFullName(const gd::EventsFunction &eventsFunction);
333  static gd::String GetDefaultSentence(const gd::EventsFunction &eventsFunction,
334  const int firstParameterIndex,
335  const int parameterIndexOffset);
336  static gd::String
337  GetFreeFunctionSentence(const gd::EventsFunction &eventsFunction);
338  static gd::String
339  GetBehaviorFunctionSentence(const gd::EventsFunction &eventsFunction,
340  const bool excludeObjectParameter = false);
341  static gd::String
342  GetObjectFunctionSentence(const gd::EventsFunction &eventsFunction,
343  const bool excludeObjectParameter = false);
344 
345  std::vector<gd::MultipleInstructionMetadata> expressionAndConditions;
346 };
347 
348 } // namespace gdjs
This file contains the logic to declare extension metadata from events functions or events based beha...
Definition: MetadataDeclarationHelper.h:47
static void DeclareExtension(gd::PlatformExtension &extension, const gd::EventsFunctionsExtension &eventsFunctionsExtension)
Definition: MetadataDeclarationHelper.cpp:31
static bool IsExtensionLifecycleEventsFunction(const gd::String &functionName)
Definition: MetadataDeclarationHelper.cpp:413
static gd::String GetBehaviorFunctionCodeNamespace(const gd::EventsBasedBehavior &eventsBasedBehavior, const gd::String &codeNamespacePrefix)
Definition: MetadataDeclarationHelper.cpp:1527
static gd::String GetFreeFunctionCodeName(const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsFunction &eventsFunction)
Definition: MetadataDeclarationHelper.cpp:1517
static gd::String GetExtensionCodeNamespacePrefix(const gd::EventsFunctionsExtension &eventsFunctionsExtension)
Definition: MetadataDeclarationHelper.cpp:1503
static bool IsObjectLifecycleEventsFunction(const gd::String &functionName)
Definition: MetadataDeclarationHelper.cpp:402
static gd::String GetObjectFunctionCodeNamespace(const gd::EventsBasedObject &eventsBasedObject, const gd::String &codeNamespacePrefix)
Definition: MetadataDeclarationHelper.cpp:1535
static bool IsBehaviorLifecycleEventsFunction(const gd::String &functionName)
Definition: MetadataDeclarationHelper.cpp:388
static gd::String GetFreeFunctionCodeNamespace(const gd::EventsFunction &eventsFunction, const gd::String &codeNamespacePrefix)
Definition: MetadataDeclarationHelper.cpp:1510