GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ObjectsContainer.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <memory>
9 #include <vector>
10 #include <set>
11 #include "GDCore/String.h"
12 #include "GDCore/Project/ObjectGroupsContainer.h"
13 #include "GDCore/Project/ObjectFolderOrObject.h"
14 namespace gd {
15 class Object;
16 class Project;
17 class SerializerElement;
18 } // namespace gd
19 #undef GetObject // Disable an annoying macro
20 
21 namespace gd {
22 
37 class GD_CORE_API ObjectsContainer {
38  public:
39  enum SourceType {
40  Unknown,
41  Global,
42  Scene,
43  Object,
44  Function,
45  };
46 
50  ObjectsContainer(const SourceType sourceType);
51  virtual ~ObjectsContainer();
52 
54  ObjectsContainer& operator=(const ObjectsContainer& rhs);
55 
56  SourceType GetSourceType() const { return sourceType; }
57 
62 
66  bool HasObjectNamed(const gd::String& name) const;
67 
71  gd::Object& GetObject(const gd::String& name);
72 
76  const gd::Object& GetObject(const gd::String& name) const;
77 
82  gd::Object& GetObject(std::size_t index);
83 
88  const gd::Object& GetObject(std::size_t index) const;
89 
98  std::size_t GetObjectPosition(const gd::String& name) const;
99 
103  std::size_t GetObjectsCount() const;
104 
112  gd::Object& InsertNewObject(const gd::Project& project,
113  const gd::String& objectType,
114  const gd::String& name,
115  std::size_t position);
123  gd::Object& InsertNewObjectInFolder(
124  const gd::Project& project,
125  const gd::String& objectType,
126  const gd::String& name,
127  gd::ObjectFolderOrObject& objectFolderOrObject,
128  std::size_t position);
129 
139  gd::Object& InsertObject(const gd::Object& object, std::size_t position);
140 
148  void RemoveObject(const gd::String& name);
149 
153  void MoveObject(std::size_t oldIndex, std::size_t newIndex);
154 
163  void MoveObjectFolderOrObjectToAnotherContainerInFolder(
164  gd::ObjectFolderOrObject& objectFolderOrObject,
165  gd::ObjectsContainer& newContainer,
166  gd::ObjectFolderOrObject& newParentFolder,
167  std::size_t newPosition);
168 
172  std::vector<std::unique_ptr<gd::Object> >& GetObjects() {
173  return initialObjects;
174  }
175 
179  const std::vector<std::unique_ptr<gd::Object> >& GetObjects() const {
180  return initialObjects;
181  }
182 
183  std::set<gd::String> GetAllObjectNames() const;
185 
191  std::vector<const ObjectFolderOrObject*> GetAllObjectFolderOrObjects() const;
192 
193  gd::ObjectFolderOrObject& GetRootFolder() {
194  return *rootFolder;
195  }
196 
197  void AddMissingObjectsInRootFolder();
198 
203 
206  void SerializeObjectsTo(SerializerElement& element) const;
207 
211  void UnserializeObjectsFrom(gd::Project& project,
212  const SerializerElement& element);
216  void SerializeFoldersTo(SerializerElement& element) const;
217 
221  void UnserializeFoldersFrom(gd::Project& project,
222  const SerializerElement& element);
224 
229 
233  ObjectGroupsContainer& GetObjectGroups() { return objectGroups; }
234 
238  const ObjectGroupsContainer& GetObjectGroups() const { return objectGroups; }
239 
241 
242  protected:
243  std::vector<std::unique_ptr<gd::Object> >
245  gd::ObjectGroupsContainer objectGroups;
246 
247  private:
248  SourceType sourceType = Unknown;
249  std::unique_ptr<gd::ObjectFolderOrObject> rootFolder;
250 
255  void Init(const ObjectsContainer& other);
256 };
257 
258 } // namespace gd
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:40
Class representing a folder structure in order to organize objects in folders (to be used with an Obj...
Definition: ObjectFolderOrObject.h:30
A container for objects groups.
Definition: ObjectGroupsContainer.h:29
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
std::vector< std::unique_ptr< gd::Object > > & GetObjects()
Definition: ObjectsContainer.h:172
const ObjectGroupsContainer & GetObjectGroups() const
Return a const reference to the project's objects groups.
Definition: ObjectsContainer.h:238
const std::vector< std::unique_ptr< gd::Object > > & GetObjects() const
Definition: ObjectsContainer.h:179
std::vector< std::unique_ptr< gd::Object > > initialObjects
Objects contained.
Definition: ObjectsContainer.h:244
ObjectGroupsContainer & GetObjectGroups()
Return a reference to the project's objects groups.
Definition: ObjectsContainer.h:233
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
Definition: CommonTools.h:24