GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Object.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 #ifndef GDCORE_OBJECT_H
7 #define GDCORE_OBJECT_H
8 #include <map>
9 #include <memory>
10 #include <vector>
11 
12 #include "GDCore/Project/Behavior.h"
13 #include "GDCore/Project/EffectsContainer.h"
14 #include "GDCore/Project/ObjectConfiguration.h"
15 #include "GDCore/Project/VariablesContainer.h"
16 #include "GDCore/String.h"
17 #include "GDCore/Tools/MakeUnique.h"
18 #include "GDCore/Vector2.h"
19 
20 namespace gd {
21 class PropertyDescriptor;
22 class Project;
23 class Layout;
24 class ArbitraryResourceWorker;
25 class InitialInstance;
26 class SerializerElement;
27 class EffectsContainer;
28 } // namespace gd
29 
30 namespace gd {
31 
37 class GD_CORE_API Object {
38  public:
42  Object(const gd::String& name,
43  const gd::String& type,
44  std::unique_ptr<gd::ObjectConfiguration> configuration);
45 
51  Object(const gd::String& name,
52  const gd::String& type,
53  gd::ObjectConfiguration* configuration);
54 
58  Object(const gd::Object& object) { Init(object); };
59 
63  Object& operator=(const gd::Object& object) {
64  if ((this) != &object) Init(object);
65  return *this;
66  }
67 
71  virtual ~Object();
72 
81  virtual std::unique_ptr<gd::Object> Clone() const {
82  return gd::make_unique<gd::Object>(*this);
83  }
84 
88  gd::ObjectConfiguration& GetConfiguration();
89 
90  const gd::ObjectConfiguration& GetConfiguration() const;
91 
96 
99  void SetName(const gd::String& name_) { name = name_; };
100 
103  const gd::String& GetName() const { return name; };
104 
107  void SetAssetStoreId(const gd::String& assetStoreId_) {
108  assetStoreId = assetStoreId_;
109  };
110 
113  const gd::String& GetAssetStoreId() const { return assetStoreId; };
114 
117  void SetType(const gd::String& type_) { configuration->SetType(type_); }
118 
121  const gd::String& GetType() const { return configuration->GetType(); }
122 
124 
129 
134  std::vector<gd::String> GetAllBehaviorNames() const;
135 
139  Behavior& GetBehavior(const gd::String& name);
140 
144  const Behavior& GetBehavior(const gd::String& name) const;
145 
149  bool HasBehaviorNamed(const gd::String& name) const;
150 
154  void RemoveBehavior(const gd::String& name);
155 
160  bool RenameBehavior(const gd::String& name, const gd::String& newName);
161 
171  gd::Behavior* AddNewBehavior(const gd::Project& project,
172  const gd::String& type,
173  const gd::String& name);
174 
179  const std::map<gd::String, std::unique_ptr<gd::Behavior>>&
181  return behaviors;
182  };
184 
189 
193  const gd::VariablesContainer& GetVariables() const { return objectVariables; }
194 
199  gd::VariablesContainer& GetVariables() { return objectVariables; }
201 
207 
211  const gd::EffectsContainer& GetEffects() const { return effectsContainer; }
212 
217  gd::EffectsContainer& GetEffects() { return effectsContainer; }
219 
224 
228  void SerializeTo(SerializerElement& element) const;
229 
234  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
235 
240  Object& ResetPersistentUuid();
241 
246  Object& ClearPersistentUuid();
248 
249  protected:
253  std::unique_ptr<gd::ObjectConfiguration> configuration;
254  std::map<gd::String, std::unique_ptr<gd::Behavior>>
264 
272  void Init(const gd::Object& object);
273 };
274 
280 struct ObjectHasName : public std::binary_function<std::unique_ptr<gd::Object>,
281  gd::String,
282  bool> {
283  bool operator()(const std::unique_ptr<gd::Object>& object,
284  const gd::String& name) const {
285  return object->GetName() == name;
286  }
287 };
288 
289 } // namespace gd
290 
291 #endif // GDCORE_OBJECT_H
Base class used to represents a behavior that can be applied to an object. It stores the content (i....
Definition: Behavior.h:23
Contains effects applied to an entity on screen (i.e: a Layer or an Object).
Definition: EffectsContainer.h:29
Base class used to represent an object configuration. For example, this can be the animations in a sp...
Definition: ObjectConfiguration.h:38
Represent an object of a platform.
Definition: Object.h:37
Object(const gd::Object &object)
Definition: Object.h:58
const gd::String & GetType() const
Return the type of the object.
Definition: Object.h:121
const gd::String & GetAssetStoreId() const
Return the asset store id of the object.
Definition: Object.h:113
gd::EffectsContainer effectsContainer
The effects container for the object.
Definition: Object.h:261
gd::VariablesContainer objectVariables
List of the variables of the object.
Definition: Object.h:259
void SetAssetStoreId(const gd::String &assetStoreId_)
Change the asset store id of the object.
Definition: Object.h:107
const std::map< gd::String, std::unique_ptr< gd::Behavior > > & GetAllBehaviorContents() const
Get a read-only access to the map containing the behaviors with their properties.
Definition: Object.h:180
gd::VariablesContainer & GetVariables()
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:199
gd::String name
The full name of the object.
Definition: Object.h:250
void SetType(const gd::String &type_)
Change the type of the object.
Definition: Object.h:117
gd::String persistentUuid
Definition: Object.h:262
virtual std::unique_ptr< gd::Object > Clone() const
Definition: Object.h:81
gd::EffectsContainer & GetEffects()
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:217
gd::String assetStoreId
Definition: Object.h:251
void SetName(const gd::String &name_)
Change the name of the object with the name passed as parameter.
Definition: Object.h:99
std::map< gd::String, std::unique_ptr< gd::Behavior > > behaviors
Definition: Object.h:255
Object & operator=(const gd::Object &object)
Definition: Object.h:63
const gd::String & GetName() const
Return the name of the object.
Definition: Object.h:103
const gd::VariablesContainer & GetVariables() const
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:193
const gd::EffectsContainer & GetEffects() const
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:211
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:31
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:30
Definition: CommonTools.h:24
Functor testing object name.
Definition: Object.h:282