GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ExportedDependencyResolver.h
1 #pragma once
2 #include <vector>
3 
4 #include "GDCore/Extensions/Metadata/DependencyMetadata.h"
5 #include "GDCore/Extensions/PlatformExtension.h"
6 #include "GDCore/Project/Project.h"
7 
8 namespace gd {
9 
18  gd::PlatformExtension &extension_)
19  : dependency(&dependency_), extension(&extension_){};
20 
21  gd::DependencyMetadata &GetDependency() const { return *dependency; };
22  gd::PlatformExtension &GetExtension() const { return *extension; };
23 
24  private:
25  gd::DependencyMetadata *dependency;
26  gd::PlatformExtension *extension;
27 };
28 
34  public:
44  static std::vector<DependencyMetadataAndExtension> GetDependenciesFor(
45  const gd::Project &project,
46  std::set<gd::String> usedExtensions,
47  const gd::String &dependencyType) {
48  std::vector<DependencyMetadataAndExtension> dependenciesWithProperType;
49  for (const gd::String &extensionName : usedExtensions) {
50  auto extension = project.GetCurrentPlatform().GetExtension(extensionName);
51  for (gd::DependencyMetadata &dependency :
52  extension->GetAllDependencies()) {
53  if (dependency.GetDependencyType() == dependencyType) {
54  DependencyMetadataAndExtension dependencyMetadataAndExtension(
55  dependency, *extension);
56  dependenciesWithProperType.push_back(dependencyMetadataAndExtension);
57  }
58  }
59  }
60 
61  // Keep only the dependencies that have their extra settings filled
62  // and those that don't require extra settings to be filled.
63  std::vector<DependencyMetadataAndExtension> dependenciesWithFilledSettings;
64  for (auto dependencyAndExtension : dependenciesWithProperType) {
65  auto &dependency = dependencyAndExtension.GetDependency();
66  auto extraSettingValues = GetExtensionDependencyExtraSettingValues(
67  project, dependencyAndExtension);
68 
69  bool hasExtraSettings = !extraSettingValues.empty();
70  if (!dependency.IsOnlyIfSomeExtraSettingsNonEmpty() || hasExtraSettings)
71  dependenciesWithFilledSettings.push_back(dependencyAndExtension);
72  }
73 
74  // Keep only the dependency that depends on another dependencies that is
75  // exported (or dependencies that don't require another dependency).
76  std::vector<DependencyMetadataAndExtension> exportedDependencies;
77  for (auto dependencyAndExtension : dependenciesWithFilledSettings) {
78  auto &dependency = dependencyAndExtension.GetDependency();
79  auto &otherDependencyName =
80  dependency.GetOtherDependencyThatMustBeExported();
81  if (otherDependencyName.empty() ||
82  std::find_if(
83  dependenciesWithFilledSettings.begin(),
84  dependenciesWithFilledSettings.end(),
85  [&otherDependencyName](
86  DependencyMetadataAndExtension &otherDependencyAndExtension) {
87  return otherDependencyAndExtension.GetDependency().GetName() ==
88  otherDependencyName;
89  }) != dependenciesWithFilledSettings.end()) {
90  exportedDependencies.push_back(dependencyAndExtension);
91  }
92  }
93 
94  return exportedDependencies;
95  }
96 
101  static std::map<gd::String, gd::String>
103  const gd::Project &project,
104  const gd::DependencyMetadataAndExtension &dependencyAndExtension) {
105  std::map<gd::String, gd::String> values;
106  auto &dependency = dependencyAndExtension.GetDependency();
107  const gd::String &extensionName =
108  dependencyAndExtension.GetExtension().GetName();
109 
110  for (const auto &extraSetting : dependency.GetAllExtraSettings()) {
111  const gd::String &type = extraSetting.second.GetType();
112  const gd::String extraSettingValue =
113  type == "ExtensionProperty"
114  ? project.GetExtensionProperties().GetValue(
115  extensionName, extraSetting.second.GetValue())
116  : extraSetting.second.GetValue();
117 
118  if (!extraSettingValue.empty())
119  values[extraSetting.first] = extraSettingValue;
120  }
121 
122  return values;
123  };
124 };
125 
126 } // namespace gd
Contains information about a dependency (library, npm/cordova package, or other according to the expo...
Definition: DependencyMetadata.h:20
Helpers to manipulate dependencies of extensions to be exported along with a game.
Definition: ExportedDependencyResolver.h:33
static std::vector< DependencyMetadataAndExtension > GetDependenciesFor(const gd::Project &project, std::set< gd::String > usedExtensions, const gd::String &dependencyType)
Return the list of dependencies to be exported for the given project, used extensions list and depend...
Definition: ExportedDependencyResolver.h:44
static std::map< gd::String, gd::String > GetExtensionDependencyExtraSettingValues(const gd::Project &project, const gd::DependencyMetadataAndExtension &dependencyAndExtension)
Return the values that were stored in the project for the given dependency.
Definition: ExportedDependencyResolver.h:102
Base class for implementing platform's extensions.
Definition: PlatformExtension.h:84
const gd::String & GetName() const
Return the name of the extension.
Definition: PlatformExtension.h:378
std::shared_ptr< PlatformExtension > GetExtension(const gd::String &name) const
Get an extension of the platform.
Definition: Platform.cpp:87
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
Platform & GetCurrentPlatform() const
Return a reference to the platform being currently used to edit the project.
Definition: Project.cpp:218
gd::ExtensionProperties & GetExtensionProperties()
Get the properties set by extensions.
Definition: Project.h:464
String represents an UTF8 encoded string.
Definition: String.h:31
bool empty() const
Returns true if the string is empty.
Definition: String.h:155
Definition: CommonTools.h:24
Store references to a gd::DependencyMetadata and its associated gd::PlatformExtension.
Definition: ExportedDependencyResolver.h:16