GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ProjectScopedContainers.h
1 #pragma once
2 #include <set>
3 
4 #include "GDCore/Extensions/Metadata/ParameterMetadataTools.h"
5 #include "ObjectsContainersList.h"
6 #include "PropertiesContainersList.h"
7 #include "VariablesContainersList.h"
8 #include "ResourcesContainersList.h"
9 #include "VariablesContainer.h"
10 
11 namespace gd {
12 class Project;
13 class ObjectsContainer;
14 class NamedPropertyDescriptor;
15 class ParameterMetadataContainer;
16 class BaseEvent;
17 class EventsFunctionsExtension;
18 class EventsFunction;
19 class EventsBasedBehavior;
20 class EventsBasedObject;
21 } // namespace gd
22 
23 namespace gd {
24 
36  public:
38  const gd::ObjectsContainersList &objectsContainersList_,
39  const gd::VariablesContainersList &variablesContainersList_,
40  const gd::VariablesContainer *legacyGlobalVariables_,
41  const gd::VariablesContainer *legacySceneVariables_,
42  const gd::PropertiesContainersList &propertiesContainersList_,
43  const gd::ResourcesContainersList &resourcesContainersList_)
44  : objectsContainersList(objectsContainersList_),
45  variablesContainersList(variablesContainersList_),
46  legacyGlobalVariables(legacyGlobalVariables_),
47  legacySceneVariables(legacySceneVariables_),
48  propertiesContainersList(propertiesContainersList_),
49  resourcesContainersList(resourcesContainersList_){};
50  virtual ~ProjectScopedContainers(){};
51 
53  MakeNewProjectScopedContainersForProjectAndLayout(const gd::Project &project,
54  const gd::Layout &layout);
55 
57  MakeNewProjectScopedContainersForProject(const gd::Project &project);
58 
60  MakeNewProjectScopedContainersForEventsFunctionsExtension(
61  const gd::Project &project,
62  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
63 
65  MakeNewProjectScopedContainersForFreeEventsFunction(
66  const gd::Project &project,
67  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
68  const gd::EventsFunction &eventsFunction,
69  gd::ObjectsContainer &parameterObjectsContainer,
70  gd::VariablesContainer &parameterVariablesContainer,
71  gd::ResourcesContainer &parameterResourcesContainer);
72 
74  MakeNewProjectScopedContainersForBehaviorEventsFunction(
75  const gd::Project &project,
76  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
77  const gd::EventsBasedBehavior &eventsBasedBehavior,
78  const gd::EventsFunction &eventsFunction,
79  gd::ObjectsContainer &parameterObjectsContainer,
80  gd::VariablesContainer &parameterVariablesContainer,
81  gd::VariablesContainer &propertyVariablesContainer,
82  gd::ResourcesContainer &parameterResourcesContainer,
83  gd::ResourcesContainer &propertyResourcesContainer);
84 
86  MakeNewProjectScopedContainersForObjectEventsFunction(
87  const gd::Project &project,
88  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
89  const gd::EventsBasedObject &eventsBasedObject,
90  const gd::EventsFunction &eventsFunction,
91  gd::ObjectsContainer &parameterObjectsContainer,
92  gd::VariablesContainer &parameterVariablesContainer,
93  gd::VariablesContainer &propertyVariablesContainer,
94  gd::ResourcesContainer &parameterResourcesContainer,
95  gd::ResourcesContainer &propertyResourcesContainer);
96 
98  MakeNewProjectScopedContainersForEventsBasedObject(
99  const gd::Project &project,
100  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
101  const gd::EventsBasedObject &eventsBasedObject,
102  gd::ObjectsContainer &outputObjectsContainer);
103 
105  MakeNewProjectScopedContainersWithLocalVariables(
106  const ProjectScopedContainers &projectScopedContainers,
107  const gd::BaseEvent &event);
108 
109  ProjectScopedContainers &AddPropertiesContainer(
110  const gd::PropertiesContainer &container) {
111  propertiesContainersList.Add(container);
112 
113  return *this;
114  }
115 
116  ProjectScopedContainers &AddParameters(
117  const ParameterMetadataContainer &parameters) {
118  parametersVectorsList.push_back(&parameters);
119 
120  return *this;
121  }
122 
123  template <class ReturnType>
124  ReturnType MatchIdentifierWithName(
125  const gd::String &name,
126  std::function<ReturnType()> objectCallback,
127  std::function<ReturnType()> variableCallback,
128  std::function<ReturnType()> propertyCallback,
129  std::function<ReturnType()> parameterCallback,
130  std::function<ReturnType()> notFoundCallback) const {
131  if (objectsContainersList.HasObjectOrGroupNamed(name))
132  return objectCallback();
133  else if (variablesContainersList.Has(name)) {
134  const auto &variablesContainer =
136  const auto sourceType = variablesContainer.GetSourceType();
137  if (sourceType == gd::VariablesContainer::SourceType::Properties) {
138  return propertyCallback();
139  } else if (sourceType == gd::VariablesContainer::SourceType::Parameters) {
140  return parameterCallback();
141  }
142  return variableCallback();
143  } else if (ParameterMetadataTools::Has(parametersVectorsList, name))
144  return parameterCallback();
145  else if (propertiesContainersList.Has(name))
146  return propertyCallback();
147 
148  return notFoundCallback();
149  };
150 
151  void ForEachIdentifierMatchingSearch(
152  const gd::String &search,
153  std::function<void(const gd::String &name,
154  const ObjectConfiguration *objectConfiguration)>
155  objectCallback,
156  std::function<void(const gd::String &name, const gd::Variable &variable)>
157  variableCallback,
158  std::function<void(const gd::NamedPropertyDescriptor &property)>
159  propertyCallback,
160  std::function<void(const gd::ParameterMetadata &parameter)>
161  parameterCallback) const {
162  std::set<gd::String> namesAlreadySeen;
163 
164  objectsContainersList.ForEachNameMatchingSearch(
165  search,
166  [&](const gd::String &name,
167  const ObjectConfiguration *objectConfiguration) {
168  if (namesAlreadySeen.count(name) == 0) {
169  namesAlreadySeen.insert(name);
170  objectCallback(name, objectConfiguration);
171  }
172  });
173  variablesContainersList.ForEachVariableMatchingSearch(
174  search, [&](const gd::String &name, const gd::Variable &variable) {
175  if (namesAlreadySeen.count(name) == 0) {
176  namesAlreadySeen.insert(name);
177  variableCallback(name, variable);
178  }
179  });
180  gd::ParameterMetadataTools::ForEachParameterMatchingSearch(
181  parametersVectorsList,
182  search,
183  [&](const gd::ParameterMetadata &parameter) {
184  if (namesAlreadySeen.count(parameter.GetName()) == 0) {
185  namesAlreadySeen.insert(parameter.GetName());
186  parameterCallback(parameter);
187  }
188  });
189  propertiesContainersList.ForEachPropertyMatchingSearch(
190  search, [&](const gd::NamedPropertyDescriptor &property) {
191  if (namesAlreadySeen.count(property.GetName()) == 0) {
192  namesAlreadySeen.insert(property.GetName());
193  propertyCallback(property);
194  }
195  });
196  };
197 
198  const gd::ObjectsContainersList &GetObjectsContainersList() const {
199  return objectsContainersList;
200  };
201 
202  const gd::VariablesContainersList &GetVariablesContainersList() const {
203  return variablesContainersList;
204  };
205 
211  return variablesContainersList;
212  };
213 
220  return legacyGlobalVariables;
221  };
222 
229  return legacySceneVariables;
230  };
231 
232  const gd::PropertiesContainersList &GetPropertiesContainersList() const {
233  return propertiesContainersList;
234  };
235 
236  const std::vector<const ParameterMetadataContainer *> &GetParametersVectorsList() const {
237  return parametersVectorsList;
238  };
239 
240  const gd::ResourcesContainersList &GetResourcesContainersList() const {
241  return resourcesContainersList;
242  };
243 
247  : legacyGlobalVariables(nullptr), legacySceneVariables(nullptr){};
248 
249 private:
250  gd::ObjectsContainersList objectsContainersList;
251  gd::VariablesContainersList variablesContainersList;
252  const gd::VariablesContainer *legacyGlobalVariables;
253  const gd::VariablesContainer *legacySceneVariables;
254  gd::PropertiesContainersList propertiesContainersList;
255  std::vector<const ParameterMetadataContainer *> parametersVectorsList;
256  gd::ResourcesContainersList resourcesContainersList;
257 };
258 
259 } // namespace gd
Base class defining an event.
Definition: Event.h:43
Represents a behavior that is implemented with events.
Definition: EventsBasedBehavior.h:31
Represents an object that is implemented with events.
Definition: EventsBasedObject.h:32
Events that can be generated as a stand-alone function, and used as a condition, action or expression...
Definition: EventsFunction.h:38
Hold a list of Events Functions (gd::EventsFunction) and Events Based Behaviors.
Definition: EventsFunctionsExtension.h:41
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:40
Used to describe a property shown in a property grid.
Definition: NamedPropertyDescriptor.h:21
const gd::String & GetName() const
Get the name of the property.
Definition: NamedPropertyDescriptor.h:47
Base class used to represent an object configuration. For example, this can be the animations in a sp...
Definition: ObjectConfiguration.h:38
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:37
A list of objects containers, useful for accessing objects in a scoped way, along with methods to acc...
Definition: ObjectsContainersList.h:29
void ForEachNameMatchingSearch(const gd::String &search, std::function< void(const gd::String &name, const gd::ObjectConfiguration *objectConfiguration)> fn) const
Call the callback for each object or group name matching the search passed in parameter.
Definition: ObjectsContainersList.cpp:332
bool HasObjectOrGroupNamed(const gd::String &name) const
Check if the specified object or group exists.
Definition: ObjectsContainersList.cpp:56
Used as a base class for classes that will own events-backed functions.
Definition: ParameterMetadataContainer.h:26
Describe a parameter of an instruction (action, condition) or of an expression: type,...
Definition: ParameterMetadata.h:27
const gd::String & GetName() const
Return the name of the parameter.
Definition: ParameterMetadata.h:79
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:35
gd::VariablesContainersList & GetVariablesContainersList()
Allow modification of the variables containers list. This is used by code generation which does push ...
Definition: ProjectScopedContainers.h:210
const gd::VariablesContainer * GetLegacyGlobalVariables() const
Return the global variables of the current scene or the current extension. It allows legacy "globalva...
Definition: ProjectScopedContainers.h:219
ProjectScopedContainers()
Definition: ProjectScopedContainers.h:246
const gd::VariablesContainer * GetLegacySceneVariables() const
Return the scene variables of the current scene or the current extension. It allows legacy "scenevar"...
Definition: ProjectScopedContainers.h:228
A container of properties, used for custom behaviors, custom objects, extensions.....
Definition: PropertiesContainer.h:17
A list of property containers, useful for accessing properties in a scoped way.
Definition: PropertiesContainersList.h:26
bool Has(const gd::String &name) const
Return true if the specified property is in one of the containers.
Definition: PropertiesContainersList.cpp:27
void Add(const gd::PropertiesContainer &propertiesContainer)
Add a new container of properties in the list. Add containers in order from the most global one to th...
Definition: PropertiesContainersList.h:38
void ForEachPropertyMatchingSearch(const gd::String &search, std::function< void(const gd::NamedPropertyDescriptor &property)> fn) const
Call the callback for each property having a name matching the specified search.
Definition: PropertiesContainersList.cpp:58
Inventory all resources used by a project.
Definition: ResourcesContainer.h:628
A list of resources containers, useful for accessing resources in a scoped way, along with methods to...
Definition: ResourcesContainersList.h:36
String represents an UTF8 encoded string.
Definition: String.h:33
Defines a variable which can be used by an object, a layout or a project.
Definition: Variable.h:29
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:28
A list of variables containers, useful for accessing variables in a scoped way.
Definition: VariablesContainersList.h:29
const VariablesContainer & GetVariablesContainerFromVariableOrPropertyOrParameterName(const gd::String &variableName) const
Definition: VariablesContainersList.cpp:150
bool Has(const gd::String &name) const
Return true if the specified variable is in one of the containers.
Definition: VariablesContainersList.cpp:131
void ForEachVariableMatchingSearch(const gd::String &search, std::function< void(const gd::String &name, const gd::Variable &variable)> fn) const
Call the callback for each variable having a name matching the specified search.
Definition: VariablesContainersList.cpp:217
Definition: CommonTools.h:24