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 #ifndef GDCORE_EVENTSFUNCTIONEXTENSION_H
7 #define GDCORE_EVENTSFUNCTIONEXTENSION_H
8 
9 #include <vector>
10 
11 #include "GDCore/Extensions/Metadata/DependencyMetadata.h"
12 #include "GDCore/Project/EventsBasedBehavior.h"
13 #include "GDCore/Project/EventsBasedObject.h"
14 #include "GDCore/Project/EventsFunctionsContainer.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 
222 
225  void SerializeTo(gd::SerializerElement& element) const;
226 
230  void UnserializeFrom(gd::Project& project,
231  const gd::SerializerElement& element);
232 
237  void UnserializeExtensionDeclarationFrom(
238  gd::Project& project,
239  const gd::SerializerElement& element);
240 
245  void UnserializeExtensionImplementationFrom(
246  gd::Project& project,
247  const gd::SerializerElement& element);
249 
253  static bool IsExtensionLifecycleEventsFunction(
254  const gd::String& eventsFunctionName);
256 
257  private:
262  void Init(const gd::EventsFunctionsExtension& other);
263 
264  void SerializeDependencyTo(const gd::DependencyMetadata& dependency,
265  gd::SerializerElement& serializer) const {
266  serializer.SetStringAttribute("type", dependency.GetDependencyType());
267  serializer.SetStringAttribute("exportName", dependency.GetExportName());
268  serializer.SetStringAttribute("name", dependency.GetName());
269  serializer.SetStringAttribute("version", dependency.GetVersion());
270  }
271 
272  gd::DependencyMetadata UnserializeDependencyFrom(
273  gd::SerializerElement& serializer) {
274  gd::DependencyMetadata dependency;
275  dependency.SetDependencyType(serializer.GetStringAttribute("type"));
276  dependency.SetExportName(serializer.GetStringAttribute("exportName"));
277  dependency.SetName(serializer.GetStringAttribute("name"));
278  dependency.SetVersion(serializer.GetStringAttribute("version"));
279  return dependency;
280  }
281 
282  gd::String version;
283  gd::String extensionNamespace;
284  gd::String shortDescription;
285  gd::String description;
286  gd::String name;
287  gd::String fullName;
288  gd::String category;
289  std::vector<gd::String> tags;
290  std::vector<gd::String> authorIds;
291  gd::String author;
292  gd::String previewIconUrl;
293  gd::String originName;
294  gd::String originIdentifier;
295  gd::String iconUrl;
296  gd::String helpPath;
300  std::vector<gd::DependencyMetadata> dependencies;
301 };
302 
303 } // namespace gd
304 
305 #endif // GDCORE_EVENTSFUNCTIONEXTENSION_H
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::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
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
gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors()
Return a reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:139
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: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
String represents an UTF8 encoded string.
Definition: String.h:31
Definition: CommonTools.h:24