GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
InitialInstancesContainer.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 
7 #pragma once
8 
9 #include <list>
10 #include "GDCore/Project/InitialInstance.h"
11 #include "GDCore/String.h"
12 namespace gd {
13 class InitialInstanceFunctor;
14 }
15 namespace gd {
16 class Project;
17 }
18 namespace gd {
19 class SerializerElement;
20 }
21 
22 namespace gd {
23 
38 class GD_CORE_API InitialInstancesContainer {
39  public:
41  virtual ~InitialInstancesContainer();
42 
54  return new InitialInstancesContainer(*this);
55  };
56 
72  void Create(const InitialInstancesContainer &source);
73 
78 
82  std::size_t GetInstancesCount() const;
83 
88  void IterateOverInstances(InitialInstanceFunctor &func);
89 
98  void IterateOverInstancesWithZOrdering(InitialInstanceFunctor &func,
99  const gd::String &layer);
100 
105  InitialInstance &InsertInitialInstance(const InitialInstance &instance);
106 
111  InitialInstance &InsertNewInitialInstance();
112 
116  void RemoveInstance(const gd::InitialInstance &instance);
117 
121  void RemoveAllInstancesOnLayer(const gd::String &layerName);
122 
126  void MoveInstancesToLayer(const gd::String &fromLayer,
127  const gd::String &toLayer);
128 
132  void RemoveInitialInstancesOfObject(const gd::String &objectName);
133 
137  void RenameInstancesOfObject(const gd::String &oldName,
138  const gd::String &newName);
139 
143  std::size_t GetLayerInstancesCount(const gd::String &layerName) const;
144 
149  bool SomeInstancesAreOnLayer(const gd::String &layerName) const;
150 
154  bool HasInstancesOfObject(const gd::String &objectName) const;
155 
159  bool
160  IsInstancesCountOfObjectGreaterThan(const gd::String &objectName,
161  const std::size_t minInstanceCount) const;
162 
166  void Clear();
167 
169 
174 
178  virtual void SerializeTo(SerializerElement &element) const;
179 
183  virtual void UnserializeFrom(const SerializerElement &element);
185 
186  private:
187  void RemoveInstanceIf(
188  std::function<bool(const gd::InitialInstance &)> predicate);
189 
190  std::list<gd::InitialInstance> initialInstances;
191 
192  static gd::InitialInstance badPosition;
193 };
194 
202 class GD_CORE_API InitialInstanceFunctor {
203  public:
205  virtual ~InitialInstanceFunctor();
206 
207  virtual void operator()(InitialInstance &instance) = 0;
208 };
209 
217  public:
219  : highestZOrder(0),
220  lowestZOrder(0),
221  instancesCount(0),
222  firstCall(true),
223  layerRestricted(false){};
224  virtual ~HighestZOrderFinder(){};
225 
226  virtual void operator()(gd::InitialInstance &instance);
227 
231  void RestrictSearchToLayer(const gd::String &layerName_) {
232  layerName = layerName_;
233  layerRestricted = true;
234  };
235 
240  int GetHighestZOrder() const { return highestZOrder; }
241 
246  int GetLowestZOrder() const { return lowestZOrder; }
247 
252  size_t GetInstancesCount() const { return instancesCount; }
253 
254  void Reset() {
255  highestZOrder = 0;
256  lowestZOrder = 0;
257  instancesCount = 0;
258  firstCall = true;
259  layerRestricted = false;
260  layerName.clear();
261  }
262 
263  private:
264  int highestZOrder;
265  int lowestZOrder;
266  size_t instancesCount;
267  bool firstCall;
268 
269  bool layerRestricted;
271  gd::String layerName;
272 };
273 
274 } // namespace gd
Tool class picking returning the highest Z order of instances on a layer.
Definition: InitialInstancesContainer.h:216
void RestrictSearchToLayer(const gd::String &layerName_)
Restrict to instances on the specified layer.
Definition: InitialInstancesContainer.h:231
int GetHighestZOrder() const
After calling the instances container iterate method with this functor, this method will return the h...
Definition: InitialInstancesContainer.h:240
int GetLowestZOrder() const
After calling the instances container iterate method with this functor, this method will return the l...
Definition: InitialInstancesContainer.h:246
size_t GetInstancesCount() const
After calling the instances container iterate method with this functor, this method will return the n...
Definition: InitialInstancesContainer.h:252
Tool class to be used with gd::InitialInstancesContainer::IterateOverInstances.
Definition: InitialInstancesContainer.h:202
Represents an instance of an object to be created on a layout start up.
Definition: InitialInstance.h:26
Defines a container of gd::InitialInstances.
Definition: InitialInstancesContainer.h:38
InitialInstancesContainer * Clone() const
Return a pointer to a copy of the container. A such method is needed as the IDE may want to store cop...
Definition: InitialInstancesContainer.h:53
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24