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 #pragma once
7 
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 
85  void CopyWithoutConfiguration(const gd::Object& object);
86 
90  gd::ObjectConfiguration& GetConfiguration();
91 
92  const gd::ObjectConfiguration& GetConfiguration() const;
93 
98 
101  void SetName(const gd::String& name_) { name = name_; };
102 
105  const gd::String& GetName() const { return name; };
106 
109  void SetAssetStoreId(const gd::String& assetStoreId_) {
110  assetStoreId = assetStoreId_;
111  };
112 
115  const gd::String& GetAssetStoreId() const { return assetStoreId; };
116 
119  void SetType(const gd::String& type_) { configuration->SetType(type_); }
120 
123  const gd::String& GetType() const { return configuration->GetType(); }
124 
126 
131 
136  std::vector<gd::String> GetAllBehaviorNames() const;
137 
141  Behavior& GetBehavior(const gd::String& name);
142 
146  const Behavior& GetBehavior(const gd::String& name) const;
147 
151  bool HasBehaviorNamed(const gd::String& name) const;
152 
156  void RemoveBehavior(const gd::String& name);
157 
162  bool RenameBehavior(const gd::String& name, const gd::String& newName);
163 
173  gd::Behavior* AddNewBehavior(const gd::Project& project,
174  const gd::String& type,
175  const gd::String& name);
176 
181  const std::map<gd::String, std::unique_ptr<gd::Behavior>>&
183  return behaviors;
184  };
186 
191 
195  const gd::VariablesContainer& GetVariables() const { return objectVariables; }
196 
201  gd::VariablesContainer& GetVariables() { return objectVariables; }
203 
209 
213  const gd::EffectsContainer& GetEffects() const { return effectsContainer; }
214 
219  gd::EffectsContainer& GetEffects() { return effectsContainer; }
221 
226 
230  void SerializeTo(SerializerElement& element) const;
231 
236  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
237 
242  Object& ResetPersistentUuid();
243 
248  Object& ClearPersistentUuid();
250 
251  protected:
255  std::unique_ptr<gd::ObjectConfiguration> configuration;
256  std::map<gd::String, std::unique_ptr<gd::Behavior>>
266 
274  void Init(const gd::Object& object);
275 };
276 
282 struct ObjectHasName : public std::binary_function<std::unique_ptr<gd::Object>,
283  gd::String,
284  bool> {
285  bool operator()(const std::unique_ptr<gd::Object>& object,
286  const gd::String& name) const {
287  return object->GetName() == name;
288  }
289 };
290 
291 } // 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
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:123
const gd::String & GetAssetStoreId() const
Return the asset store id of the object.
Definition: Object.h:115
gd::EffectsContainer effectsContainer
The effects container for the object.
Definition: Object.h:263
gd::VariablesContainer objectVariables
List of the variables of the object.
Definition: Object.h:261
void SetAssetStoreId(const gd::String &assetStoreId_)
Change the asset store id of the object.
Definition: Object.h:109
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:182
gd::VariablesContainer & GetVariables()
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:201
gd::String name
The full name of the object.
Definition: Object.h:252
void SetType(const gd::String &type_)
Change the type of the object.
Definition: Object.h:119
gd::String persistentUuid
Definition: Object.h:264
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:219
gd::String assetStoreId
Definition: Object.h:253
void SetName(const gd::String &name_)
Change the name of the object with the name passed as parameter.
Definition: Object.h:101
std::map< gd::String, std::unique_ptr< gd::Behavior > > behaviors
Definition: Object.h:257
Object & operator=(const gd::Object &object)
Definition: Object.h:63
const gd::String & GetName() const
Return the name of the object.
Definition: Object.h:105
const gd::VariablesContainer & GetVariables() const
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:195
const gd::EffectsContainer & GetEffects() const
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:213
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
Functor testing object name.
Definition: Object.h:284