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 "GDCore/String.h"
6 #include "ObjectsContainersList.h"
7 #include "PropertiesContainersList.h"
8 #include "VariablesContainersList.h"
9 #include "ResourcesContainersList.h"
10 #include "VariablesContainer.h"
11 
12 namespace gd {
13 class Project;
14 class ObjectsContainer;
15 class NamedPropertyDescriptor;
16 class ParameterMetadataContainer;
17 class BaseEvent;
18 class EventsFunctionsExtension;
19 class EventsFunction;
20 class EventsBasedBehavior;
21 class EventsBasedObject;
22 } // namespace gd
23 
24 namespace gd {
25 
37  public:
39  const gd::ObjectsContainersList &objectsContainersList_,
40  const gd::VariablesContainersList &variablesContainersList_,
41  const gd::VariablesContainer *legacyGlobalVariables_,
42  const gd::VariablesContainer *legacySceneVariables_,
43  const gd::PropertiesContainersList &propertiesContainersList_,
44  const gd::ResourcesContainersList &resourcesContainersList_)
45  : objectsContainersList(objectsContainersList_),
46  variablesContainersList(variablesContainersList_),
47  legacyGlobalVariables(legacyGlobalVariables_),
48  legacySceneVariables(legacySceneVariables_),
49  propertiesContainersList(propertiesContainersList_),
50  resourcesContainersList(resourcesContainersList_){};
51  virtual ~ProjectScopedContainers(){};
52 
54  MakeNewProjectScopedContainersForProjectAndLayout(const gd::Project &project,
55  const gd::Layout &layout);
56 
58  MakeNewProjectScopedContainersForProject(const gd::Project &project);
59 
61  MakeNewProjectScopedContainersForEventsFunctionsExtension(
62  const gd::Project &project,
63  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
64 
66  MakeNewProjectScopedContainersForFreeEventsFunction(
67  const gd::Project &project,
68  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
69  const gd::EventsFunction &eventsFunction,
70  gd::ObjectsContainer &parameterObjectsContainer,
71  gd::VariablesContainer &parameterVariablesContainer,
72  gd::ResourcesContainer &parameterResourcesContainer);
73 
75  MakeNewProjectScopedContainersForBehaviorEventsFunction(
76  const gd::Project &project,
77  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
78  const gd::EventsBasedBehavior &eventsBasedBehavior,
79  const gd::EventsFunction &eventsFunction,
80  gd::ObjectsContainer &parameterObjectsContainer,
81  gd::VariablesContainer &parameterVariablesContainer,
82  gd::VariablesContainer &propertyVariablesContainer,
83  gd::ResourcesContainer &parameterResourcesContainer,
84  gd::ResourcesContainer &propertyResourcesContainer);
85 
87  MakeNewProjectScopedContainersForObjectEventsFunction(
88  const gd::Project &project,
89  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
90  const gd::EventsBasedObject &eventsBasedObject,
91  const gd::EventsFunction &eventsFunction,
92  gd::ObjectsContainer &parameterObjectsContainer,
93  gd::VariablesContainer &parameterVariablesContainer,
94  gd::VariablesContainer &propertyVariablesContainer,
95  gd::ResourcesContainer &parameterResourcesContainer,
96  gd::ResourcesContainer &propertyResourcesContainer);
97 
99  MakeNewProjectScopedContainersForEventsBasedObject(
100  const gd::Project &project,
101  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
102  const gd::EventsBasedObject &eventsBasedObject,
103  gd::ObjectsContainer &outputObjectsContainer);
104 
106  MakeNewProjectScopedContainersWithLocalVariables(
107  const ProjectScopedContainers &projectScopedContainers,
108  const gd::BaseEvent &event);
109 
110  ProjectScopedContainers &AddPropertiesContainer(
111  const gd::PropertiesContainer &container) {
112  propertiesContainersList.Add(container);
113 
114  return *this;
115  }
116 
117  ProjectScopedContainers &AddParameters(
118  const ParameterMetadataContainer &parameters) {
119  parametersVectorsList.push_back(&parameters);
120 
121  return *this;
122  }
123 
124  template <class ReturnType>
125  ReturnType MatchIdentifierWithName(
126  const gd::String &name,
127  std::function<ReturnType()> objectCallback,
128  std::function<ReturnType()> variableCallback,
129  std::function<ReturnType()> propertyCallback,
130  std::function<ReturnType()> parameterCallback,
131  std::function<ReturnType()> notFoundCallback) const {
132  if (objectsContainersList.HasObjectOrGroupNamed(name))
133  return objectCallback();
134  else if (variablesContainersList.Has(name)) {
135  const auto &variablesContainer =
137  const auto sourceType = variablesContainer.GetSourceType();
138  if (sourceType == gd::VariablesContainer::SourceType::Properties) {
139  return propertyCallback();
140  } else if (sourceType == gd::VariablesContainer::SourceType::Parameters) {
141  return parameterCallback();
142  }
143  return variableCallback();
144  } else if (ParameterMetadataTools::Has(parametersVectorsList, name))
145  return parameterCallback();
146  else if (propertiesContainersList.Has(name))
147  return propertyCallback();
148 
149  return notFoundCallback();
150  };
151 
152  void ForEachIdentifierMatchingSearch(
153  const gd::String &search,
154  std::function<void(const gd::String &name,
155  const ObjectConfiguration *objectConfiguration)>
156  objectCallback,
157  std::function<void(const gd::String &name, const gd::Variable &variable)>
158  variableCallback,
159  std::function<void(const gd::NamedPropertyDescriptor &property)>
160  propertyCallback,
161  std::function<void(const gd::ParameterMetadata &parameter)>
162  parameterCallback) const {
163  std::set<gd::String> namesAlreadySeen;
164 
165  objectsContainersList.ForEachNameMatchingSearch(
166  search,
167  [&](const gd::String &name,
168  const ObjectConfiguration *objectConfiguration) {
169  if (namesAlreadySeen.count(name) == 0) {
170  namesAlreadySeen.insert(name);
171  objectCallback(name, objectConfiguration);
172  }
173  });
174  variablesContainersList.ForEachVariableMatchingSearch(
175  search, [&](const gd::String &name, const gd::Variable &variable) {
176  if (namesAlreadySeen.count(name) == 0) {
177  namesAlreadySeen.insert(name);
178  variableCallback(name, variable);
179  }
180  });
181  gd::ParameterMetadataTools::ForEachParameterMatchingSearch(
182  parametersVectorsList,
183  search,
184  [&](const gd::ParameterMetadata &parameter) {
185  if (namesAlreadySeen.count(parameter.GetName()) == 0) {
186  namesAlreadySeen.insert(parameter.GetName());
187  parameterCallback(parameter);
188  }
189  });
190  propertiesContainersList.ForEachPropertyMatchingSearch(
191  search, [&](const gd::NamedPropertyDescriptor &property) {
192  if (namesAlreadySeen.count(property.GetName()) == 0) {
193  namesAlreadySeen.insert(property.GetName());
194  propertyCallback(property);
195  }
196  });
197  };
198 
199  const gd::ObjectsContainersList &GetObjectsContainersList() const {
200  return objectsContainersList;
201  };
202 
203  const gd::VariablesContainersList &GetVariablesContainersList() const {
204  return variablesContainersList;
205  };
206 
212  return variablesContainersList;
213  };
214 
221  return legacyGlobalVariables;
222  };
223 
230  return legacySceneVariables;
231  };
232 
233  const gd::PropertiesContainersList &GetPropertiesContainersList() const {
234  return propertiesContainersList;
235  };
236 
237  const std::vector<const ParameterMetadataContainer *> &GetParametersVectorsList() const {
238  return parametersVectorsList;
239  };
240 
241  const gd::ResourcesContainersList &GetResourcesContainersList() const {
242  return resourcesContainersList;
243  };
244 
249  const gd::String &GetScopeSceneName() const {
250  return scopeSceneName;
251  };
252 
258  return scopeExternalEventsName;
259  };
260 
266  const gd::String &externalEventsName) {
267  scopeExternalEventsName = externalEventsName;
268  return *this;
269  };
270 
276  return scopeExtensionName;
277  };
278 
284  return scopeFunctionName;
285  };
286 
292  return scopeBehaviorName;
293  };
294 
300  return scopeObjectName;
301  };
302 
306  : legacyGlobalVariables(nullptr), legacySceneVariables(nullptr){};
307 
308 private:
309  gd::ObjectsContainersList objectsContainersList;
310  gd::VariablesContainersList variablesContainersList;
311  const gd::VariablesContainer *legacyGlobalVariables;
312  const gd::VariablesContainer *legacySceneVariables;
313  gd::PropertiesContainersList propertiesContainersList;
314  std::vector<const ParameterMetadataContainer *> parametersVectorsList;
315  gd::ResourcesContainersList resourcesContainersList;
316 
317  gd::String scopeSceneName;
318  gd::String scopeExternalEventsName;
319  gd::String scopeExtensionName;
320  gd::String scopeFunctionName;
321  gd::String scopeBehaviorName;
322  gd::String scopeObjectName;
323 };
324 
325 } // 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:41
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:38
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:51
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:36
const gd::String & GetScopeExtensionName() const
Return the name of the extension in scope, or an empty string if the scope is not an extension functi...
Definition: ProjectScopedContainers.h:275
ProjectScopedContainers & SetScopeExternalEventsName(const gd::String &externalEventsName)
Set the external events name for the scope. Used by ProjectBrowserHelper when scanning external event...
Definition: ProjectScopedContainers.h:265
gd::VariablesContainersList & GetVariablesContainersList()
Allow modification of the variables containers list. This is used by code generation which does push ...
Definition: ProjectScopedContainers.h:211
const gd::VariablesContainer * GetLegacyGlobalVariables() const
Return the global variables of the current scene or the current extension. It allows legacy "globalva...
Definition: ProjectScopedContainers.h:220
const gd::String & GetScopeBehaviorName() const
Return the name of the custom behavior in scope, or an empty string if the scope is not a behavior fu...
Definition: ProjectScopedContainers.h:291
const gd::String & GetScopeObjectName() const
Return the name of the custom object in scope, or an empty string if the scope is not an object funct...
Definition: ProjectScopedContainers.h:299
ProjectScopedContainers()
Definition: ProjectScopedContainers.h:305
const gd::String & GetScopeSceneName() const
Return the name of the scene (layout) in scope, or an empty string if the scope is not a scene.
Definition: ProjectScopedContainers.h:249
const gd::String & GetScopeExternalEventsName() const
Return the name of the external events in scope, or an empty string if the scope is not external even...
Definition: ProjectScopedContainers.h:257
const gd::VariablesContainer * GetLegacySceneVariables() const
Return the scene variables of the current scene or the current extension. It allows legacy "scenevar"...
Definition: ProjectScopedContainers.h:229
const gd::String & GetScopeFunctionName() const
Return the name of the function in scope, or an empty string if the scope is not an extension functio...
Definition: ProjectScopedContainers.h:283
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:29
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:148
bool Has(const gd::String &name) const
Return true if the specified variable is in one of the containers.
Definition: VariablesContainersList.cpp:129
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:215
Definition: CommonTools.h:24