GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
EventsFunctionsExtension.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <vector>
9 
10 #include "GDCore/Extensions/Metadata/DependencyMetadata.h"
11 #include "GDCore/Extensions/Metadata/SourceFileMetadata.h"
12 #include "GDCore/Project/EventsBasedBehavior.h"
13 #include "GDCore/Project/EventsBasedObject.h"
14 #include "GDCore/Project/EventsFunctionsContainer.h"
15 #include "GDCore/Project/EventsFunctionsExtensionChangelog.h"
16 #include "GDCore/Project/VariablesContainer.h"
17 #include "GDCore/String.h"
18 #include "GDCore/Tools/SerializableWithNameList.h"
19 
20 namespace gd {
21 class SerializerElement;
22 class Project;
23 } // namespace gd
24 
25 namespace gd {
26 // TODO Remove the EventsFunctionsContainer inheritance and make it an attribute.
27 // This will allow to get EventsFunctionsContainer the same way for extensions,
28 // objects and behaviors.
41 class GD_CORE_API EventsFunctionsExtension {
42  public:
46  virtual ~EventsFunctionsExtension(){};
47 
53  return new EventsFunctionsExtension(*this);
54  };
55 
56  const gd::String& GetVersion() const { return version; };
57  EventsFunctionsExtension& SetVersion(const gd::String& version_) {
58  version = version_;
59  return *this;
60  }
61 
62  const gd::String& GetNamespace() const { return extensionNamespace; };
63  EventsFunctionsExtension& SetNamespace(const gd::String& namespace_) {
64  extensionNamespace = namespace_;
65  return *this;
66  }
67 
68  const gd::String& GetShortDescription() const { return shortDescription; };
69  EventsFunctionsExtension& SetShortDescription(
70  const gd::String& shortDescription_) {
71  shortDescription = shortDescription_;
72  return *this;
73  }
74 
75  const gd::String& GetDescription() const { return description; };
76  EventsFunctionsExtension& SetDescription(const gd::String& description_) {
77  description = description_;
78  return *this;
79  }
80 
81  const gd::String& GetDimension() const { return dimension; };
82  EventsFunctionsExtension& SetDimension(const gd::String& dimension_) {
83  dimension = dimension_;
84  return *this;
85  }
86 
87  const gd::String& GetName() const { return name; };
88  EventsFunctionsExtension& SetName(const gd::String& name_) {
89  name = name_;
90  return *this;
91  }
92 
93  const gd::String& GetFullName() const { return fullName; };
94  EventsFunctionsExtension& SetFullName(const gd::String& fullName_) {
95  fullName = fullName_;
96  return *this;
97  }
98 
99  const gd::String& GetCategory() const { return category; };
100  EventsFunctionsExtension& SetCategory(const gd::String& category_) {
101  category = category_;
102  return *this;
103  }
104 
105  const std::vector<gd::String>& GetTags() const { return tags; };
106  std::vector<gd::String>& GetTags() { return tags; };
107 
108  const std::vector<gd::String>& GetAuthorIds() const { return authorIds; };
109  std::vector<gd::String>& GetAuthorIds() { return authorIds; };
110 
111  const gd::String& GetAuthor() const { return author; };
112  EventsFunctionsExtension& SetAuthor(const gd::String& author_) {
113  author = author_;
114  return *this;
115  }
116 
117  const gd::String& GetPreviewIconUrl() const { return previewIconUrl; };
118  EventsFunctionsExtension& SetPreviewIconUrl(
119  const gd::String& previewIconUrl_) {
120  previewIconUrl = previewIconUrl_;
121  return *this;
122  }
123 
124  const gd::String& GetIconUrl() const { return iconUrl; };
125  EventsFunctionsExtension& SetIconUrl(const gd::String& iconUrl_) {
126  iconUrl = iconUrl_;
127  return *this;
128  }
129 
134  const gd::String& GetHelpPath() const { return helpPath; };
135 
141  helpPath = helpPath_;
142  return *this;
143  }
144 
148  const gd::String& GetGDevelopVersion() const { return gdevelopVersion; };
149 
154  gdevelopVersion = gdevelopVersion_;
155  return *this;
156  }
157 
162  return eventsBasedBehaviors;
163  }
164 
170  return eventsBasedBehaviors;
171  }
172 
177  return eventsBasedObjects;
178  }
179 
185  return eventsBasedObjects;
186  }
187 
194  virtual void SetOrigin(const gd::String& originName_,
195  const gd::String& originIdentifier_) {
196  originName = originName_;
197  originIdentifier = originIdentifier_;
198  }
199 
200  virtual const gd::String& GetOriginName() const { return originName; }
201  virtual const gd::String& GetOriginIdentifier() const {
202  return originIdentifier;
203  }
204 
209  return eventsFunctionsContainer;
210  }
211 
217  return eventsFunctionsContainer;
218  }
219 
223 
228  gd::DependencyMetadata dependency;
229  dependencies.push_back(dependency);
230  return dependencies.back();
231  };
232 
236  void RemoveDependencyAt(size_t index) {
237  dependencies.erase(dependencies.begin() + index);
238  };
239 
243  std::vector<gd::DependencyMetadata>& GetAllDependencies() {
244  return dependencies;
245  };
246 
250  const std::vector<gd::DependencyMetadata>& GetAllDependencies() const {
251  return dependencies;
252  };
253 
255 
260 
266  return globalVariables;
267  }
268 
273  inline gd::VariablesContainer& GetGlobalVariables() { return globalVariables; }
274 
280  return sceneVariables;
281  }
282 
287  inline gd::VariablesContainer& GetSceneVariables() { return sceneVariables; }
288 
290 
294 
297  void SerializeTo(gd::SerializerElement& element, bool isExternal = false) const;
298 
303  SerializeTo(element, true);
304  }
305 
309  void UnserializeFrom(gd::Project& project,
310  const gd::SerializerElement& element);
311 
316  void UnserializeExtensionDeclarationFrom(
317  gd::Project& project,
318  const gd::SerializerElement& element);
319 
324  void UnserializeExtensionImplementationFrom(
325  gd::Project& project,
326  const gd::SerializerElement& element);
328 
332  static bool IsExtensionLifecycleEventsFunction(
333  const gd::String& eventsFunctionName);
335 
339 
344  gd::SourceFileMetadata sourceFile;
345  sourceFiles.push_back(sourceFile);
346  return sourceFiles.back();
347  };
348 
352  void RemoveSourceFileAt(size_t index) {
353  sourceFiles.erase(sourceFiles.begin() + index);
354  };
355 
359  std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() {
360  return sourceFiles;
361  };
362 
366  const std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() const {
367  return sourceFiles;
368  };
369 
371 
372  private:
377  void Init(const gd::EventsFunctionsExtension& other);
378 
379  void SerializeDependencyTo(const gd::DependencyMetadata& dependency,
380  gd::SerializerElement& serializer) const {
381  serializer.SetStringAttribute("type", dependency.GetDependencyType());
382  serializer.SetStringAttribute("exportName", dependency.GetExportName());
383  serializer.SetStringAttribute("name", dependency.GetName());
384  serializer.SetStringAttribute("version", dependency.GetVersion());
385  }
386 
387  gd::DependencyMetadata UnserializeDependencyFrom(
388  gd::SerializerElement& serializer) {
389  gd::DependencyMetadata dependency;
390  dependency.SetDependencyType(serializer.GetStringAttribute("type"));
391  dependency.SetExportName(serializer.GetStringAttribute("exportName"));
392  dependency.SetName(serializer.GetStringAttribute("name"));
393  dependency.SetVersion(serializer.GetStringAttribute("version"));
394  return dependency;
395  }
396 
397  std::vector<gd::String> GetUnserializingOrderEventsBasedObjectNames(
398  const gd::SerializerElement &eventsBasedObjectsElement);
399 
400  gd::String version;
401  gd::String extensionNamespace;
402  gd::String shortDescription;
403  gd::String description;
404  gd::String dimension;
405  gd::String name;
406  gd::String fullName;
407  gd::String category;
408  std::vector<gd::String> tags;
409  std::vector<gd::String> authorIds;
410  gd::String author;
411  gd::String previewIconUrl;
412  gd::String originName;
413  gd::String originIdentifier;
414  gd::String iconUrl;
415  gd::String helpPath;
417  gd::String gdevelopVersion;
421  std::vector<gd::DependencyMetadata> dependencies;
422  std::vector<gd::SourceFileMetadata> sourceFiles;
423 
424  gd::EventsFunctionsContainer eventsFunctionsContainer;
425  gd::VariablesContainer globalVariables;
426  gd::VariablesContainer sceneVariables;
427 };
428 
429 } // namespace gd
Contains information about a dependency (library, npm/cordova package, or other according to the expo...
Definition: DependencyMetadata.h:20
DependencyMetadata & SetVersion(const gd::String &version_)
Set the version of the dependency to install. Use an empty string to use the latest version.
Definition: DependencyMetadata.h:59
DependencyMetadata & SetName(const gd::String &name_)
Sets the name shown to users.
Definition: DependencyMetadata.h:33
DependencyMetadata & SetDependencyType(const gd::String &dependencyType_)
Sets the type of dependency (what will be used to install it)
Definition: DependencyMetadata.h:69
Used as a base class for classes that will own events-backed functions.
Definition: EventsFunctionsContainer.h:27
The changelog of an extension (only the breaking changes).
Definition: EventsFunctionsExtensionChangelog.h:66
Hold a list of Events Functions (gd::EventsFunction) and Events Based Behaviors.
Definition: EventsFunctionsExtension.h:41
void SerializeToExternal(gd::SerializerElement &element) const
Serialize the EventsFunctionsExtension to the specified element.
Definition: EventsFunctionsExtension.h:302
gd::DependencyMetadata & AddDependency()
Adds a new dependency.
Definition: EventsFunctionsExtension.h:227
const std::vector< gd::DependencyMetadata > & GetAllDependencies() const
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:250
const gd::String & GetHelpPath() const
Get the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:134
void RemoveSourceFileAt(size_t index)
Removes a source file.
Definition: EventsFunctionsExtension.h:352
virtual void SetOrigin(const gd::String &originName_, const gd::String &originIdentifier_)
Sets an extension origin. This method is not present since the beginning so the projects created befo...
Definition: EventsFunctionsExtension.h:194
const EventsFunctionsContainer & GetEventsFunctions() const
Return a const reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:216
gd::VariablesContainer & GetGlobalVariables()
Definition: EventsFunctionsExtension.h:273
gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects()
Return a reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:176
void RemoveDependencyAt(size_t index)
Adds a new dependency.
Definition: EventsFunctionsExtension.h:236
EventsFunctionsExtension & SetGDevelopVersion(const gd::String &gdevelopVersion_)
Set the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:153
const gd::VariablesContainer & GetSceneVariables() const
Definition: EventsFunctionsExtension.h:279
std::vector< gd::DependencyMetadata > & GetAllDependencies()
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:243
gd::SourceFileMetadata & AddSourceFile()
Adds a new source file.
Definition: EventsFunctionsExtension.h:343
const gd::String & GetGDevelopVersion() const
Get the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:148
const gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors() const
Return a const reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:169
const gd::VariablesContainer & GetGlobalVariables() const
Definition: EventsFunctionsExtension.h:265
const std::vector< gd::SourceFileMetadata > & GetAllSourceFiles() const
Returns the list of source files.
Definition: EventsFunctionsExtension.h:366
gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors()
Return a reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:161
gd::VariablesContainer & GetSceneVariables()
Definition: EventsFunctionsExtension.h:287
std::vector< gd::SourceFileMetadata > & GetAllSourceFiles()
Returns the list of source files.
Definition: EventsFunctionsExtension.h:359
EventsFunctionsExtension & SetHelpPath(const gd::String &helpPath_)
Set the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:140
EventsFunctionsContainer & GetEventsFunctions()
Return a reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:208
EventsFunctionsExtension * Clone() const
Return a pointer to a new EventsFunctionsExtension constructed from this one.
Definition: EventsFunctionsExtension.h:52
const gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects() const
Return a const reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:184
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
A class template that store a list of elements that can be accessed by their names and serialized.
Definition: SerializableWithNameList.h:33
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
SerializerElement & SetStringAttribute(const gd::String &name, const gd::String &value)
Set the string value of an attribute of the element.
Definition: SerializerElement.h:234
gd::String GetStringAttribute(const gd::String &name, gd::String defaultValue="", gd::String deprecatedName="") const
Definition: SerializerElement.cpp:95
Contains information about a source file that must be included when an extension is used.
Definition: SourceFileMetadata.h:15
String represents an UTF8 encoded string.
Definition: String.h:33
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:28
Definition: CommonTools.h:24