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(const gd::PlatformExtension &extension);
128 
129  static const gd::String &
130  GetEntityIconUrl(const gd::PlatformExtension &extension,
131  const gd::AbstractEventsBasedEntity &eventsBasedEntity);
132 
136  static void DeclareExtensionDependencies(
137  gd::PlatformExtension &extension,
138  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
139 
144  static void DeclarePropertyInstructionAndExpression(
145  gd::PlatformExtension &extension,
146  gd::InstructionOrExpressionContainerMetadata &entityMetadata,
147  const gd::AbstractEventsBasedEntity &eventsBasedEntity,
148  const gd::NamedPropertyDescriptor &property,
149  const gd::String &propertyLabel, const gd::String &expressionName,
150  const gd::String &conditionName, const gd::String &actionName,
151  const gd::String &toggleActionName, const gd::String &setterName,
152  const gd::String &getterName, const gd::String &toggleFunctionName,
153  const int valueParameterIndex,
154  std::function<gd::AbstractFunctionMetadata &(
155  gd::AbstractFunctionMetadata &instructionOrExpression)>
156  addObjectAndBehaviorParameters,
157  bool isSharedProperty);
158 
165  static void DeclareBehaviorPropertiesInstructionAndExpressions(
166  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
167  const gd::EventsBasedBehavior &eventsBasedBehavior);
168 
175  static void DeclareObjectPropertiesInstructionAndExpressions(
176  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
177  const gd::EventsBasedObject &eventsBasedObject);
178 
185  static void DeclareObjectInternalInstructions(
186  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
187  const gd::EventsBasedObject &eventsBasedObject);
188 
189  static const gd::String defaultExtensionIconPath;
190 
195  static gd::BehaviorMetadata &
196  DeclareBehaviorMetadata(const gd::Project &project,
197  gd::PlatformExtension &extension,
198  const gd::EventsBasedBehavior &eventsBasedBehavior);
199 
204  static gd::ObjectMetadata &
205  DeclareObjectMetadata(gd::PlatformExtension &extension,
206  const gd::EventsBasedObject &eventsBasedObject);
207 
208  static void
209  AddParameter(gd::AbstractFunctionMetadata &instructionOrExpression,
210  const gd::ParameterMetadata &parameter);
211 
216  gd::AbstractFunctionMetadata &DeclareInstructionOrExpressionMetadata(
217  gd::PlatformExtension &extension,
218  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
219  const gd::EventsFunction &eventsFunction);
220 
225  gd::AbstractFunctionMetadata &DeclareExpressionMetadata(
226  gd::PlatformExtension &extension,
227  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
228  const gd::EventsFunction &eventsFunction);
229 
234  static gd::InstructionMetadata &DeclareInstructionMetadata(
235  gd::PlatformExtension &extension,
236  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
237  const gd::EventsFunction &eventsFunction);
238 
243  gd::AbstractFunctionMetadata &DeclareBehaviorInstructionOrExpressionMetadata(
244  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
245  const gd::EventsBasedBehavior &eventsBasedBehavior,
246  const gd::EventsFunction &eventsFunction,
247  std::map<gd::String, gd::String> &objectMethodMangledNames);
248 
253  gd::AbstractFunctionMetadata &DeclareBehaviorExpressionMetadata(
254  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
255  const gd::EventsBasedBehavior &eventsBasedBehavior,
256  const gd::EventsFunction &eventsFunction);
257 
262  static gd::InstructionMetadata &DeclareBehaviorInstructionMetadata(
263  gd::PlatformExtension &extension, gd::BehaviorMetadata &behaviorMetadata,
264  const gd::EventsBasedBehavior &eventsBasedBehavior,
265  const gd::EventsFunction &eventsFunction);
266 
271  gd::AbstractFunctionMetadata &DeclareObjectInstructionOrExpressionMetadata(
272  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
273  const gd::EventsBasedObject &eventsBasedObject,
274  const gd::EventsFunction &eventsFunction,
275  std::map<gd::String, gd::String> &objectMethodMangledNames);
276 
281  gd::AbstractFunctionMetadata &DeclareObjectExpressionMetadata(
282  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
283  const gd::EventsBasedObject &eventsBasedObject,
284  const gd::EventsFunction &eventsFunction);
285 
290  static gd::InstructionMetadata &DeclareObjectInstructionMetadata(
291  gd::PlatformExtension &extension, gd::ObjectMetadata &objectMetadata,
292  const gd::EventsBasedObject &eventsBasedObject,
293  const gd::EventsFunction &eventsFunction);
294 
299  static void DeclareEventsFunctionParameters(
300  const gd::EventsFunctionsContainer &eventsFunctionsContainer,
301  const gd::EventsFunction &eventsFunction,
302  gd::ExpressionMetadata &expression,
303  const int userDefinedFirstParameterIndex);
304 
309  static void DeclareEventsFunctionParameters(
310  const gd::EventsFunctionsContainer &eventsFunctionsContainer,
311  const gd::EventsFunction &eventsFunction,
312  gd::InstructionMetadata &instruction,
313  const int userDefinedFirstParameterIndex);
314 
319  static void DeclareEventsFunctionParameters(
320  const gd::EventsFunctionsContainer &eventsFunctionsContainer,
321  const gd::EventsFunction &eventsFunction,
322  gd::MultipleInstructionMetadata &multipleInstructionMetadata,
323  const int userDefinedFirstParameterIndex);
324 
325  static void
326  UpdateCustomObjectDefaultBehaviors(gd::Project &project,
327  const gd::ObjectMetadata &objectMetadata);
328 
329  static gd::String RemoveTrailingDot(const gd::String &description);
330 
331  static gd::String
332  GetStringifiedExtraInfo(const gd::PropertyDescriptor &property);
333 
334  static gd::String UncapitalizeFirstLetter(const gd::String &string);
335 
336  static gd::String GetFullName(const gd::EventsFunction &eventsFunction);
337  static gd::String GetDefaultSentence(const gd::EventsFunction &eventsFunction,
338  const int firstParameterIndex,
339  const int parameterIndexOffset);
340  static gd::String
341  GetFreeFunctionSentence(const gd::EventsFunction &eventsFunction);
342  static gd::String
343  GetBehaviorFunctionSentence(const gd::EventsFunction &eventsFunction,
344  const bool excludeObjectParameter = false);
345  static gd::String
346  GetObjectFunctionSentence(const gd::EventsFunction &eventsFunction,
347  const bool excludeObjectParameter = false);
348 
349  std::vector<gd::MultipleInstructionMetadata> expressionAndConditions;
350 };
351 
352 } // 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:425
static gd::String GetBehaviorFunctionCodeNamespace(const gd::EventsBasedBehavior &eventsBasedBehavior, const gd::String &codeNamespacePrefix)
Definition: MetadataDeclarationHelper.cpp:1591
static gd::String GetFreeFunctionCodeName(const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsFunction &eventsFunction)
Definition: MetadataDeclarationHelper.cpp:1581
static gd::String GetExtensionCodeNamespacePrefix(const gd::EventsFunctionsExtension &eventsFunctionsExtension)
Definition: MetadataDeclarationHelper.cpp:1567
static bool IsObjectLifecycleEventsFunction(const gd::String &functionName)
Definition: MetadataDeclarationHelper.cpp:414
static gd::String GetObjectFunctionCodeNamespace(const gd::EventsBasedObject &eventsBasedObject, const gd::String &codeNamespacePrefix)
Definition: MetadataDeclarationHelper.cpp:1599
static bool IsBehaviorLifecycleEventsFunction(const gd::String &functionName)
Definition: MetadataDeclarationHelper.cpp:400
static gd::String GetFreeFunctionCodeNamespace(const gd::EventsFunction &eventsFunction, const gd::String &codeNamespacePrefix)
Definition: MetadataDeclarationHelper.cpp:1574