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 #include "GDCore/Extensions/Platform.h"
8 
9 namespace gd {
10 
19  gd::PlatformExtension &extension_)
20  : dependency(&dependency_), extension(&extension_){};
21 
22  gd::DependencyMetadata &GetDependency() const { return *dependency; };
23  gd::PlatformExtension &GetExtension() const { return *extension; };
24 
25  private:
26  gd::DependencyMetadata *dependency;
27  gd::PlatformExtension *extension;
28 };
29 
35  public:
45  static std::vector<DependencyMetadataAndExtension> GetDependenciesFor(
46  const gd::Project &project,
47  std::set<gd::String> usedExtensions,
48  const gd::String &dependencyType) {
49  std::vector<DependencyMetadataAndExtension> dependenciesWithProperType;
50  for (const gd::String &extensionName : usedExtensions) {
51  auto extension = project.GetCurrentPlatform().GetExtension(extensionName);
52  for (gd::DependencyMetadata &dependency :
53  extension->GetAllDependencies()) {
54  if (dependency.GetDependencyType() == dependencyType) {
55  DependencyMetadataAndExtension dependencyMetadataAndExtension(
56  dependency, *extension);
57  dependenciesWithProperType.push_back(dependencyMetadataAndExtension);
58  }
59  }
60  }
61 
62  // Keep only the dependencies that have their extra settings filled
63  // and those that don't require extra settings to be filled.
64  std::vector<DependencyMetadataAndExtension> dependenciesWithFilledSettings;
65  for (auto dependencyAndExtension : dependenciesWithProperType) {
66  auto &dependency = dependencyAndExtension.GetDependency();
67  auto extraSettingValues = GetExtensionDependencyExtraSettingValues(
68  project, dependencyAndExtension);
69 
70  bool hasExtraSettings = !extraSettingValues.empty();
71  if (!dependency.IsOnlyIfSomeExtraSettingsNonEmpty() || hasExtraSettings)
72  dependenciesWithFilledSettings.push_back(dependencyAndExtension);
73  }
74 
75  // Keep only the dependency that depends on another dependencies that is
76  // exported (or dependencies that don't require another dependency).
77  std::vector<DependencyMetadataAndExtension> exportedDependencies;
78  for (auto dependencyAndExtension : dependenciesWithFilledSettings) {
79  auto &dependency = dependencyAndExtension.GetDependency();
80  auto &otherDependencyName =
81  dependency.GetOtherDependencyThatMustBeExported();
82  if (otherDependencyName.empty() ||
83  std::find_if(
84  dependenciesWithFilledSettings.begin(),
85  dependenciesWithFilledSettings.end(),
86  [&otherDependencyName](
87  DependencyMetadataAndExtension &otherDependencyAndExtension) {
88  return otherDependencyAndExtension.GetDependency().GetName() ==
89  otherDependencyName;
90  }) != dependenciesWithFilledSettings.end()) {
91  exportedDependencies.push_back(dependencyAndExtension);
92  }
93  }
94 
95  return exportedDependencies;
96  }
97 
102  static std::map<gd::String, gd::String>
104  const gd::Project &project,
105  const gd::DependencyMetadataAndExtension &dependencyAndExtension) {
106  std::map<gd::String, gd::String> values;
107  auto &dependency = dependencyAndExtension.GetDependency();
108  const gd::String &extensionName =
109  dependencyAndExtension.GetExtension().GetName();
110 
111  for (const auto &extraSetting : dependency.GetAllExtraSettings()) {
112  const gd::String &type = extraSetting.second.GetType();
113  const gd::String extraSettingValue =
114  type == "ExtensionProperty"
115  ? project.GetExtensionProperties().GetValue(
116  extensionName, extraSetting.second.GetValue())
117  : extraSetting.second.GetValue();
118 
119  if (!extraSettingValue.empty())
120  values[extraSetting.first] = extraSettingValue;
121  }
122 
123  return values;
124  };
125 };
126 
127 } // 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:34
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:45
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:103
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:379
std::shared_ptr< PlatformExtension > GetExtension(const gd::String &name) const
Get an extension of the platform.
Definition: Platform.cpp:91
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:253
gd::ExtensionProperties & GetExtensionProperties()
Get the properties set by extensions.
Definition: Project.h:464
String represents an UTF8 encoded string.
Definition: String.h:33
bool empty() const
Returns true if the string is empty.
Definition: String.h:157
Definition: CommonTools.h:24
Store references to a gd::DependencyMetadata and its associated gd::PlatformExtension.
Definition: ExportedDependencyResolver.h:17