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/TestsContainer.h"
17 #include "GDCore/Project/VariablesContainer.h"
18 #include "GDCore/String.h"
19 #include "GDCore/Tools/SerializableWithNameList.h"
20 
21 namespace gd {
22 class SerializerElement;
23 class Project;
24 } // namespace gd
25 
26 namespace gd {
27 // TODO Remove the EventsFunctionsContainer inheritance and make it an attribute.
28 // This will allow to get EventsFunctionsContainer the same way for extensions,
29 // objects and behaviors.
42 class GD_CORE_API EventsFunctionsExtension {
43  public:
47  virtual ~EventsFunctionsExtension(){};
48 
54  return new EventsFunctionsExtension(*this);
55  };
56 
57  const gd::String& GetVersion() const { return version; };
58  EventsFunctionsExtension& SetVersion(const gd::String& version_) {
59  version = version_;
60  return *this;
61  }
62 
63  const gd::String& GetNamespace() const { return extensionNamespace; };
64  EventsFunctionsExtension& SetNamespace(const gd::String& namespace_) {
65  extensionNamespace = namespace_;
66  return *this;
67  }
68 
69  const gd::String& GetShortDescription() const { return shortDescription; };
70  EventsFunctionsExtension& SetShortDescription(
71  const gd::String& shortDescription_) {
72  shortDescription = shortDescription_;
73  return *this;
74  }
75 
76  const gd::String& GetDescription() const { return description; };
77  EventsFunctionsExtension& SetDescription(const gd::String& description_) {
78  description = description_;
79  return *this;
80  }
81 
82  const gd::String& GetDimension() const { return dimension; };
83  EventsFunctionsExtension& SetDimension(const gd::String& dimension_) {
84  dimension = dimension_;
85  return *this;
86  }
87 
88  const gd::String& GetName() const { return name; };
89  EventsFunctionsExtension& SetName(const gd::String& name_) {
90  name = name_;
91  return *this;
92  }
93 
94  const gd::String& GetFullName() const { return fullName; };
95  EventsFunctionsExtension& SetFullName(const gd::String& fullName_) {
96  fullName = fullName_;
97  return *this;
98  }
99 
100  const gd::String& GetCategory() const { return category; };
101  EventsFunctionsExtension& SetCategory(const gd::String& category_) {
102  category = category_;
103  return *this;
104  }
105 
106  const std::vector<gd::String>& GetTags() const { return tags; };
107  std::vector<gd::String>& GetTags() { return tags; };
108 
109  const std::vector<gd::String>& GetAuthorIds() const { return authorIds; };
110  std::vector<gd::String>& GetAuthorIds() { return authorIds; };
111 
112  const gd::String& GetAuthor() const { return author; };
113  EventsFunctionsExtension& SetAuthor(const gd::String& author_) {
114  author = author_;
115  return *this;
116  }
117 
118  const gd::String& GetPreviewIconUrl() const { return previewIconUrl; };
119  EventsFunctionsExtension& SetPreviewIconUrl(
120  const gd::String& previewIconUrl_) {
121  previewIconUrl = previewIconUrl_;
122  return *this;
123  }
124 
125  const gd::String& GetIconUrl() const { return iconUrl; };
126  EventsFunctionsExtension& SetIconUrl(const gd::String& iconUrl_) {
127  iconUrl = iconUrl_;
128  return *this;
129  }
130 
135  const gd::String& GetHelpPath() const { return helpPath; };
136 
142  helpPath = helpPath_;
143  return *this;
144  }
145 
149  const gd::String& GetGDevelopVersion() const { return gdevelopVersion; };
150 
155  gdevelopVersion = gdevelopVersion_;
156  return *this;
157  }
158 
163  return eventsBasedBehaviors;
164  }
165 
171  return eventsBasedBehaviors;
172  }
173 
178  return eventsBasedObjects;
179  }
180 
186  return eventsBasedObjects;
187  }
188 
192  gd::TestsContainer& GetTests() { return tests; }
193 
197  const gd::TestsContainer& GetTests() const { return tests; }
198 
205  virtual void SetOrigin(const gd::String& originName_,
206  const gd::String& originIdentifier_) {
207  originName = originName_;
208  originIdentifier = originIdentifier_;
209  }
210 
211  virtual const gd::String& GetOriginName() const { return originName; }
212  virtual const gd::String& GetOriginIdentifier() const {
213  return originIdentifier;
214  }
215 
220  return eventsFunctionsContainer;
221  }
222 
228  return eventsFunctionsContainer;
229  }
230 
234 
239  gd::DependencyMetadata dependency;
240  dependencies.push_back(dependency);
241  return dependencies.back();
242  };
243 
247  void RemoveDependencyAt(size_t index) {
248  dependencies.erase(dependencies.begin() + index);
249  };
250 
254  std::vector<gd::DependencyMetadata>& GetAllDependencies() {
255  return dependencies;
256  };
257 
261  const std::vector<gd::DependencyMetadata>& GetAllDependencies() const {
262  return dependencies;
263  };
264 
266 
271 
277  return globalVariables;
278  }
279 
284  inline gd::VariablesContainer& GetGlobalVariables() { return globalVariables; }
285 
291  return sceneVariables;
292  }
293 
298  inline gd::VariablesContainer& GetSceneVariables() { return sceneVariables; }
299 
301 
305 
308  void SerializeTo(gd::SerializerElement& element, bool isExternal = false) const;
309 
314  SerializeTo(element, true);
315  }
316 
320  void UnserializeFrom(gd::Project& project,
321  const gd::SerializerElement& element);
322 
327  void UnserializeExtensionDeclarationFrom(
328  gd::Project& project,
329  const gd::SerializerElement& element);
330 
334  void UnserializeExtensionDefaultVariantsFrom(gd::Project &project,
335  const SerializerElement &element);
336 
341  void UnserializeExtensionImplementationFrom(
342  gd::Project& project,
343  const gd::SerializerElement& element);
345 
349  static bool IsExtensionLifecycleEventsFunction(
350  const gd::String& eventsFunctionName);
352 
356 
361  gd::SourceFileMetadata sourceFile;
362  sourceFiles.push_back(sourceFile);
363  return sourceFiles.back();
364  };
365 
369  void RemoveSourceFileAt(size_t index) {
370  sourceFiles.erase(sourceFiles.begin() + index);
371  };
372 
376  std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() {
377  return sourceFiles;
378  };
379 
383  const std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() const {
384  return sourceFiles;
385  };
386 
388 
389  private:
394  void Init(const gd::EventsFunctionsExtension& other);
395 
396  void SerializeDependencyTo(const gd::DependencyMetadata& dependency,
397  gd::SerializerElement& serializer) const {
398  serializer.SetStringAttribute("type", dependency.GetDependencyType());
399  serializer.SetStringAttribute("exportName", dependency.GetExportName());
400  serializer.SetStringAttribute("name", dependency.GetName());
401  serializer.SetStringAttribute("version", dependency.GetVersion());
402  }
403 
404  gd::DependencyMetadata UnserializeDependencyFrom(
405  gd::SerializerElement& serializer) {
406  gd::DependencyMetadata dependency;
407  dependency.SetDependencyType(serializer.GetStringAttribute("type"));
408  dependency.SetExportName(serializer.GetStringAttribute("exportName"));
409  dependency.SetName(serializer.GetStringAttribute("name"));
410  dependency.SetVersion(serializer.GetStringAttribute("version"));
411  return dependency;
412  }
413 
414  gd::String version;
415  gd::String extensionNamespace;
416  gd::String shortDescription;
417  gd::String description;
418  gd::String dimension;
419  gd::String name;
420  gd::String fullName;
421  gd::String category;
422  std::vector<gd::String> tags;
423  std::vector<gd::String> authorIds;
424  gd::String author;
425  gd::String previewIconUrl;
426  gd::String originName;
427  gd::String originIdentifier;
428  gd::String iconUrl;
429  gd::String helpPath;
431  gd::String gdevelopVersion;
435  std::vector<gd::DependencyMetadata> dependencies;
436  std::vector<gd::SourceFileMetadata> sourceFiles;
437 
438  gd::EventsFunctionsContainer eventsFunctionsContainer;
439  gd::VariablesContainer globalVariables;
440  gd::VariablesContainer sceneVariables;
441  gd::TestsContainer tests;
442 };
443 
444 } // 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:42
void SerializeToExternal(gd::SerializerElement &element) const
Serialize the EventsFunctionsExtension to the specified element.
Definition: EventsFunctionsExtension.h:313
gd::DependencyMetadata & AddDependency()
Adds a new dependency.
Definition: EventsFunctionsExtension.h:238
const std::vector< gd::DependencyMetadata > & GetAllDependencies() const
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:261
const gd::String & GetHelpPath() const
Get the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:135
void RemoveSourceFileAt(size_t index)
Removes a source file.
Definition: EventsFunctionsExtension.h:369
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:205
const EventsFunctionsContainer & GetEventsFunctions() const
Return a const reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:227
gd::VariablesContainer & GetGlobalVariables()
Definition: EventsFunctionsExtension.h:284
gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects()
Return a reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:177
void RemoveDependencyAt(size_t index)
Adds a new dependency.
Definition: EventsFunctionsExtension.h:247
EventsFunctionsExtension & SetGDevelopVersion(const gd::String &gdevelopVersion_)
Set the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:154
const gd::VariablesContainer & GetSceneVariables() const
Definition: EventsFunctionsExtension.h:290
std::vector< gd::DependencyMetadata > & GetAllDependencies()
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:254
gd::SourceFileMetadata & AddSourceFile()
Adds a new source file.
Definition: EventsFunctionsExtension.h:360
const gd::String & GetGDevelopVersion() const
Get the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:149
const gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors() const
Return a const reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:170
const gd::VariablesContainer & GetGlobalVariables() const
Definition: EventsFunctionsExtension.h:276
const gd::TestsContainer & GetTests() const
Return a const reference to the tests of the extension.
Definition: EventsFunctionsExtension.h:197
gd::TestsContainer & GetTests()
Return a reference to the tests of the extension.
Definition: EventsFunctionsExtension.h:192
const std::vector< gd::SourceFileMetadata > & GetAllSourceFiles() const
Returns the list of source files.
Definition: EventsFunctionsExtension.h:383
gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors()
Return a reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:162
gd::VariablesContainer & GetSceneVariables()
Definition: EventsFunctionsExtension.h:298
std::vector< gd::SourceFileMetadata > & GetAllSourceFiles()
Returns the list of source files.
Definition: EventsFunctionsExtension.h:376
EventsFunctionsExtension & SetHelpPath(const gd::String &helpPath_)
Set the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:141
EventsFunctionsContainer & GetEventsFunctions()
Return a reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:219
EventsFunctionsExtension * Clone() const
Return a pointer to a new EventsFunctionsExtension constructed from this one.
Definition: EventsFunctionsExtension.h:53
const gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects() const
Return a const reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:185
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:52
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
A container of tests (gd::Test), used by gd::Project and gd::EventsFunctionsExtension.
Definition: TestsContainer.h:27
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:29
Definition: CommonTools.h:24