GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
PlatformExtension.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. Copyright 2016 Victor Levasseur ([email protected]) This
5  * project is released under the MIT License.
6  */
7 
8 #pragma once
9 #include <map>
10 #include <memory>
11 #include <vector>
12 
13 #include "GDCore/CommonTools.h"
14 #include "GDCore/Extensions/Metadata/BehaviorMetadata.h"
15 #include "GDCore/Extensions/Metadata/DependencyMetadata.h"
16 #include "GDCore/Extensions/Metadata/EffectMetadata.h"
17 #include "GDCore/Extensions/Metadata/EventMetadata.h"
18 #include "GDCore/Extensions/Metadata/InstructionOrExpressionGroupMetadata.h"
19 #include "GDCore/Extensions/Metadata/ObjectMetadata.h"
20 #include "GDCore/Project/PropertyDescriptor.h"
21 #include "GDCore/String.h"
22 #include "GDCore/Tools/VersionPriv.h"
23 
24 namespace gd {
25 class Instruction;
26 class InstructionMetadata;
27 class MultipleInstructionMetadata;
28 class ExpressionMetadata;
29 class ObjectMetadata;
30 class BehaviorMetadata;
31 class EffectMetadata;
32 class DependencyMetadata;
33 class BaseEvent;
34 class EventMetadata;
35 class EventCodeGenerator;
36 class ArbitraryResourceWorker;
37 class BehaviorsSharedData;
38 class Behavior;
39 class Object;
40 class ObjectConfiguration;
41 } // namespace gd
42 
43 typedef std::function<std::unique_ptr<gd::ObjectConfiguration>()> CreateFunPtr;
44 
45 namespace gd {
46 
51 class GD_CORE_API CompilationInfo {
52  public:
53  CompilationInfo() {};
54  virtual ~CompilationInfo() {};
55 
56  bool informationCompleted = false;
57 
58  bool runtimeOnly = false;
60 
61 #if defined(__GNUC__)
62  int gccMajorVersion = 0;
63  int gccMinorVersion = 0;
64  int gccPatchLevel = 0;
65 #endif
66 
67  int sfmlMajorVersion = 0;
68  int sfmlMinorVersion = 0;
69 
70  gd::String gdCoreVersion;
71  int sizeOfpInt = 0;
72 };
73 
74 struct GD_CORE_API DuplicatedInstructionOptions {
75  bool unscoped;
76 };
77 
83 class GD_CORE_API PlatformExtension {
84  public:
85  CompilationInfo compilationInfo;
86 
88  virtual ~PlatformExtension();
89 
94 
98  PlatformExtension& SetExtensionInformation(const gd::String& name_,
99  const gd::String& fullname_,
100  const gd::String& description_,
101  const gd::String& author_,
102  const gd::String& license_);
103 
108  iconUrl = iconUrl_;
109  return *this;
110  }
111 
116  category = category_;
117  return *this;
118  }
119 
129  helpPath = helpPath_;
130  return *this;
131  }
132 
137  void MarkAsDeprecated() { deprecated = true; }
138 
140 
145 
149  gd::InstructionMetadata& AddCondition(const gd::String& name_,
150  const gd::String& fullname_,
151  const gd::String& description_,
152  const gd::String& sentence_,
153  const gd::String& group_,
154  const gd::String& icon_,
155  const gd::String& smallicon_);
156 
160  gd::InstructionMetadata& AddAction(const gd::String& name_,
161  const gd::String& fullname_,
162  const gd::String& description_,
163  const gd::String& sentence_,
164  const gd::String& group_,
165  const gd::String& icon_,
166  const gd::String& smallicon_);
170  gd::ExpressionMetadata& AddExpression(const gd::String& name_,
171  const gd::String& fullname_,
172  const gd::String& description_,
173  const gd::String& group_,
174  const gd::String& smallicon_);
178  gd::ExpressionMetadata& AddStrExpression(const gd::String& name_,
179  const gd::String& fullname_,
180  const gd::String& description_,
181  const gd::String& group_,
182  const gd::String& smallicon_);
183 
190  gd::MultipleInstructionMetadata AddExpressionAndCondition(
191  const gd::String& type,
192  const gd::String& name,
193  const gd::String& fullname,
194  const gd::String& description,
195  const gd::String& sentenceName,
196  const gd::String& group,
197  const gd::String& icon);
198 
207  gd::MultipleInstructionMetadata AddExpressionAndConditionAndAction(
208  const gd::String& type,
209  const gd::String& name,
210  const gd::String& fullname,
211  const gd::String& description,
212  const gd::String& sentenceName,
213  const gd::String& group,
214  const gd::String& icon);
215 
216  gd::DependencyMetadata& AddDependency();
217 
226  template <class T>
227  gd::ObjectMetadata& AddObject(const gd::String& name_,
228  const gd::String& fullname_,
229  const gd::String& description_,
230  const gd::String& icon_);
231 
241  gd::ObjectMetadata& AddObject(
242  const gd::String& name_,
243  const gd::String& fullname_,
244  const gd::String& description_,
245  const gd::String& icon_,
246  std::shared_ptr<gd::ObjectConfiguration> instance);
247 
256  gd::ObjectMetadata& AddEventsBasedObject(const gd::String& name_,
257  const gd::String& fullname_,
258  const gd::String& description_,
259  const gd::String& icon_);
260 
276  gd::BehaviorMetadata& AddBehavior(
277  const gd::String& name_,
278  const gd::String& fullname_,
279  const gd::String& defaultName_,
280  const gd::String& description_,
281  const gd::String& group_,
282  const gd::String& icon_,
283  const gd::String& className_,
284  std::shared_ptr<gd::Behavior> instance,
285  std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance);
286 
291  gd::EffectMetadata& AddEffect(const gd::String& name_);
292 
296  gd::EventMetadata& AddEvent(const gd::String& name_,
297  const gd::String& fullname_,
298  const gd::String& description_,
299  const gd::String& group_,
300  const gd::String& smallicon_,
301  std::shared_ptr<gd::BaseEvent> instance);
302 
309  gd::InstructionMetadata& AddDuplicatedAction(
310  const gd::String& newActionName, const gd::String& copiedActionName);
317  gd::InstructionMetadata& AddDuplicatedCondition(
318  const gd::String& newConditionName,
319  const gd::String& copiedConditionName,
320  gd::DuplicatedInstructionOptions options = {.unscoped = false});
327  gd::ExpressionMetadata& AddDuplicatedExpression(
328  const gd::String& newExpressionName,
329  const gd::String& copiedExpressionName);
337  gd::ExpressionMetadata& AddDuplicatedStrExpression(
338  const gd::String& newExpressionName,
339  const gd::String& copiedExpressionName);
340 
345  return extensionPropertiesMetadata[name];
346  };
347 
353  const gd::String& name) {
354  return instructionOrExpressionGroupMetadata[name];
355  }
356 
361  void StripUnimplementedInstructionsAndExpressions();
363 
368 
372  const gd::String& GetFullName() const { return fullname; }
373 
377  const gd::String& GetName() const { return name; }
378 
382  const gd::String& GetCategory() const { return category; }
383 
387  const gd::String& GetDescription() const { return informations; }
388 
392  const gd::String& GetAuthor() const { return author; }
393 
397  const gd::String& GetLicense() const { return license; }
398 
403  const gd::String& GetHelpPath() const { return helpPath; }
404 
409  const gd::String& GetIconUrl() const { return iconUrl; }
410 
414  const std::vector<gd::String>& GetTags() const { return tags; }
415 
420  tags.clear();
421  tags = csvTags.Split(',');
422  for (size_t i = 0; i < tags.size(); i++) {
423  tags[i] = tags[i].Trim().LowerCase();
424  }
425  return *this;
426  }
427 
432  tags.push_back(tag);
433  return *this;
434  }
435 
439  bool IsDeprecated() const { return deprecated; }
440 
445  bool IsBuiltin() const;
446 
452  const gd::String& GetNameSpace() { return nameSpace; };
453 
458  std::vector<gd::String> GetExtensionObjectsTypes() const;
459 
464  std::vector<gd::String> GetBehaviorsTypes() const;
465 
470  CreateFunPtr GetObjectCreationFunctionPtr(const gd::String& objectType) const;
471 
476  std::vector<gd::String> GetExtensionEffectTypes() const;
477 
483  std::shared_ptr<gd::BaseEvent> CreateEvent(const gd::String& eventType) const;
489  gd::Behavior* GetBehavior(const gd::String& behaviorType) const;
490 
497  gd::BehaviorsSharedData* GetBehaviorSharedDatas(
498  const gd::String& behaviorType) const;
499 
504  ObjectMetadata& GetObjectMetadata(const gd::String& objectType);
505 
510  BehaviorMetadata& GetBehaviorMetadata(const gd::String& behaviorType);
511 
516  bool HasBehavior(const gd::String& behaviorType) const;
517 
521  EffectMetadata& GetEffectMetadata(const gd::String& effectName);
522 
526  std::map<gd::String, gd::EventMetadata>& GetAllEvents();
527 
532  std::map<gd::String, gd::InstructionMetadata>& GetAllActions();
533 
537  std::map<gd::String, gd::InstructionMetadata>& GetAllConditions();
538 
542  std::map<gd::String, gd::ExpressionMetadata>& GetAllExpressions();
543 
547  std::map<gd::String, gd::ExpressionMetadata>& GetAllStrExpressions();
548 
553  std::vector<gd::DependencyMetadata>& GetAllDependencies();
554 
559  std::map<gd::String, gd::InstructionMetadata>& GetAllActionsForObject(
560  gd::String objectType);
561 
565  std::map<gd::String, gd::InstructionMetadata>& GetAllConditionsForObject(
566  gd::String objectType);
567 
571  std::map<gd::String, gd::ExpressionMetadata>& GetAllExpressionsForObject(
572  gd::String objectType);
573 
577  std::map<gd::String, gd::ExpressionMetadata>& GetAllStrExpressionsForObject(
578  gd::String objectType);
579 
583  std::map<gd::String, gd::InstructionMetadata>& GetAllActionsForBehavior(
584  gd::String autoType);
585 
589  std::map<gd::String, gd::InstructionMetadata>& GetAllConditionsForBehavior(
590  gd::String autoType);
591 
595  std::map<gd::String, gd::ExpressionMetadata>& GetAllExpressionsForBehavior(
596  gd::String autoType);
597 
601  std::map<gd::String, gd::ExpressionMetadata>& GetAllStrExpressionsForBehavior(
602  gd::String autoType);
603 
609  std::map<gd::String, gd::PropertyDescriptor>& GetAllProperties() {
610  return extensionPropertiesMetadata;
611  }
612 
617  const std::map<gd::String, InstructionOrExpressionGroupMetadata>&
619  return instructionOrExpressionGroupMetadata;
620  }
622 
627  static std::vector<gd::String> GetBuiltinExtensionsNames();
628 
633  static gd::String GetNamespaceSeparator() { return "::"; }
634 
635  static gd::String GetEventsFunctionFullType(const gd::String& extensionName,
636  const gd::String& functionName);
637 
638  static gd::String GetBehaviorEventsFunctionFullType(
639  const gd::String& extensionName,
640  const gd::String& behaviorName,
641  const gd::String& functionName);
642 
643  static gd::String GetBehaviorFullType(const gd::String& extensionName,
644  const gd::String& behaviorName);
645 
646  static gd::String GetObjectEventsFunctionFullType(
647  const gd::String& extensionName,
648  const gd::String& objectName,
649  const gd::String& functionName);
650 
651  static gd::String GetObjectFullType(const gd::String& extensionName,
652  const gd::String& objectName);
653 
654  static gd::String GetExtensionFromFullObjectType(const gd::String& type);
655 
656  static gd::String GetObjectNameFromFullObjectType(const gd::String& type);
657 
658  private:
663  void SetNameSpace(gd::String nameSpace_);
664 
665  gd::String name;
666  gd::String
667  nameSpace;
670  gd::String fullname;
671  gd::String informations;
672  gd::String category;
673  gd::String author;
674  gd::String license;
675  bool deprecated;
677  gd::String helpPath;
679  gd::String iconUrl;
680  std::vector<gd::String> tags;
681 
682  std::map<gd::String, gd::ObjectMetadata> objectsInfos;
683  std::map<gd::String, gd::BehaviorMetadata> behaviorsInfo;
684  std::map<gd::String, gd::EffectMetadata> effectsMetadata;
685  std::map<gd::String, gd::InstructionMetadata> conditionsInfos;
686  std::map<gd::String, gd::InstructionMetadata> actionsInfos;
687  std::map<gd::String, gd::ExpressionMetadata> expressionsInfos;
688  std::map<gd::String, gd::ExpressionMetadata> strExpressionsInfos;
689  std::vector<gd::DependencyMetadata> extensionDependenciesMetadata;
690  std::map<gd::String, gd::EventMetadata> eventsInfos;
691  std::map<gd::String, gd::PropertyDescriptor> extensionPropertiesMetadata;
692  std::map<gd::String, InstructionOrExpressionGroupMetadata>
693  instructionOrExpressionGroupMetadata;
694 
695  ObjectMetadata badObjectMetadata;
696  BehaviorMetadata badBehaviorMetadata;
697  EffectMetadata badEffectMetadata;
698  static std::map<gd::String, gd::InstructionMetadata>
699  badConditionsMetadata;
701  static std::map<gd::String, gd::InstructionMetadata>
702  badActionsMetadata;
704  static std::map<gd::String, gd::ExpressionMetadata>
705  badExpressionsMetadata;
707 };
708 
709 } // namespace gd
710 
714 #define GD_COMPLETE_EXTENSION_COMPILATION_INFORMATION() \
715  compilationInfo.runtimeOnly = false; \
716  compilationInfo.sfmlMajorVersion = 2; \
717  compilationInfo.sfmlMinorVersion = 0; \
718  compilationInfo.gdCoreVersion = GD_VERSION_STRING; \
719  compilationInfo.sizeOfpInt = sizeof(int*); \
720  compilationInfo.gccMajorVersion = __GNUC__; \
721  compilationInfo.gccMinorVersion = __GNUC_MINOR__; \
722  compilationInfo.gccPatchLevel = __GNUC_PATCHLEVEL__; \
723  compilationInfo.informationCompleted = true;
724 
725 #include "GDCore/Extensions/PlatformExtension.inl"
Base class used to represents a behavior that can be applied to an object. It stores the content (i....
Definition: Behavior.h:23
Contains user-friendly information about a behavior type.
Definition: BehaviorMetadata.h:32
Base class for defining data shared by behaviors having the same type and name.
Definition: BehaviorsSharedData.h:24
Class used by gd::PlatformExtension to ensure that an extension is compiled against the right version...
Definition: PlatformExtension.h:51
Contains information about a dependency (library, npm/cordova package, or other according to the expo...
Definition: DependencyMetadata.h:20
Contains user-friendly information about an effect.
Definition: EffectMetadata.h:23
Describe an event provided by an extension of a platform.
Definition: EventMetadata.h:29
Describe user-friendly information about an expression, its parameters and the function name as well ...
Definition: ExpressionMetadata.h:47
Describe user-friendly information about an instruction (action or condition), its parameters and the...
Definition: InstructionMetadata.h:39
Contains information about how to display a group of instructions to the user.
Definition: InstructionOrExpressionGroupMetadata.h:14
A "composite" metadata that can be used to easily declare both an expression and a related condition ...
Definition: MultipleInstructionMetadata.h:24
Contains user-friendly information about an object type, and a function to create a new gd::Object of...
Definition: ObjectMetadata.h:37
Base class for implementing platform's extensions.
Definition: PlatformExtension.h:83
PlatformExtension & AddTag(const gd::String &tag)
Add a keyword that help search engines find this extension.
Definition: PlatformExtension.h:431
gd::PropertyDescriptor & RegisterProperty(const gd::String &name)
Adds a property to the extension.
Definition: PlatformExtension.h:344
const std::map< gd::String, InstructionOrExpressionGroupMetadata > & GetAllInstructionOrExpressionGroupMetadata() const
Get the metadata (icon, etc...) for groups used for instructions or expressions.
Definition: PlatformExtension.h:618
const std::vector< gd::String > & GetTags() const
Return keywords that help search engines find this extension.
Definition: PlatformExtension.h:414
const gd::String & GetNameSpace()
Get the namespace of the extension.
Definition: PlatformExtension.h:452
const gd::String & GetName() const
Return the name of the extension.
Definition: PlatformExtension.h:377
const gd::String & GetCategory() const
Return the category of the extension.
Definition: PlatformExtension.h:382
PlatformExtension & SetTags(const gd::String &csvTags)
Set keywords that help search engines find this extension.
Definition: PlatformExtension.h:419
PlatformExtension & SetCategory(const gd::String &category_)
Set the category of the extension.
Definition: PlatformExtension.h:115
const gd::String & GetLicense() const
Return the name of extension license.
Definition: PlatformExtension.h:397
void MarkAsDeprecated()
Mark this extension as deprecated: the IDE will hide it from the user.
Definition: PlatformExtension.h:137
InstructionOrExpressionGroupMetadata & AddInstructionOrExpressionGroupMetadata(const gd::String &name)
Add some metadata (icon, etc...) for a group used for instructions or expressions.
Definition: PlatformExtension.h:352
PlatformExtension & SetIconUrl(const gd::String &iconUrl_)
Set the URL of the extension icon.
Definition: PlatformExtension.h:107
const gd::String & GetAuthor() const
Return the name of the extension developer.
Definition: PlatformExtension.h:392
bool IsDeprecated() const
Check if the extension is flagged as being deprecated.
Definition: PlatformExtension.h:439
std::map< gd::String, gd::PropertyDescriptor > & GetAllProperties()
Get all the properties of the extension. Properties are shown in the game properties in the editor,...
Definition: PlatformExtension.h:609
const gd::String & GetHelpPath() const
Return the help path of extension, relative to the GDevelop documentation root.
Definition: PlatformExtension.h:403
const gd::String & GetIconUrl() const
Return the URL to the icon to be displayed for this extension.
Definition: PlatformExtension.h:409
const gd::String & GetFullName() const
Return the name extension user friendly name.
Definition: PlatformExtension.h:372
static gd::String GetNamespaceSeparator()
Get the string used to separate the name of the instruction/expression and the extension.
Definition: PlatformExtension.h:633
PlatformExtension & SetExtensionHelpPath(const gd::String &helpPath_)
Set the path to the help, relative to the GDevelop documentation root. For example,...
Definition: PlatformExtension.h:128
const gd::String & GetDescription() const
Return a description of the extension.
Definition: PlatformExtension.h:387
Used to describe a property shown in a property grid.
Definition: PropertyDescriptor.h:25
String represents an UTF8 encoded string.
Definition: String.h:33
std::vector< String > Split(value_type delimiter) const
Split the string with a delimiter.
Definition: String.cpp:358
Definition: CommonTools.h:24
Definition: PlatformExtension.h:74