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/VariablesContainer.h"
16 #include "GDCore/String.h"
17 #include "GDCore/Tools/SerializableWithNameList.h"
18 namespace gd {
19 class SerializerElement;
20 class Project;
21 } // namespace gd
22 
23 namespace gd {
24 // TODO Remove the EventsFunctionsContainer inheritance and make it an attribute.
25 // This will allow to get EventsFunctionsContainer the same way for extensions,
26 // objects and behaviors.
39 class GD_CORE_API EventsFunctionsExtension {
40  public:
44  virtual ~EventsFunctionsExtension(){};
45 
51  return new EventsFunctionsExtension(*this);
52  };
53 
54  const gd::String& GetVersion() const { return version; };
55  EventsFunctionsExtension& SetVersion(const gd::String& version_) {
56  version = version_;
57  return *this;
58  }
59 
60  const gd::String& GetNamespace() const { return extensionNamespace; };
61  EventsFunctionsExtension& SetNamespace(const gd::String& namespace_) {
62  extensionNamespace = namespace_;
63  return *this;
64  }
65 
66  const gd::String& GetShortDescription() const { return shortDescription; };
67  EventsFunctionsExtension& SetShortDescription(
68  const gd::String& shortDescription_) {
69  shortDescription = shortDescription_;
70  return *this;
71  }
72 
73  const gd::String& GetDescription() const { return description; };
74  EventsFunctionsExtension& SetDescription(const gd::String& description_) {
75  description = description_;
76  return *this;
77  }
78 
79  const gd::String& GetName() const { return name; };
80  EventsFunctionsExtension& SetName(const gd::String& name_) {
81  name = name_;
82  return *this;
83  }
84 
85  const gd::String& GetFullName() const { return fullName; };
86  EventsFunctionsExtension& SetFullName(const gd::String& fullName_) {
87  fullName = fullName_;
88  return *this;
89  }
90 
91  const gd::String& GetCategory() const { return category; };
92  EventsFunctionsExtension& SetCategory(const gd::String& category_) {
93  category = category_;
94  return *this;
95  }
96 
97  const std::vector<gd::String>& GetTags() const { return tags; };
98  std::vector<gd::String>& GetTags() { return tags; };
99 
100  const std::vector<gd::String>& GetAuthorIds() const { return authorIds; };
101  std::vector<gd::String>& GetAuthorIds() { return authorIds; };
102 
103  const gd::String& GetAuthor() const { return author; };
104  EventsFunctionsExtension& SetAuthor(const gd::String& author_) {
105  author = author_;
106  return *this;
107  }
108 
109  const gd::String& GetPreviewIconUrl() const { return previewIconUrl; };
110  EventsFunctionsExtension& SetPreviewIconUrl(
111  const gd::String& previewIconUrl_) {
112  previewIconUrl = previewIconUrl_;
113  return *this;
114  }
115 
116  const gd::String& GetIconUrl() const { return iconUrl; };
117  EventsFunctionsExtension& SetIconUrl(const gd::String& iconUrl_) {
118  iconUrl = iconUrl_;
119  return *this;
120  }
121 
126  const gd::String& GetHelpPath() const { return helpPath; };
127 
133  helpPath = helpPath_;
134  return *this;
135  }
136 
140  const gd::String& GetGDevelopVersion() const { return gdevelopVersion; };
141 
146  gdevelopVersion = gdevelopVersion_;
147  return *this;
148  }
149 
154  return eventsBasedBehaviors;
155  }
156 
162  return eventsBasedBehaviors;
163  }
164 
169  return eventsBasedObjects;
170  }
171 
177  return eventsBasedObjects;
178  }
179 
186  virtual void SetOrigin(const gd::String& originName_,
187  const gd::String& originIdentifier_) {
188  originName = originName_;
189  originIdentifier = originIdentifier_;
190  }
191 
192  virtual const gd::String& GetOriginName() const { return originName; }
193  virtual const gd::String& GetOriginIdentifier() const {
194  return originIdentifier;
195  }
196 
201  return eventsFunctionsContainer;
202  }
203 
209  return eventsFunctionsContainer;
210  }
211 
215 
220  gd::DependencyMetadata dependency;
221  dependencies.push_back(dependency);
222  return dependencies.back();
223  };
224 
228  void RemoveDependencyAt(size_t index) {
229  dependencies.erase(dependencies.begin() + index);
230  };
231 
235  std::vector<gd::DependencyMetadata>& GetAllDependencies() {
236  return dependencies;
237  };
238 
242  const std::vector<gd::DependencyMetadata>& GetAllDependencies() const {
243  return dependencies;
244  };
245 
247 
252 
258  return globalVariables;
259  }
260 
265  inline gd::VariablesContainer& GetGlobalVariables() { return globalVariables; }
266 
272  return sceneVariables;
273  }
274 
279  inline gd::VariablesContainer& GetSceneVariables() { return sceneVariables; }
280 
282 
286 
289  void SerializeTo(gd::SerializerElement& element) const;
290 
294  void UnserializeFrom(gd::Project& project,
295  const gd::SerializerElement& element);
296 
301  void UnserializeExtensionDeclarationFrom(
302  gd::Project& project,
303  const gd::SerializerElement& element);
304 
309  void UnserializeExtensionImplementationFrom(
310  gd::Project& project,
311  const gd::SerializerElement& element);
313 
317  static bool IsExtensionLifecycleEventsFunction(
318  const gd::String& eventsFunctionName);
320 
324 
329  gd::SourceFileMetadata sourceFile;
330  sourceFiles.push_back(sourceFile);
331  return sourceFiles.back();
332  };
333 
337  void RemoveSourceFileAt(size_t index) {
338  sourceFiles.erase(sourceFiles.begin() + index);
339  };
340 
344  std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() {
345  return sourceFiles;
346  };
347 
351  const std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() const {
352  return sourceFiles;
353  };
354 
356 
357  private:
362  void Init(const gd::EventsFunctionsExtension& other);
363 
364  void SerializeDependencyTo(const gd::DependencyMetadata& dependency,
365  gd::SerializerElement& serializer) const {
366  serializer.SetStringAttribute("type", dependency.GetDependencyType());
367  serializer.SetStringAttribute("exportName", dependency.GetExportName());
368  serializer.SetStringAttribute("name", dependency.GetName());
369  serializer.SetStringAttribute("version", dependency.GetVersion());
370  }
371 
372  gd::DependencyMetadata UnserializeDependencyFrom(
373  gd::SerializerElement& serializer) {
374  gd::DependencyMetadata dependency;
375  dependency.SetDependencyType(serializer.GetStringAttribute("type"));
376  dependency.SetExportName(serializer.GetStringAttribute("exportName"));
377  dependency.SetName(serializer.GetStringAttribute("name"));
378  dependency.SetVersion(serializer.GetStringAttribute("version"));
379  return dependency;
380  }
381 
382  std::vector<gd::String> GetUnserializingOrderEventsBasedObjectNames(
383  const gd::SerializerElement &eventsBasedObjectsElement);
384 
385  gd::String version;
386  gd::String extensionNamespace;
387  gd::String shortDescription;
388  gd::String description;
389  gd::String name;
390  gd::String fullName;
391  gd::String category;
392  std::vector<gd::String> tags;
393  std::vector<gd::String> authorIds;
394  gd::String author;
395  gd::String previewIconUrl;
396  gd::String originName;
397  gd::String originIdentifier;
398  gd::String iconUrl;
399  gd::String helpPath;
401  gd::String gdevelopVersion;
404  std::vector<gd::DependencyMetadata> dependencies;
405  std::vector<gd::SourceFileMetadata> sourceFiles;
406 
407  gd::EventsFunctionsContainer eventsFunctionsContainer;
408  gd::VariablesContainer globalVariables;
409  gd::VariablesContainer sceneVariables;
410 };
411 
412 } // 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:39
gd::DependencyMetadata & AddDependency()
Adds a new dependency.
Definition: EventsFunctionsExtension.h:219
const std::vector< gd::DependencyMetadata > & GetAllDependencies() const
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:242
const gd::String & GetHelpPath() const
Get the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:126
void RemoveSourceFileAt(size_t index)
Removes a source file.
Definition: EventsFunctionsExtension.h:337
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:186
const EventsFunctionsContainer & GetEventsFunctions() const
Return a const reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:208
gd::VariablesContainer & GetGlobalVariables()
Definition: EventsFunctionsExtension.h:265
gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects()
Return a reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:168
void RemoveDependencyAt(size_t index)
Adds a new dependency.
Definition: EventsFunctionsExtension.h:228
EventsFunctionsExtension & SetGDevelopVersion(const gd::String &gdevelopVersion_)
Set the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:145
const gd::VariablesContainer & GetSceneVariables() const
Definition: EventsFunctionsExtension.h:271
std::vector< gd::DependencyMetadata > & GetAllDependencies()
Returns the list of dependencies.
Definition: EventsFunctionsExtension.h:235
gd::SourceFileMetadata & AddSourceFile()
Adds a new source file.
Definition: EventsFunctionsExtension.h:328
const gd::String & GetGDevelopVersion() const
Get the GDevelop version required by this extension.
Definition: EventsFunctionsExtension.h:140
const gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors() const
Return a const reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:161
const gd::VariablesContainer & GetGlobalVariables() const
Definition: EventsFunctionsExtension.h:257
const std::vector< gd::SourceFileMetadata > & GetAllSourceFiles() const
Returns the list of source files.
Definition: EventsFunctionsExtension.h:351
gd::SerializableWithNameList< EventsBasedBehavior > & GetEventsBasedBehaviors()
Return a reference to the list of the events based behaviors.
Definition: EventsFunctionsExtension.h:153
gd::VariablesContainer & GetSceneVariables()
Definition: EventsFunctionsExtension.h:279
std::vector< gd::SourceFileMetadata > & GetAllSourceFiles()
Returns the list of source files.
Definition: EventsFunctionsExtension.h:344
EventsFunctionsExtension & SetHelpPath(const gd::String &helpPath_)
Set the help path of this extension, relative to the GDevelop documentation root.
Definition: EventsFunctionsExtension.h:132
EventsFunctionsContainer & GetEventsFunctions()
Return a reference to the functions of the events based behavior or object.
Definition: EventsFunctionsExtension.h:200
EventsFunctionsExtension * Clone() const
Return a pointer to a new EventsFunctionsExtension constructed from this one.
Definition: EventsFunctionsExtension.h:50
const gd::SerializableWithNameList< EventsBasedObject > & GetEventsBasedObjects() const
Return a const reference to the list of the events based objects.
Definition: EventsFunctionsExtension.h:176
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