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 
273  bool IsHidden() const { return hidden; };
274 
281  void SetHidden(bool enable = true) { hidden = enable; }
282 
284 
289 
295  return initialVariables;
296  }
297 
302  gd::VariablesContainer& GetVariables() { return initialVariables; }
304 
309 
314  bool HasAnyOverriddenProperty(const gd::Object &object);
315 
320  bool HasAnyOverriddenPropertyForBehavior(const gd::Behavior &behavior);
321 
326  Behavior &GetBehaviorOverriding(const gd::String &name);
327 
332  const Behavior &GetBehaviorOverriding(const gd::String &name) const;
333 
338  bool HasBehaviorOverridingNamed(const gd::String &name) const;
339 
343  void RemoveBehaviorOverriding(const gd::String &name);
344 
349  bool RenameBehaviorOverriding(const gd::String &name,
350  const gd::String &newName);
351 
361  gd::Behavior *AddNewBehaviorOverriding(const gd::Project &project,
362  const gd::String &type,
363  const gd::String &name);
365 
383 
390  std::map<gd::String, gd::PropertyDescriptor> GetCustomProperties(
391  gd::ObjectsContainer& globalObjectsContainer,
392  gd::ObjectsContainer& objectsContainer);
393 
399  bool UpdateCustomProperty(const gd::String& name,
400  const gd::String& value,
401  gd::ObjectsContainer& globalObjectsContainer,
402  gd::ObjectsContainer& objectsContainer);
403 
411  double GetRawDoubleProperty(const gd::String& name) const;
412 
420  const gd::String& GetRawStringProperty(const gd::String& name) const;
421 
425  void SetRawDoubleProperty(const gd::String& name, double value);
426 
430  void SetRawStringProperty(const gd::String& name, const gd::String& value);
432 
437 
440  virtual void SerializeTo(SerializerElement& element) const;
441 
445  virtual void UnserializeFrom(gd::Project &project,
446  const SerializerElement &element);
447 
452  InitialInstance& ResetPersistentUuid();
453 
458  const gd::String& GetPersistentUuid() const { return persistentUuid; }
460 
461  private:
462  // More properties can be stored in numberProperties and stringProperties.
463  // These properties are then managed by the Object class.
464  std::map<gd::String, double>
465  numberProperties;
466  std::map<gd::String, gd::String>
467  stringProperties;
468 
469  gd::String objectName;
470  double x = 0;
471  double y = 0;
472  double z = 0;
473  double angle = 0;
474  double rotationX = 0;
475  double rotationY = 0;
476  int zOrder = 0;
477  int opacity = 255;
478  bool flippedX = false;
479  bool flippedY = false;
480  bool flippedZ = false;
481  gd::String layer;
482  bool customSize = false;
483  bool customDepth = false;
484  double width = 0;
485  double height = 0;
486  double depth = 0;
487  double defaultWidth = 0;
488  double defaultHeight = 0;
489  double defaultDepth = 0;
490  gd::VariablesContainer initialVariables;
492  behaviorOverridings;
495  bool locked = false;
496  bool sealed = false;
497  bool keepRatio = true;
499  bool hidden = false;
501  mutable gd::String persistentUuid;
503 
504  static gd::String* badStringPropertyValue;
506 };
507 
508 } // namespace gd
Base class used to represents a behavior that can be applied to an object. It stores the content (i....
Definition: Behavior.h:24
Represent an behaviors container of a platform.
Definition: BehaviorsContainer.h:38
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:458
void SetX(double x_)
Set the X position of the instance.
Definition: InitialInstance.h:67
gd::VariablesContainer & GetVariables()
Definition: InitialInstance.h:302
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
bool IsHidden() const
Return true if the instance is hidden when the scene starts.
Definition: InitialInstance.h:273
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
void SetHidden(bool enable=true)
Set if the instance is hidden when the scene starts.
Definition: InitialInstance.h:281
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:294
Represent an object of a platform.
Definition: Object.h:39
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:38
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:52
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:29
Definition: CommonTools.h:24