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, bool isExternal = false) const;
290 
295  SerializeTo(element, true);
296  }
297 
301  void UnserializeFrom(gd::Project& project,
302  const gd::SerializerElement& element);
303 
308  void UnserializeExtensionDeclarationFrom(
309  gd::Project& project,
310  const gd::SerializerElement& element);
311 
316  void UnserializeExtensionImplementationFrom(
317  gd::Project& project,
318  const gd::SerializerElement& element);
320 
324  static bool IsExtensionLifecycleEventsFunction(
325  const gd::String& eventsFunctionName);
327 
331 
336  gd::SourceFileMetadata sourceFile;
337  sourceFiles.push_back(sourceFile);
338  return sourceFiles.back();
339  };
340 
344  void RemoveSourceFileAt(size_t index) {
345  sourceFiles.erase(sourceFiles.begin() + index);
346  };
347 
351  std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() {
352  return sourceFiles;
353  };
354 
358  const std::vector<gd::SourceFileMetadata>& GetAllSourceFiles() const {
359  return sourceFiles;
360  };
361 
363 
364  private:
369  void Init(const gd::EventsFunctionsExtension& other);
370 
371  void SerializeDependencyTo(const gd::DependencyMetadata& dependency,
372  gd::SerializerElement& serializer) const {
373  serializer.SetStringAttribute("type", dependency.GetDependencyType());
374  serializer.SetStringAttribute("exportName", dependency.GetExportName());
375  serializer.SetStringAttribute("name", dependency.GetName());
376  serializer.SetStringAttribute("version", dependency.GetVersion());
377  }
378 
379  gd::DependencyMetadata UnserializeDependencyFrom(
380  gd::SerializerElement& serializer) {
381  gd::DependencyMetadata dependency;
382  dependency.SetDependencyType(serializer.GetStringAttribute("type"));
383  dependency.SetExportName(serializer.GetStringAttribute("exportName"));
384  dependency.SetName(serializer.GetStringAttribute("name"));
385  dependency.SetVersion(serializer.GetStringAttribute("version"));
386  return dependency;
387  }
388 
389  std::vector<gd::String> GetUnserializingOrderEventsBasedObjectNames(
390  const gd::SerializerElement &eventsBasedObjectsElement);
391 
392  gd::String version;
393  gd::String extensionNamespace;
394  gd::String shortDescription;
395  gd::String description;
396  gd::String name;
397  gd::String fullName;
398  gd::String category;
399  std::vector<gd::String> tags;
400  std::vector<gd::String> authorIds;
401  gd::String author;
402  gd::String previewIconUrl;
403  gd::String originName;
404  gd::String originIdentifier;
405  gd::String iconUrl;
406  gd::String helpPath;
408  gd::String gdevelopVersion;
411  std::vector<gd::DependencyMetadata> dependencies;
412  std::vector<gd::SourceFileMetadata> sourceFiles;
413 
414  gd::EventsFunctionsContainer eventsFunctionsContainer;
415  gd::VariablesContainer globalVariables;
416  gd::VariablesContainer sceneVariables;
417 };
418 
419 } // 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
void SerializeToExternal(gd::SerializerElement &element) const
Serialize the EventsFunctionsExtension to the specified element.
Definition: EventsFunctionsExtension.h:294
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:344
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:335
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:358
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:351
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