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 "VariablesContainer.h"
9 
10 namespace gd {
11 class Project;
12 class ObjectsContainer;
13 class NamedPropertyDescriptor;
14 class ParameterMetadataContainer;
15 class BaseEvent;
16 class EventsFunctionsExtension;
17 class EventsFunction;
18 class EventsBasedBehavior;
19 class EventsBasedObject;
20 } // namespace gd
21 
22 namespace gd {
23 
35  public:
37  const gd::ObjectsContainersList &objectsContainersList_,
38  const gd::VariablesContainersList &variablesContainersList_,
39  const gd::VariablesContainer *legacyGlobalVariables_,
40  const gd::VariablesContainer *legacySceneVariables_,
41  const gd::PropertiesContainersList &propertiesContainersList_)
42  : objectsContainersList(objectsContainersList_),
43  variablesContainersList(variablesContainersList_),
44  legacyGlobalVariables(legacyGlobalVariables_),
45  legacySceneVariables(legacySceneVariables_),
46  propertiesContainersList(propertiesContainersList_){};
47  virtual ~ProjectScopedContainers(){};
48 
50  MakeNewProjectScopedContainersForProjectAndLayout(const gd::Project &project,
51  const gd::Layout &layout);
52 
54  MakeNewProjectScopedContainersForProject(const gd::Project &project);
55 
60  const gd::ObjectsContainer &globalObjectsContainers,
61  const gd::ObjectsContainer &objectsContainers);
62 
64  MakeNewProjectScopedContainersForEventsFunctionsExtension(
65  const gd::Project &project,
66  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
67 
69  MakeNewProjectScopedContainersForFreeEventsFunction(
70  const gd::Project &project,
71  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
72  const gd::EventsFunction& eventsFunction,
73  gd::ObjectsContainer& parameterObjectsContainer);
74 
76  MakeNewProjectScopedContainersForBehaviorEventsFunction(
77  const gd::Project &project,
78  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
79  const gd::EventsBasedBehavior &eventsBasedBehavior,
80  const gd::EventsFunction &eventsFunction,
81  gd::ObjectsContainer &parameterObjectsContainer);
82 
84  MakeNewProjectScopedContainersForObjectEventsFunction(
85  const gd::Project &project,
86  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
87  const gd::EventsBasedObject &eventsBasedObject,
88  const gd::EventsFunction &eventsFunction,
89  gd::ObjectsContainer &parameterObjectsContainer);
90 
92  MakeNewProjectScopedContainersForEventsBasedObject(
93  const gd::Project &project,
94  const gd::EventsFunctionsExtension &eventsFunctionsExtension,
95  const gd::EventsBasedObject &eventsBasedObject,
96  gd::ObjectsContainer &outputObjectsContainer);
97 
99  MakeNewProjectScopedContainersWithLocalVariables(
100  const ProjectScopedContainers &projectScopedContainers,
101  const gd::BaseEvent &event);
102 
103  ProjectScopedContainers &AddPropertiesContainer(
104  const gd::PropertiesContainer &container) {
105  propertiesContainersList.Add(container);
106 
107  return *this;
108  }
109 
110  ProjectScopedContainers &AddParameters(
111  const ParameterMetadataContainer &parameters) {
112  parametersVectorsList.push_back(&parameters);
113 
114  return *this;
115  }
116 
117  template <class ReturnType>
118  ReturnType MatchIdentifierWithName(
119  const gd::String &name,
120  std::function<ReturnType()> objectCallback,
121  std::function<ReturnType()> variableCallback,
122  std::function<ReturnType()> propertyCallback,
123  std::function<ReturnType()> parameterCallback,
124  std::function<ReturnType()> notFoundCallback) const {
125  if (objectsContainersList.HasObjectOrGroupNamed(name))
126  return objectCallback();
127  else if (variablesContainersList.Has(name))
128  return variableCallback();
129  else if (ParameterMetadataTools::Has(parametersVectorsList, name))
130  return parameterCallback();
131  else if (propertiesContainersList.Has(name))
132  return propertyCallback();
133 
134  return notFoundCallback();
135  };
136 
137  void ForEachIdentifierMatchingSearch(
138  const gd::String &search,
139  std::function<void(const gd::String &name,
140  const ObjectConfiguration *objectConfiguration)>
141  objectCallback,
142  std::function<void(const gd::String &name, const gd::Variable &variable)>
143  variableCallback,
144  std::function<void(const gd::NamedPropertyDescriptor &property)>
145  propertyCallback,
146  std::function<void(const gd::ParameterMetadata &parameter)>
147  parameterCallback) const {
148  std::set<gd::String> namesAlreadySeen;
149 
150  objectsContainersList.ForEachNameMatchingSearch(
151  search,
152  [&](const gd::String &name,
153  const ObjectConfiguration *objectConfiguration) {
154  if (namesAlreadySeen.count(name) == 0) {
155  namesAlreadySeen.insert(name);
156  objectCallback(name, objectConfiguration);
157  }
158  });
159  variablesContainersList.ForEachVariableMatchingSearch(
160  search, [&](const gd::String &name, const gd::Variable &variable) {
161  if (namesAlreadySeen.count(name) == 0) {
162  namesAlreadySeen.insert(name);
163  variableCallback(name, variable);
164  }
165  });
166  gd::ParameterMetadataTools::ForEachParameterMatchingSearch(
167  parametersVectorsList,
168  search,
169  [&](const gd::ParameterMetadata &parameter) {
170  if (namesAlreadySeen.count(parameter.GetName()) == 0) {
171  namesAlreadySeen.insert(parameter.GetName());
172  parameterCallback(parameter);
173  }
174  });
175  propertiesContainersList.ForEachPropertyMatchingSearch(
176  search, [&](const gd::NamedPropertyDescriptor &property) {
177  if (namesAlreadySeen.count(property.GetName()) == 0) {
178  namesAlreadySeen.insert(property.GetName());
179  propertyCallback(property);
180  }
181  });
182  };
183 
184  const gd::ObjectsContainersList &GetObjectsContainersList() const {
185  return objectsContainersList;
186  };
187 
188  const gd::VariablesContainersList &GetVariablesContainersList() const {
189  return variablesContainersList;
190  };
191 
197  return variablesContainersList;
198  };
199 
206  return legacyGlobalVariables;
207  };
208 
215  return legacySceneVariables;
216  };
217 
218  const gd::PropertiesContainersList &GetPropertiesContainersList() const {
219  return propertiesContainersList;
220  };
221 
222  const std::vector<const ParameterMetadataContainer *> &GetParametersVectorsList() const {
223  return parametersVectorsList;
224  };
225 
229  : legacyGlobalVariables(nullptr), legacySceneVariables(nullptr){};
230 
231 private:
232  gd::ObjectsContainersList objectsContainersList;
233  gd::VariablesContainersList variablesContainersList;
234  const gd::VariablesContainer *legacyGlobalVariables;
235  const gd::VariablesContainer *legacySceneVariables;
236  gd::PropertiesContainersList propertiesContainersList;
237  std::vector<const ParameterMetadataContainer *> parametersVectorsList;
238 };
239 
240 } // namespace gd
Base class defining an event.
Definition: Event.h:43
Represents a behavior that is implemented with events.
Definition: EventsBasedBehavior.h:32
Represents an object that is implemented with events.
Definition: EventsBasedObject.h:30
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:38
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:51
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:34
static ProjectScopedContainers MakeNewProjectScopedContainersFor(const gd::ObjectsContainer &globalObjectsContainers, const gd::ObjectsContainer &objectsContainers)
Definition: ProjectScopedContainers.cpp:43
gd::VariablesContainersList & GetVariablesContainersList()
Allow modification of the variables containers list. This is used by code generation which does push ...
Definition: ProjectScopedContainers.h:196
const gd::VariablesContainer * GetLegacyGlobalVariables() const
Return the global variables of the current scene or the current extension. It allows legacy "globalva...
Definition: ProjectScopedContainers.h:205
ProjectScopedContainers()
Definition: ProjectScopedContainers.h:228
const gd::VariablesContainer * GetLegacySceneVariables() const
Return the scene variables of the current scene or the current extension. It allows legacy "scenevar"...
Definition: ProjectScopedContainers.h:214
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
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:26
bool Has(const gd::String &name) const
Return true if the specified variable is in one of the containers.
Definition: VariablesContainersList.cpp:58
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:116
Definition: CommonTools.h:24