GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ObjectsContainersList.h
1 #pragma once
2 #include <vector>
3 
4 #include "Variable.h"
5 #include "GDCore/Project/ObjectsContainer.h"
6 
7 namespace gd {
8 class String;
9 class Project;
10 class Layout;
11 class VariablesContainer;
12 class Object;
13 class ObjectConfiguration;
14 } // namespace gd
15 
16 namespace gd {
17 
29 class GD_CORE_API ObjectsContainersList {
30  public:
31  virtual ~ObjectsContainersList(){};
32 
33  static ObjectsContainersList MakeNewEmptyObjectsContainersList();
34 
35  static ObjectsContainersList MakeNewObjectsContainersListForProjectAndLayout(
36  const gd::Project& project, const gd::Layout& layout);
37 
38  static ObjectsContainersList MakeNewObjectsContainersListForProject(
39  const gd::Project& project);
40 
41  static ObjectsContainersList MakeNewObjectsContainersListForContainers(
42  const gd::ObjectsContainer& globalObjectsContainer,
43  const gd::ObjectsContainer& objectsContainer);
44 
45  static ObjectsContainersList MakeNewObjectsContainersListForContainer(
46  const gd::ObjectsContainer& objectsContainer);
47 
51  bool HasObjectOrGroupNamed(const gd::String& name) const;
52 
56  bool HasObjectNamed(const gd::String& name) const;
57 
58  enum VariableExistence {
59  DoesNotExist,
60  Exists,
61  GroupIsEmpty,
62  ExistsOnlyOnSomeObjectsOfTheGroup
63  };
64 
69  VariableExistence HasObjectOrGroupWithVariableNamed(
70  const gd::String& objectOrGroupName,
71  const gd::String& variableName) const;
72 
77  bool HasObjectOrGroupVariablesContainer(
78  const gd::String& objectOrGroupName,
79  const gd::VariablesContainer& variablesContainer) const;
80 
85  const gd::VariablesContainer* GetObjectOrGroupVariablesContainer(
86  const gd::String& objectOrGroupName) const;
87 
91  gd::Variable::Type GetTypeOfObjectOrGroupVariable(const gd::String& objectOrGroupName, const gd::String& variableName) const;
92 
101  gd::String GetTypeOfObject(const gd::String& objectName) const;
102 
106  bool HasBehaviorInObjectOrGroup(const gd::String& objectOrGroupName,
107  const gd::String& behaviorName) const;
108 
114  const gd::String& objectOrGroupName,
115  const gd::String& behaviorName,
116  bool searchInGroups = true) const;
117 
123  gd::String GetTypeOfBehavior(const gd::String& behaviorName,
124  bool searchInGroups = true) const;
125 
133  std::vector<gd::String> GetBehaviorsOfObject(
134  const gd::String& objectName, bool searchInGroups = true) const;
135 
143  std::vector<gd::String>
144  GetBehaviorNamesInObjectOrGroup(const gd::String &objectOrGroupName,
145  const gd::String &behaviorType,
146  bool searchInGroups = true) const;
147 
155  std::vector<gd::String>
156  GetAnimationNamesOfObject(const gd::String &objectOrGroupName) const;
157 
167  std::vector<gd::String> ExpandObjectName(
168  const gd::String& objectOrGroupName,
169  const gd::String& onlyObjectToSelectIfPresent = "") const;
170 
171  void ForEachObject(std::function<void(const gd::Object& object)> fn) const;
172 
177  void ForEachNameMatchingSearch(
178  const gd::String& search,
179  std::function<void(const gd::String& name,
180  const gd::ObjectConfiguration* objectConfiguration)>
181  fn) const;
182 
187  void ForEachObjectOrGroupVariableMatchingSearch(
188  const gd::String& objectOrGroupName,
189  const gd::String& search,
190  std::function<void(const gd::String& variableName,
191  const gd::Variable& variable)> fn) const;
192 
197  const gd::ObjectsContainer::SourceType GetObjectsContainerSourceType(
198  const gd::String& objectOrGroupName) const;
199 
203  const ObjectsContainer *
204  GetObjectsContainerFromObjectName(const gd::String &objectOrGroupName) const;
205 
216  const gd::ObjectsContainer &GetObjectsContainer(std::size_t index) const;
217 
221  std::size_t GetObjectsContainersCount() const;
222 
226 
227  private:
228  const gd::Object* GetObject(const gd::String& name) const;
229 
230  bool HasObjectWithVariableNamed(const gd::String& objectName,
231  const gd::String& variableName) const;
232 
233  bool HasObjectVariablesContainer(
234  const gd::String& objectName,
235  const gd::VariablesContainer& variablesContainer) const;
236 
237  const gd::VariablesContainer* GetObjectVariablesContainer(
238  const gd::String& objectName) const;
239 
240  gd::Variable::Type GetTypeOfObjectVariable(const gd::String& objectName, const gd::String& variableName) const;
241 
242  void ForEachObjectVariableMatchingSearch(
243  const gd::String& objectOrGroupName,
244  const gd::String& search,
245  std::function<void(const gd::String& variableName,
246  const gd::Variable& variable)> fn) const;
247 
248  void Add(const gd::ObjectsContainer& objectsContainer) {
249  objectsContainers.push_back(&objectsContainer);
250  };
251 
252  std::vector<const gd::ObjectsContainer*> objectsContainers;
253 };
254 
255 } // namespace gd
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:40
Base class used to represent an object configuration. For example, this can be the animations in a sp...
Definition: ObjectConfiguration.h:38
Represent an object of a platform.
Definition: Object.h:37
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
ObjectsContainersList()
Definition: ObjectsContainersList.h:225
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
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
Type
Definition: Variable.h:32
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:28
Definition: CommonTools.h:24
gd::String GD_CORE_API GetTypeOfObject(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, gd::String name, bool searchInGroups)
Get a type from an object/group name.
Definition: Layout.cpp:422
std::vector< gd::String > GD_CORE_API GetBehaviorNamesInObjectOrGroup(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &objectOrGroupName, const gd::String &behaviorType, bool searchInGroups)
Get the names of behavior of a given type if an object or all objects of a group has it.
Definition: Layout.cpp:510
gd::String GD_CORE_API GetTypeOfBehaviorInObjectOrGroup(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &objectOrGroupName, const gd::String &behaviorName, bool searchInGroups)
Get the type of a behavior if an object or all objects of a group has it.
Definition: Layout.cpp:677
gd::String GD_CORE_API GetTypeOfBehavior(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, gd::String name, bool searchInGroups)
Get a type from a behavior name.
Definition: Layout.cpp:732
vector< gd::String > GD_CORE_API GetBehaviorsOfObject(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &name, bool searchInGroups)
Get behaviors of an object/group.
Definition: Layout.cpp:754
bool GD_CORE_API HasBehaviorInObjectOrGroup(const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout, const gd::String &objectOrGroupName, const gd::String &behaviorName, bool searchInGroups)
Check if an object or all objects of a group has a behavior.
Definition: Layout.cpp:579