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/Project/EventsBasedBehavior.h"
12 #include "GDCore/Project/EventsBasedObject.h"
13 #include "GDCore/Project/EventsFunctionsContainer.h"
14 #include "GDCore/Project/VariablesContainer.h"
15 #include "GDCore/String.h"
16 #include "GDCore/Tools/SerializableWithNameList.h"
17 namespace gd {
18 class SerializerElement;
19 class Project;
20 } // namespace gd
21 
22 namespace gd {
23 // TODO Remove the EventsFunctionsContainer inheritance and make it an attribute.
24 // This will allow to get EventsFunctionsContainer the same way for extensions,
25 // objects and behaviors.
39  public:
43  virtual ~EventsFunctionsExtension(){};
44 
50  return new EventsFunctionsExtension(*this);
51  };
52 
53  const gd::String& GetVersion() const { return version; };
54  EventsFunctionsExtension& SetVersion(const gd::String& version_) {
55  version = version_;
56  return *this;
57  }
58 
59  const gd::String& GetNamespace() const { return extensionNamespace; };
60  EventsFunctionsExtension& SetNamespace(const gd::String& namespace_) {
61  extensionNamespace = namespace_;
62  return *this;
63  }
64 
65  const gd::String& GetShortDescription() const { return shortDescription; };
66  EventsFunctionsExtension& SetShortDescription(
67  const gd::String& shortDescription_) {
68  shortDescription = shortDescription_;
69  return *this;
70  }
71 
72  const gd::String& GetDescription() const { return description; };
73  EventsFunctionsExtension& SetDescription(const gd::String& description_) {
74  description = description_;
75  return *this;
76  }
77 
78  const gd::String& GetName() const { return name; };
79  EventsFunctionsExtension& SetName(const gd::String& name_) {
80  name = name_;
81  return *this;
82  }
83 
84  const gd::String& GetFullName() const { return fullName; };
85  EventsFunctionsExtension& SetFullName(const gd::String& fullName_) {
86  fullName = fullName_;
87  return *this;
88  }
89 
90  const gd::String& GetCategory() const { return category; };
91  EventsFunctionsExtension& SetCategory(const gd::String& category_) {
92  category = category_;
93  return *this;
94  }
95 
96  const std::vector<gd::String>& GetTags() const { return tags; };
97  std::vector<gd::String>& GetTags() { return tags; };
98 
99  const std::vector<gd::String>& GetAuthorIds() const { return authorIds; };
100  std::vector<gd::String>& GetAuthorIds() { return authorIds; };
101 
102  const gd::String& GetAuthor() const { return author; };
103  EventsFunctionsExtension& SetAuthor(const gd::String& author_) {
104  author = author_;
105  return *this;
106  }
107 
108  const gd::String& GetPreviewIconUrl() const { return previewIconUrl; };
109  EventsFunctionsExtension& SetPreviewIconUrl(
110  const gd::String& previewIconUrl_) {
111  previewIconUrl = previewIconUrl_;
112  return *this;
113  }
114 
115  const gd::String& GetIconUrl() const { return iconUrl; };
116  EventsFunctionsExtension& SetIconUrl(const gd::String& iconUrl_) {
117  iconUrl = iconUrl_;
118  return *this;
119  }
120 
125  const gd::String& GetHelpPath() const { return helpPath; };
126 
132  helpPath = helpPath_;
133  return *this;
134  }
135 
140  return eventsBasedBehaviors;
141  }
142 
148  return eventsBasedBehaviors;
149  }
150 
155  return eventsBasedObjects;
156  }
157 
163  return eventsBasedObjects;
164  }
165 
172  virtual void SetOrigin(const gd::String& originName_,
173  const gd::String& originIdentifier_) {
174  originName = originName_;
175  originIdentifier = originIdentifier_;
176  }
177 
178  virtual const gd::String& GetOriginName() const { return originName; }
179  virtual const gd::String& GetOriginIdentifier() const {
180  return originIdentifier;
181  }
182 
186 
191  gd::DependencyMetadata dependency;
192  dependencies.push_back(dependency);
193  return dependencies.back();
194  };
195 
199  void RemoveDependencyAt(size_t index) {
200  dependencies.erase(dependencies.begin() + index);
201  };
202 
206  std::vector<gd::DependencyMetadata>& GetAllDependencies() {
207  return dependencies;
208  };
209 
213  const std::vector<gd::DependencyMetadata>& GetAllDependencies() const {
214  return dependencies;
215  };
216 
218 
223 
229  return globalVariables;
230  }
231 
236  inline gd::VariablesContainer& GetGlobalVariables() { return globalVariables; }
237 
243  return sceneVariables;
244  }
245 
250  inline gd::VariablesContainer& GetSceneVariables() { return sceneVariables; }
251 
253 
257 
260  void SerializeTo(gd::SerializerElement& element) const;
261 
265  void UnserializeFrom(gd::Project& project,
266  const gd::SerializerElement& element);
267 
272  void UnserializeExtensionDeclarationFrom(
273  gd::Project& project,
274  const gd::SerializerElement& element);
275 
280  void UnserializeExtensionImplementationFrom(
281  gd::Project& project,
282  const gd::SerializerElement& element);
284 
288  static bool IsExtensionLifecycleEventsFunction(
289  const gd::String& eventsFunctionName);
291 
292  private:
297  void Init(const gd::EventsFunctionsExtension& other);
298 
299  void SerializeDependencyTo(const gd::DependencyMetadata& dependency,
300  gd::SerializerElement& serializer) const {
301  serializer.SetStringAttribute("type", dependency.GetDependencyType());
302  serializer.SetStringAttribute("exportName", dependency.GetExportName());
303  serializer.SetStringAttribute("name", dependency.GetName());
304  serializer.SetStringAttribute("version", dependency.GetVersion());
305  }
306 
307  gd::DependencyMetadata UnserializeDependencyFrom(
308  gd::SerializerElement& serializer) {
309  gd::DependencyMetadata dependency;
310  dependency.SetDependencyType(serializer.GetStringAttribute("type"));
311  dependency.SetExportName(serializer.GetStringAttribute("exportName"));
312  dependency.SetName(serializer.GetStringAttribute("name"));
313  dependency.SetVersion(serializer.GetStringAttribute("version"));
314  return dependency;
315  }
316 
317  std::vector<gd::String> GetUnserializingOrderEventsBasedObjectNames(
318  const gd::SerializerElement &eventsBasedObjectsElement);
319 
320  gd::String version;
321  gd::String extensionNamespace;
322  gd::String shortDescription;
323  gd::String description;
324  gd::String name;
325  gd::String fullName;
326  gd::String category;
327  std::vector<gd::String> tags;
328  std::vector<gd::String> authorIds;
329  gd::String author;
330  gd::String previewIconUrl;
331  gd::String originName;
332  gd::String originIdentifier;
333  gd::String iconUrl;
334  gd::String helpPath;
338  std::vector<gd::DependencyMetadata> dependencies;
339 
340  gd::VariablesContainer globalVariables;
341  gd::VariablesContainer sceneVariables;
342 };
343 
344 } // 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
Hold a list of Events Functions (gd::EventsFunction) and Events Based Behaviors.
Definition: EventsFunctionsExtension.h:38
gd::DependencyMetadata & AddDependency()
Adds a new dependency.
Definition: EventsFunctionsExtension.h:190
const std::vector< gd::DependencyMetadata > & GetAllDependencies() const
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:213
const gd::String & GetHelpPath() const
Get the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:125
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:172
gd::VariablesContainer & GetGlobalVariables()
Definition: EventsFunctionsExtension.h:236
gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects()
Return a reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:154
void RemoveDependencyAt(size_t index)
Adds a new dependency.
Definition: EventsFunctionsExtension.h:199
const gd::VariablesContainer & GetSceneVariables() const
Definition: EventsFunctionsExtension.h:242
std::vector< gd::DependencyMetadata > & GetAllDependencies()
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:206
const gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors() const
Return a const reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:147
const gd::VariablesContainer & GetGlobalVariables() const
Definition: EventsFunctionsExtension.h:228
gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors()
Return a reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:139
gd::VariablesContainer & GetSceneVariables()
Definition: EventsFunctionsExtension.h:250
EventsFunctionsExtension & SetHelpPath(const gd::String &helpPath_)
Set the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:131
EventsFunctionsExtension * Clone() const
Return a pointer to a new EventsFunctionsExtension constructed from this one.
Definition: EventsFunctionsExtension.h:49
const gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects() const
Return a const reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:162
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
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
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