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/Project/BehaviorsContainer.h"
13 #include "GDCore/String.h"
14 namespace gd {
15 class PropertyDescriptor;
16 class Project;
17 class Layout;
18 class ObjectsContainer;
19 class Object;
20 class Behavior;
21 } // namespace gd
22 
23 namespace gd {
24 
29 class GD_CORE_API InitialInstance {
30  public:
35  virtual ~InitialInstance() {};
36 
42  InitialInstance* Clone() const { return new InitialInstance(*this); }
43 
48 
52  const gd::String& GetObjectName() const { return objectName; }
53 
57  void SetObjectName(const gd::String& name) { objectName = name; }
58 
62  double GetX() const { return x; }
63 
67  void SetX(double x_) { x = x_; }
68 
72  double GetY() const { return y; }
73 
77  void SetY(double y_) { y = y_; }
78 
82  double GetZ() const { return z; }
83 
87  void SetZ(double z_) { z = z_; }
88 
92  double GetAngle() const { return angle; }
93 
97  void SetAngle(double angle_) { angle = angle_; }
98 
102  double GetRotationX() const { return rotationX; }
103 
107  void SetRotationX(double rotationX_) { rotationX = rotationX_; }
108 
112  double GetRotationY() const { return rotationY; }
113 
117  void SetRotationY(double rotationY_) { rotationY = rotationY_; }
118 
122  int GetZOrder() const { return zOrder; }
123 
127  void SetZOrder(int zOrder_) { zOrder = zOrder_; }
128 
132  int GetOpacity() const { return opacity; }
133 
137  void SetOpacity(int opacity_) { opacity = opacity_; }
138 
142  bool IsFlippedX() const { return flippedX; }
143 
147  void SetFlippedX(bool flippedX_) { flippedX = flippedX_; }
148 
152  bool IsFlippedY() const { return flippedY; }
153 
157  void SetFlippedY(bool flippedY_) { flippedY = flippedY_; }
158 
162  bool IsFlippedZ() const { return flippedZ; }
163 
167  void SetFlippedZ(bool flippedZ_) { flippedZ = flippedZ_; }
168 
172  const gd::String& GetLayer() const { return layer; }
173 
177  void SetLayer(const gd::String& layer_) { layer = layer_; }
178 
186  bool HasCustomSize() const { return customSize; }
187 
194  bool HasCustomDepth() const { return customDepth; }
195 
203  void SetHasCustomSize(bool hasCustomSize_) { customSize = hasCustomSize_; }
204 
214  void SetHasCustomDepth(bool hasCustomDepth_) {
215  customDepth = hasCustomDepth_;
216  }
217 
218  double GetCustomWidth() const { return width; }
219  void SetCustomWidth(double width_) { width = width_; }
220  double GetCustomHeight() const { return height; }
221  void SetCustomHeight(double height_) { height = height_; }
222  double GetCustomDepth() const { return depth; }
223  void SetCustomDepth(double depth_) { depth = depth_; }
224 
225  double GetDefaultWidth() const { return defaultWidth; }
226  double GetDefaultHeight() const { return defaultHeight; }
227  double GetDefaultDepth() const { return defaultDepth; }
228  void SetDefaultWidth(double width_) { defaultWidth = width_; }
229  void SetDefaultHeight(double height_) { defaultHeight = height_; }
230  void SetDefaultDepth(double depth_) { defaultDepth = depth_; }
231 
236  bool IsLocked() const { return locked; };
237 
243  void SetLocked(bool enable = true) { locked = enable; }
244 
249  bool IsSealed() const { return sealed; };
250 
257  void SetSealed(bool enable = true) { sealed = enable; }
258 
263  bool ShouldKeepRatio() const { return keepRatio; };
264 
268  void SetShouldKeepRatio(bool enable = true) { keepRatio = enable; }
269 
271 
276 
282  return initialVariables;
283  }
284 
289  gd::VariablesContainer& GetVariables() { return initialVariables; }
291 
296 
301  bool HasAnyOverriddenProperty(const gd::Object &object);
302 
307  bool HasAnyOverriddenPropertyForBehavior(const gd::Behavior &behavior);
308 
313  Behavior &GetBehaviorOverriding(const gd::String &name);
314 
319  const Behavior &GetBehaviorOverriding(const gd::String &name) const;
320 
325  bool HasBehaviorOverridingNamed(const gd::String &name) const;
326 
330  void RemoveBehaviorOverriding(const gd::String &name);
331 
336  bool RenameBehaviorOverriding(const gd::String &name,
337  const gd::String &newName);
338 
348  gd::Behavior *AddNewBehaviorOverriding(const gd::Project &project,
349  const gd::String &type,
350  const gd::String &name);
352 
370 
377  std::map<gd::String, gd::PropertyDescriptor> GetCustomProperties(
378  gd::ObjectsContainer& globalObjectsContainer,
379  gd::ObjectsContainer& objectsContainer);
380 
386  bool UpdateCustomProperty(const gd::String& name,
387  const gd::String& value,
388  gd::ObjectsContainer& globalObjectsContainer,
389  gd::ObjectsContainer& objectsContainer);
390 
398  double GetRawDoubleProperty(const gd::String& name) const;
399 
407  const gd::String& GetRawStringProperty(const gd::String& name) const;
408 
412  void SetRawDoubleProperty(const gd::String& name, double value);
413 
417  void SetRawStringProperty(const gd::String& name, const gd::String& value);
419 
424 
427  virtual void SerializeTo(SerializerElement& element) const;
428 
432  virtual void UnserializeFrom(gd::Project &project,
433  const SerializerElement &element);
434 
439  InitialInstance& ResetPersistentUuid();
440 
445  const gd::String& GetPersistentUuid() const { return persistentUuid; }
447 
448  private:
449  // More properties can be stored in numberProperties and stringProperties.
450  // These properties are then managed by the Object class.
451  std::map<gd::String, double>
452  numberProperties;
453  std::map<gd::String, gd::String>
454  stringProperties;
455 
456  gd::String objectName;
457  double x = 0;
458  double y = 0;
459  double z = 0;
460  double angle = 0;
461  double rotationX = 0;
462  double rotationY = 0;
463  int zOrder = 0;
464  int opacity = 255;
465  bool flippedX = false;
466  bool flippedY = false;
467  bool flippedZ = false;
468  gd::String layer;
469  bool customSize = false;
470  bool customDepth = false;
471  double width = 0;
472  double height = 0;
473  double depth = 0;
474  double defaultWidth = 0;
475  double defaultHeight = 0;
476  double defaultDepth = 0;
477  gd::VariablesContainer initialVariables;
479  behaviorOverridings;
482  bool locked = false;
483  bool sealed = false;
484  bool keepRatio = true;
486  mutable gd::String persistentUuid;
488 
489  static gd::String* badStringPropertyValue;
491 };
492 
493 } // namespace gd
Base class used to represents a behavior that can be applied to an object. It stores the content (i....
Definition: Behavior.h:23
Represent an behaviors container of a platform.
Definition: BehaviorsContainer.h:37
Represents an instance of an object to be created on a layout start up.
Definition: InitialInstance.h:29
double GetRotationY() const
Get the rotation of the instance on Y axis, in radians.
Definition: InitialInstance.h:112
double GetRotationX() const
Get the rotation of the instance on X axis, in radians.
Definition: InitialInstance.h:102
void SetY(double y_)
Set the Y position of the instance.
Definition: InitialInstance.h:77
bool ShouldKeepRatio() const
Return true if the dimensions (width, height and depth) should keep the same ratio.
Definition: InitialInstance.h:263
void SetAngle(double angle_)
Set the rotation of the instance on Z axis, in radians.
Definition: InitialInstance.h:97
const gd::String & GetPersistentUuid() const
Reset the persistent UUID used to recognize the same initial instance between serialization.
Definition: InitialInstance.h:445
void SetX(double x_)
Set the X position of the instance.
Definition: InitialInstance.h:67
gd::VariablesContainer & GetVariables()
Definition: InitialInstance.h:289
double GetZ() const
Get the Z position of the instance.
Definition: InitialInstance.h:82
bool IsFlippedX() const
Return true if the instance is flipped on X axis.
Definition: InitialInstance.h:142
void SetRotationY(double rotationY_)
Set the rotation of the instance on Y axis, in radians.
Definition: InitialInstance.h:117
bool IsLocked() const
Return true if the instance is locked and cannot be moved in the IDE.
Definition: InitialInstance.h:236
void SetFlippedY(bool flippedY_)
Set whether the instance is flipped on Y axis.
Definition: InitialInstance.h:157
bool HasCustomDepth() const
Return true if the instance has a depth which is different from its object default depth....
Definition: InitialInstance.h:194
const gd::String & GetLayer() const
Get the layer the instance belongs to.
Definition: InitialInstance.h:172
void SetFlippedZ(bool flippedZ_)
Set whether the instance is flipped on Z axis.
Definition: InitialInstance.h:167
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:203
void SetObjectName(const gd::String &name)
Set the name of object instantiated on the layout.
Definition: InitialInstance.h:57
const gd::String & GetObjectName() const
Get the name of object instantiated on the layout.
Definition: InitialInstance.h:52
void SetZOrder(int zOrder_)
Set the Z order of the instance (for a 2D object).
Definition: InitialInstance.h:127
double GetY() const
Get the Y position of the instance.
Definition: InitialInstance.h:72
void SetOpacity(int opacity_)
Set the opacity of the instance.
Definition: InitialInstance.h:137
void SetRotationX(double rotationX_)
Set the rotation of the instance on X axis, in radians.
Definition: InitialInstance.h:107
void SetShouldKeepRatio(bool enable=true)
Define if instance's dimensions should keep the same ratio.
Definition: InitialInstance.h:268
void SetZ(double z_)
Set the Z position of the instance.
Definition: InitialInstance.h:87
void SetFlippedX(bool flippedX_)
Set whether the instance is flipped on X axis.
Definition: InitialInstance.h:147
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:249
void SetLayer(const gd::String &layer_)
Set the layer the instance belongs to.
Definition: InitialInstance.h:177
int GetOpacity() const
Get Opacity.
Definition: InitialInstance.h:132
double GetAngle() const
Get the rotation of the instance on Z axis, in radians.
Definition: InitialInstance.h:92
bool IsFlippedZ() const
Return true if the instance is flipped on Z axis.
Definition: InitialInstance.h:162
InitialInstance * Clone() const
Definition: InitialInstance.h:42
bool IsFlippedY() const
Return true if the instance is flipped on Y axis.
Definition: InitialInstance.h:152
bool HasCustomSize() const
Return true if the instance has a width/height which is different from its object default width/heigh...
Definition: InitialInstance.h:186
int GetZOrder() const
Get the Z order of the instance (for a 2D object).
Definition: InitialInstance.h:122
double GetX() const
Get the X position of the instance.
Definition: InitialInstance.h:62
void SetLocked(bool enable=true)
(Un)lock the initial instance.
Definition: InitialInstance.h:243
void SetHasCustomDepth(bool hasCustomDepth_)
Set whether the instance has a depth which is different from its object default depth or not....
Definition: InitialInstance.h:214
void SetSealed(bool enable=true)
(Un)seal the initial instance.
Definition: InitialInstance.h:257
const gd::VariablesContainer & GetVariables() const
Definition: InitialInstance.h:281
Represent an object of a platform.
Definition: Object.h:38
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:37
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
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