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/BehaviorsContainer.h"
14 #include "GDCore/Project/EffectsContainer.h"
15 #include "GDCore/Project/ObjectConfiguration.h"
16 #include "GDCore/Project/VariablesContainer.h"
17 #include "GDCore/String.h"
18 #include "GDCore/Tools/MakeUnique.h"
19 #include "GDCore/Vector2.h"
20 
21 namespace gd {
22 class PropertyDescriptor;
23 class Project;
24 class Layout;
25 class ArbitraryResourceWorker;
26 class InitialInstance;
27 class SerializerElement;
28 class EffectsContainer;
29 } // namespace gd
30 
31 namespace gd {
32 
38 class GD_CORE_API Object {
39  public:
43  Object(const gd::String& name,
44  const gd::String& type,
45  std::unique_ptr<gd::ObjectConfiguration> configuration);
46 
52  Object(const gd::String& name,
53  const gd::String& type,
54  gd::ObjectConfiguration* configuration);
55 
59  Object(const gd::Object& object) { Init(object); };
60 
64  Object& operator=(const gd::Object& object) {
65  if ((this) != &object) Init(object);
66  return *this;
67  }
68 
72  virtual ~Object();
73 
82  virtual std::unique_ptr<gd::Object> Clone() const {
83  return gd::make_unique<gd::Object>(*this);
84  }
85 
86  void CopyWithoutConfiguration(const gd::Object& object);
87 
91  gd::ObjectConfiguration& GetConfiguration();
92 
93  const gd::ObjectConfiguration& GetConfiguration() const;
94 
99 
102  void SetName(const gd::String& name_) { name = name_; };
103 
106  const gd::String& GetName() const { return name; };
107 
110  void SetAssetStoreId(const gd::String& assetStoreId_) {
111  assetStoreId = assetStoreId_;
112  };
113 
116  const gd::String& GetAssetStoreId() const { return assetStoreId; };
117 
120  void SetType(const gd::String& type_) { configuration->SetType(type_); }
121 
124  const gd::String& GetType() const { return configuration->GetType(); }
125 
127 
132 
137  std::vector<gd::String> GetAllBehaviorNames() const;
138 
142  Behavior& GetBehavior(const gd::String& name);
143 
147  const Behavior& GetBehavior(const gd::String& name) const;
148 
152  bool HasBehaviorNamed(const gd::String& name) const;
153 
157  void RemoveBehavior(const gd::String& name);
158 
163  bool RenameBehavior(const gd::String& name, const gd::String& newName);
164 
174  gd::Behavior* AddNewBehavior(const gd::Project& project,
175  const gd::String& type,
176  const gd::String& name);
177 
182  const std::map<gd::String, std::unique_ptr<gd::Behavior>>&
184  return behaviors.GetAllBehaviorContents();
185  };
187 
192 
196  const gd::VariablesContainer& GetVariables() const { return objectVariables; }
197 
202  gd::VariablesContainer& GetVariables() { return objectVariables; }
204 
210 
214  const gd::EffectsContainer& GetEffects() const { return effectsContainer; }
215 
220  gd::EffectsContainer& GetEffects() { return effectsContainer; }
222 
227 
231  void SerializeTo(SerializerElement& element) const;
232 
237  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
238 
243  Object& ResetPersistentUuid();
244 
249  Object& ClearPersistentUuid();
251 
252  protected:
256  std::unique_ptr<gd::ObjectConfiguration> configuration;
267 
275  void Init(const gd::Object& object);
276 };
277 
283 struct ObjectHasName : public std::binary_function<std::unique_ptr<gd::Object>,
284  gd::String,
285  bool> {
286  bool operator()(const std::unique_ptr<gd::Object>& object,
287  const gd::String& name) const {
288  return object->GetName() == name;
289  }
290 };
291 
292 } // 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
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:38
Object(const gd::Object &object)
Definition: Object.h:59
const gd::String & GetType() const
Return the type of the object.
Definition: Object.h:124
const gd::String & GetAssetStoreId() const
Return the asset store id of the object.
Definition: Object.h:116
gd::EffectsContainer effectsContainer
The effects container for the object.
Definition: Object.h:264
gd::VariablesContainer objectVariables
List of the variables of the object.
Definition: Object.h:262
void SetAssetStoreId(const gd::String &assetStoreId_)
Change the asset store id of the object.
Definition: Object.h:110
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:183
gd::VariablesContainer & GetVariables()
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:202
gd::BehaviorsContainer behaviors
Definition: Object.h:258
gd::String name
The full name of the object.
Definition: Object.h:253
void SetType(const gd::String &type_)
Change the type of the object.
Definition: Object.h:120
gd::String persistentUuid
Definition: Object.h:265
virtual std::unique_ptr< gd::Object > Clone() const
Definition: Object.h:82
gd::EffectsContainer & GetEffects()
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:220
gd::String assetStoreId
Definition: Object.h:254
void SetName(const gd::String &name_)
Change the name of the object with the name passed as parameter.
Definition: Object.h:102
Object & operator=(const gd::Object &object)
Definition: Object.h:64
const gd::String & GetName() const
Return the name of the object.
Definition: Object.h:106
const gd::VariablesContainer & GetVariables() const
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:196
const gd::EffectsContainer & GetEffects() const
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:214
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:285