GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
InitialInstance.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 <map>
10 
11 #include "GDCore/Project/VariablesContainer.h"
12 #include "GDCore/String.h"
13 namespace gd {
14 class PropertyDescriptor;
15 class Project;
16 class Layout;
17 class ObjectsContainer;
18 } // namespace gd
19 
20 namespace gd {
21 
26 class GD_CORE_API InitialInstance {
27  public:
32  virtual ~InitialInstance() {};
33 
39  InitialInstance* Clone() const { return new InitialInstance(*this); }
40 
45 
49  const gd::String& GetObjectName() const { return objectName; }
50 
54  void SetObjectName(const gd::String& name) { objectName = name; }
55 
59  double GetX() const { return x; }
60 
64  void SetX(double x_) { x = x_; }
65 
69  double GetY() const { return y; }
70 
74  void SetY(double y_) { y = y_; }
75 
79  double GetZ() const { return z; }
80 
84  void SetZ(double z_) { z = z_; }
85 
89  double GetAngle() const { return angle; }
90 
94  void SetAngle(double angle_) { angle = angle_; }
95 
99  double GetRotationX() const { return rotationX; }
100 
104  void SetRotationX(double rotationX_) { rotationX = rotationX_; }
105 
109  double GetRotationY() const { return rotationY; }
110 
114  void SetRotationY(double rotationY_) { rotationY = rotationY_; }
115 
119  int GetZOrder() const { return zOrder; }
120 
124  void SetZOrder(int zOrder_) { zOrder = zOrder_; }
125 
129  int GetOpacity() const { return opacity; }
130 
134  void SetOpacity(int opacity_) { opacity = opacity_; }
135 
139  bool IsFlippedX() const { return flippedX; }
140 
144  void SetFlippedX(bool flippedX_) { flippedX = flippedX_; }
145 
149  bool IsFlippedY() const { return flippedY; }
150 
154  void SetFlippedY(bool flippedY_) { flippedY = flippedY_; }
155 
159  bool IsFlippedZ() const { return flippedZ; }
160 
164  void SetFlippedZ(bool flippedZ_) { flippedZ = flippedZ_; }
165 
169  const gd::String& GetLayer() const { return layer; }
170 
174  void SetLayer(const gd::String& layer_) { layer = layer_; }
175 
183  bool HasCustomSize() const { return customSize; }
184 
191  bool HasCustomDepth() const { return customDepth; }
192 
200  void SetHasCustomSize(bool hasCustomSize_) { customSize = hasCustomSize_; }
201 
211  void SetHasCustomDepth(bool hasCustomDepth_) {
212  customDepth = hasCustomDepth_;
213  }
214 
215  double GetCustomWidth() const { return width; }
216  void SetCustomWidth(double width_) { width = width_; }
217  double GetCustomHeight() const { return height; }
218  void SetCustomHeight(double height_) { height = height_; }
219  double GetCustomDepth() const { return depth; }
220  void SetCustomDepth(double depth_) { depth = depth_; }
221 
222  double GetDefaultWidth() const { return defaultWidth; }
223  double GetDefaultHeight() const { return defaultHeight; }
224  double GetDefaultDepth() const { return defaultDepth; }
225  void SetDefaultWidth(double width_) { defaultWidth = width_; }
226  void SetDefaultHeight(double height_) { defaultHeight = height_; }
227  void SetDefaultDepth(double depth_) { defaultDepth = depth_; }
228 
233  bool IsLocked() const { return locked; };
234 
240  void SetLocked(bool enable = true) { locked = enable; }
241 
246  bool IsSealed() const { return sealed; };
247 
254  void SetSealed(bool enable = true) { sealed = enable; }
255 
260  bool ShouldKeepRatio() const { return keepRatio; };
261 
265  void SetShouldKeepRatio(bool enable = true) { keepRatio = enable; }
266 
268 
273 
279  return initialVariables;
280  }
281 
286  gd::VariablesContainer& GetVariables() { return initialVariables; }
288 
306 
313  std::map<gd::String, gd::PropertyDescriptor> GetCustomProperties(
314  gd::ObjectsContainer& globalObjectsContainer,
315  gd::ObjectsContainer& objectsContainer);
316 
322  bool UpdateCustomProperty(const gd::String& name,
323  const gd::String& value,
324  gd::ObjectsContainer& globalObjectsContainer,
325  gd::ObjectsContainer& objectsContainer);
326 
334  double GetRawDoubleProperty(const gd::String& name) const;
335 
343  const gd::String& GetRawStringProperty(const gd::String& name) const;
344 
348  void SetRawDoubleProperty(const gd::String& name, double value);
349 
353  void SetRawStringProperty(const gd::String& name, const gd::String& value);
355 
360 
363  virtual void SerializeTo(SerializerElement& element) const;
364 
368  virtual void UnserializeFrom(const SerializerElement& element);
369 
374  InitialInstance& ResetPersistentUuid();
375 
380  const gd::String& GetPersistentUuid() const { return persistentUuid; }
382 
383  private:
384  // More properties can be stored in numberProperties and stringProperties.
385  // These properties are then managed by the Object class.
386  std::map<gd::String, double>
387  numberProperties;
388  std::map<gd::String, gd::String>
389  stringProperties;
390 
391  gd::String objectName;
392  double x;
393  double y;
394  double z;
395  double angle;
396  double rotationX;
397  double rotationY;
398  int zOrder;
399  int opacity;
400  bool flippedX;
401  bool flippedY;
402  bool flippedZ;
403  gd::String layer;
404  bool customSize;
405  bool customDepth;
406  double width;
407  double height;
408  double depth;
409  double defaultWidth = 0;
410  double defaultHeight = 0;
411  double defaultDepth = 0;
412  gd::VariablesContainer initialVariables;
413  bool locked;
414  bool sealed;
415  bool keepRatio;
417  mutable gd::String persistentUuid;
419 
420  static gd::String* badStringPropertyValue;
422 };
423 
424 } // namespace gd
Represents an instance of an object to be created on a layout start up.
Definition: InitialInstance.h:26
double GetRotationY() const
Get the rotation of the instance on Y axis, in radians.
Definition: InitialInstance.h:109
double GetRotationX() const
Get the rotation of the instance on X axis, in radians.
Definition: InitialInstance.h:99
void SetY(double y_)
Set the Y position of the instance.
Definition: InitialInstance.h:74
bool ShouldKeepRatio() const
Return true if the dimensions (width, height and depth) should keep the same ratio.
Definition: InitialInstance.h:260
void SetAngle(double angle_)
Set the rotation of the instance on Z axis, in radians.
Definition: InitialInstance.h:94
const gd::String & GetPersistentUuid() const
Reset the persistent UUID used to recognize the same initial instance between serialization.
Definition: InitialInstance.h:380
void SetX(double x_)
Set the X position of the instance.
Definition: InitialInstance.h:64
gd::VariablesContainer & GetVariables()
Definition: InitialInstance.h:286
double GetZ() const
Get the Z position of the instance.
Definition: InitialInstance.h:79
bool IsFlippedX() const
Return true if the instance is flipped on X axis.
Definition: InitialInstance.h:139
void SetRotationY(double rotationY_)
Set the rotation of the instance on Y axis, in radians.
Definition: InitialInstance.h:114
bool IsLocked() const
Return true if the instance is locked and cannot be moved in the IDE.
Definition: InitialInstance.h:233
void SetFlippedY(bool flippedY_)
Set whether the instance is flipped on Y axis.
Definition: InitialInstance.h:154
bool HasCustomDepth() const
Return true if the instance has a depth which is different from its object default depth....
Definition: InitialInstance.h:191
const gd::String & GetLayer() const
Get the layer the instance belongs to.
Definition: InitialInstance.h:169
void SetFlippedZ(bool flippedZ_)
Set whether the instance is flipped on Z axis.
Definition: InitialInstance.h:164
void SetHasCustomSize(bool hasCustomSize_)
Set whether the instance has a width/height which is different from its object default width/height o...
Definition: InitialInstance.h:200
void SetObjectName(const gd::String &name)
Set the name of object instantiated on the layout.
Definition: InitialInstance.h:54
const gd::String & GetObjectName() const
Get the name of object instantiated on the layout.
Definition: InitialInstance.h:49
void SetZOrder(int zOrder_)
Set the Z order of the instance (for a 2D object).
Definition: InitialInstance.h:124
double GetY() const
Get the Y position of the instance.
Definition: InitialInstance.h:69
void SetOpacity(int opacity_)
Set the opacity of the instance.
Definition: InitialInstance.h:134
void SetRotationX(double rotationX_)
Set the rotation of the instance on X axis, in radians.
Definition: InitialInstance.h:104
void SetShouldKeepRatio(bool enable=true)
Define if instance's dimensions should keep the same ratio.
Definition: InitialInstance.h:265
void SetZ(double z_)
Set the Z position of the instance.
Definition: InitialInstance.h:84
void SetFlippedX(bool flippedX_)
Set whether the instance is flipped on X axis.
Definition: InitialInstance.h:144
bool IsSealed() const
Return true if the instance cannot be selected by clicking on it in the IDE (only applies if instance...
Definition: InitialInstance.h:246
void SetLayer(const gd::String &layer_)
Set the layer the instance belongs to.
Definition: InitialInstance.h:174
int GetOpacity() const
Get Opacity.
Definition: InitialInstance.h:129
double GetAngle() const
Get the rotation of the instance on Z axis, in radians.
Definition: InitialInstance.h:89
bool IsFlippedZ() const
Return true if the instance is flipped on Z axis.
Definition: InitialInstance.h:159
InitialInstance * Clone() const
Definition: InitialInstance.h:39
bool IsFlippedY() const
Return true if the instance is flipped on Y axis.
Definition: InitialInstance.h:149
bool HasCustomSize() const
Return true if the instance has a width/height which is different from its object default width/heigh...
Definition: InitialInstance.h:183
int GetZOrder() const
Get the Z order of the instance (for a 2D object).
Definition: InitialInstance.h:119
double GetX() const
Get the X position of the instance.
Definition: InitialInstance.h:59
void SetLocked(bool enable=true)
(Un)lock the initial instance.
Definition: InitialInstance.h:240
void SetHasCustomDepth(bool hasCustomDepth_)
Set whether the instance has a depth which is different from its object default depth or not....
Definition: InitialInstance.h:211
void SetSealed(bool enable=true)
(Un)seal the initial instance.
Definition: InitialInstance.h:254
const gd::VariablesContainer & GetVariables() const
Definition: InitialInstance.h:278
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:37
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
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:28
Definition: CommonTools.h:24