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& GetName() const { return name; };
82  EventsFunctionsExtension& SetName(const gd::String& name_) {
83  name = name_;
84  return *this;
85  }
86 
87  const gd::String& GetFullName() const { return fullName; };
88  EventsFunctionsExtension& SetFullName(const gd::String& fullName_) {
89  fullName = fullName_;
90  return *this;
91  }
92 
93  const gd::String& GetCategory() const { return category; };
94  EventsFunctionsExtension& SetCategory(const gd::String& category_) {
95  category = category_;
96  return *this;
97  }
98 
99  const std::vector<gd::String>& GetTags() const { return tags; };
100  std::vector<gd::String>& GetTags() { return tags; };
101 
102  const std::vector<gd::String>& GetAuthorIds() const { return authorIds; };
103  std::vector<gd::String>& GetAuthorIds() { return authorIds; };
104 
105  const gd::String& GetAuthor() const { return author; };
106  EventsFunctionsExtension& SetAuthor(const gd::String& author_) {
107  author = author_;
108  return *this;
109  }
110 
111  const gd::String& GetPreviewIconUrl() const { return previewIconUrl; };
112  EventsFunctionsExtension& SetPreviewIconUrl(
113  const gd::String& previewIconUrl_) {
114  previewIconUrl = previewIconUrl_;
115  return *this;
116  }
117 
118  const gd::String& GetIconUrl() const { return iconUrl; };
119  EventsFunctionsExtension& SetIconUrl(const gd::String& iconUrl_) {
120  iconUrl = iconUrl_;
121  return *this;
122  }
123 
128  const gd::String& GetHelpPath() const { return helpPath; };
129 
135  helpPath = helpPath_;
136  return *this;
137  }
138 
142  const gd::String& GetGDevelopVersion() const { return gdevelopVersion; };
143 
148  gdevelopVersion = gdevelopVersion_;
149  return *this;
150  }
151 
156  return eventsBasedBehaviors;
157  }
158 
164  return eventsBasedBehaviors;
165  }
166 
171  return eventsBasedObjects;
172  }
173 
179  return eventsBasedObjects;
180  }
181 
188  virtual void SetOrigin(const gd::String& originName_,
189  const gd::String& originIdentifier_) {
190  originName = originName_;
191  originIdentifier = originIdentifier_;
192  }
193 
194  virtual const gd::String& GetOriginName() const { return originName; }
195  virtual const gd::String& GetOriginIdentifier() const {
196  return originIdentifier;
197  }
198 
203  return eventsFunctionsContainer;
204  }
205 
211  return eventsFunctionsContainer;
212  }
213 
217 
222  gd::DependencyMetadata dependency;
223  dependencies.push_back(dependency);
224  return dependencies.back();
225  };
226 
230  void RemoveDependencyAt(size_t index) {
231  dependencies.erase(dependencies.begin() + index);
232  };
233 
237  std::vector<gd::DependencyMetadata>& GetAllDependencies() {
238  return dependencies;
239  };
240 
244  const std::vector<gd::DependencyMetadata>& GetAllDependencies() const {
245  return dependencies;
246  };
247 
249 
254 
260  return globalVariables;
261  }
262 
267  inline gd::VariablesContainer& GetGlobalVariables() { return globalVariables; }
268 
274  return sceneVariables;
275  }
276 
281  inline gd::VariablesContainer& GetSceneVariables() { return sceneVariables; }
282 
284 
288 
291  void SerializeTo(gd::SerializerElement& element, bool isExternal = false) const;
292 
297  SerializeTo(element, true);
298  }
299 
303  void UnserializeFrom(gd::Project& project,
304  const gd::SerializerElement& element);
305 
310  void UnserializeExtensionDeclarationFrom(
311  gd::Project& project,
312  const gd::SerializerElement& element);
313 
318  void UnserializeExtensionImplementationFrom(
319  gd::Project& project,
320  const gd::SerializerElement& element);
322 
326  static bool IsExtensionLifecycleEventsFunction(
327  const gd::String& eventsFunctionName);
329 
333 
338  gd::SourceFileMetadata sourceFile;
339  sourceFiles.push_back(sourceFile);
340  return sourceFiles.back();
341  };
342 
346  void RemoveSourceFileAt(size_t index) {
347  sourceFiles.erase(sourceFiles.begin() + index);
348  };
349 
353  std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() {
354  return sourceFiles;
355  };
356 
360  const std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() const {
361  return sourceFiles;
362  };
363 
365 
366  private:
371  void Init(const gd::EventsFunctionsExtension& other);
372 
373  void SerializeDependencyTo(const gd::DependencyMetadata& dependency,
374  gd::SerializerElement& serializer) const {
375  serializer.SetStringAttribute("type", dependency.GetDependencyType());
376  serializer.SetStringAttribute("exportName", dependency.GetExportName());
377  serializer.SetStringAttribute("name", dependency.GetName());
378  serializer.SetStringAttribute("version", dependency.GetVersion());
379  }
380 
381  gd::DependencyMetadata UnserializeDependencyFrom(
382  gd::SerializerElement& serializer) {
383  gd::DependencyMetadata dependency;
384  dependency.SetDependencyType(serializer.GetStringAttribute("type"));
385  dependency.SetExportName(serializer.GetStringAttribute("exportName"));
386  dependency.SetName(serializer.GetStringAttribute("name"));
387  dependency.SetVersion(serializer.GetStringAttribute("version"));
388  return dependency;
389  }
390 
391  std::vector<gd::String> GetUnserializingOrderEventsBasedObjectNames(
392  const gd::SerializerElement &eventsBasedObjectsElement);
393 
394  gd::String version;
395  gd::String extensionNamespace;
396  gd::String shortDescription;
397  gd::String description;
398  gd::String name;
399  gd::String fullName;
400  gd::String category;
401  std::vector<gd::String> tags;
402  std::vector<gd::String> authorIds;
403  gd::String author;
404  gd::String previewIconUrl;
405  gd::String originName;
406  gd::String originIdentifier;
407  gd::String iconUrl;
408  gd::String helpPath;
410  gd::String gdevelopVersion;
414  std::vector<gd::DependencyMetadata> dependencies;
415  std::vector<gd::SourceFileMetadata> sourceFiles;
416 
417  gd::EventsFunctionsContainer eventsFunctionsContainer;
418  gd::VariablesContainer globalVariables;
419  gd::VariablesContainer sceneVariables;
420 };
421 
422 } // 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:296
gd::DependencyMetadata & AddDependency()
Adds a new dependency.
Definition: EventsFunctionsExtension.h:221
const std::vector< gd::DependencyMetadata > & GetAllDependencies() const
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:244
const gd::String & GetHelpPath() const
Get the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:128
void RemoveSourceFileAt(size_t index)
Removes a source file.
Definition: EventsFunctionsExtension.h:346
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:188
const EventsFunctionsContainer & GetEventsFunctions() const
Return a const reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:210
gd::VariablesContainer & GetGlobalVariables()
Definition: EventsFunctionsExtension.h:267
gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects()
Return a reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:170
void RemoveDependencyAt(size_t index)
Adds a new dependency.
Definition: EventsFunctionsExtension.h:230
EventsFunctionsExtension & SetGDevelopVersion(const gd::String &gdevelopVersion_)
Set the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:147
const gd::VariablesContainer & GetSceneVariables() const
Definition: EventsFunctionsExtension.h:273
std::vector< gd::DependencyMetadata > & GetAllDependencies()
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:237
gd::SourceFileMetadata & AddSourceFile()
Adds a new source file.
Definition: EventsFunctionsExtension.h:337
const gd::String & GetGDevelopVersion() const
Get the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:142
const gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors() const
Return a const reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:163
const gd::VariablesContainer & GetGlobalVariables() const
Definition: EventsFunctionsExtension.h:259
const std::vector< gd::SourceFileMetadata > & GetAllSourceFiles() const
Returns the list of source files.
Definition: EventsFunctionsExtension.h:360
gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors()
Return a reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:155
gd::VariablesContainer & GetSceneVariables()
Definition: EventsFunctionsExtension.h:281
std::vector< gd::SourceFileMetadata > & GetAllSourceFiles()
Returns the list of source files.
Definition: EventsFunctionsExtension.h:353
EventsFunctionsExtension & SetHelpPath(const gd::String &helpPath_)
Set the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:134
EventsFunctionsContainer & GetEventsFunctions()
Return a reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:202
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:178
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:83
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