GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Platform.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 
7 #ifndef GDCORE_PLATFORM_H
8 #define GDCORE_PLATFORM_H
9 #include <map>
10 #include <memory>
11 #include <vector>
12 
13 #include "GDCore/Extensions/Metadata/InstructionOrExpressionGroupMetadata.h"
14 #include "GDCore/String.h"
15 namespace gd {
16 class InstructionsMetadataHolder;
17 class Project;
18 class Object;
19 class ObjectConfiguration;
20 class Behavior;
21 class BehaviorMetadata;
22 class ObjectMetadata;
23 class BaseEvent;
24 class BehaviorsSharedData;
25 class PlatformExtension;
26 class LayoutEditorCanvas;
27 class ProjectExporter;
28 } // namespace gd
29 
30 typedef std::function<std::unique_ptr<gd::ObjectConfiguration>()>
31  CreateFunPtr;
32 
33 #undef CreateEvent
34 
35 namespace gd {
36 
42 class GD_CORE_API Platform {
43  public:
44  Platform();
45  virtual ~Platform();
46 
50  virtual gd::String GetName() const { return "Unnamed platform"; }
51 
55  virtual gd::String GetFullName() const { return "Unnamed platform"; }
56 
60  virtual gd::String GetSubtitle() const { return ""; }
61 
65  virtual gd::String GetDescription() const { return ""; }
66 
70  virtual gd::String GetIcon() const { return ""; }
71 
76 
81  virtual void ReloadBuiltinExtensions(){};
82 
90  virtual gd::String GetExtensionCreateFunctionName() { return ""; }
91 
97  virtual bool AddExtension(std::shared_ptr<PlatformExtension> extension);
98 
102  bool IsExtensionLoaded(const gd::String& name) const;
103 
108  std::shared_ptr<PlatformExtension> GetExtension(const gd::String& name) const;
109 
114  const std::vector<std::shared_ptr<gd::PlatformExtension>>&
116  return extensionsLoaded;
117  };
118 
125  virtual void RemoveExtension(const gd::String& name);
126 
132  const gd::String& name) const {
133  auto it = instructionOrExpressionGroupMetadata.find(name);
134  if (it == instructionOrExpressionGroupMetadata.end())
135  return badInstructionOrExpressionGroupMetadata;
136 
137  return it->second;
138  }
140 
146 
150  std::unique_ptr<gd::ObjectConfiguration> CreateObjectConfiguration(
151  gd::String type) const;
152 
156  std::shared_ptr<gd::BaseEvent> CreateEvent(const gd::String& type) const;
157 
159 
164  void EnableExtensionLoadingLogs(bool enable) {
165  enableExtensionLoadingLogs = enable;
166  };
167 
168  private:
169  std::vector<std::shared_ptr<PlatformExtension>>
170  extensionsLoaded;
171  std::map<gd::String, CreateFunPtr>
172  creationFunctionTable;
173  std::map<gd::String, InstructionOrExpressionGroupMetadata>
174  instructionOrExpressionGroupMetadata;
175  static InstructionOrExpressionGroupMetadata badInstructionOrExpressionGroupMetadata;
176  bool enableExtensionLoadingLogs;
177 };
178 
179 } // namespace gd
180 
181 #endif // GDCORE_PLATFORM_H
Contains information about how to display a group of instructions to the user.
Definition: InstructionOrExpressionGroupMetadata.h:14
Base class for implementing a platform.
Definition: Platform.h:42
virtual gd::String GetExtensionCreateFunctionName()
Must return the name of the function that is used to create an extension for this platform.
Definition: Platform.h:90
virtual gd::String GetFullName() const
Must return the platform full name, displayed to users.
Definition: Platform.h:55
virtual gd::String GetName() const
Must return the platform name.
Definition: Platform.h:50
const std::vector< std::shared_ptr< gd::PlatformExtension > > & GetAllPlatformExtensions() const
Get all extensions loaded for the platform.
Definition: Platform.h:115
virtual gd::String GetDescription() const
Must return a text describing the platform, displayed to users.
Definition: Platform.h:65
const InstructionOrExpressionGroupMetadata & GetInstructionOrExpressionGroupMetadata(const gd::String &name) const
Get the metadata (icon, etc...) of a group used for instructions or expressions.
Definition: Platform.h:131
virtual void ReloadBuiltinExtensions()
(Re)load platform built-in extensions.
Definition: Platform.h:81
void EnableExtensionLoadingLogs(bool enable)
Activate or disable the logs on the standard output when loading an extension.
Definition: Platform.h:164
virtual gd::String GetSubtitle() const
Must return a text describing the platform in a few words.
Definition: Platform.h:60
virtual gd::String GetIcon() const
Must return a filename to a 32*32 image file for the platform.
Definition: Platform.h:70
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24