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/Project/MemoryTrackedRegistry.h"
18 #include "GDCore/String.h"
19 #include "GDCore/Tools/MakeUnique.h"
20 #include "GDCore/Vector2.h"
21 
22 namespace gd {
23 class PropertyDescriptor;
24 class Project;
25 class Layout;
26 class ArbitraryResourceWorker;
27 class InitialInstance;
28 class SerializerElement;
29 class EffectsContainer;
30 } // namespace gd
31 
32 namespace gd {
33 
39 class GD_CORE_API Object {
40  public:
44  Object(const gd::String& name,
45  const gd::String& type,
46  std::unique_ptr<gd::ObjectConfiguration> configuration);
47 
53  Object(const gd::String& name,
54  const gd::String& type,
55  gd::ObjectConfiguration* configuration);
56 
60  Object(const gd::Object& object) { Init(object); };
61 
65  Object& operator=(const gd::Object& object) {
66  if ((this) != &object) Init(object);
67  return *this;
68  }
69 
73  virtual ~Object();
74 
83  virtual std::unique_ptr<gd::Object> Clone() const {
84  return gd::make_unique<gd::Object>(*this);
85  }
86 
87  void CopyWithoutConfiguration(const gd::Object& object);
88 
92  gd::ObjectConfiguration& GetConfiguration();
93 
94  const gd::ObjectConfiguration& GetConfiguration() const;
95 
100 
103  void SetName(const gd::String& name_) { name = name_; };
104 
107  const gd::String& GetName() const { return name; };
108 
111  void SetAssetStoreId(const gd::String& assetStoreId_) {
112  assetStoreId = assetStoreId_;
113  };
114 
117  const gd::String& GetAssetStoreId() const { return assetStoreId; };
118 
121  void SetType(const gd::String& type_) { configuration->SetType(type_); }
122 
125  const gd::String& GetType() const { return configuration->GetType(); }
126 
128 
133 
138  std::vector<gd::String> GetAllBehaviorNames() const;
139 
143  Behavior& GetBehavior(const gd::String& name);
144 
148  const Behavior& GetBehavior(const gd::String& name) const;
149 
153  bool HasBehaviorNamed(const gd::String& name) const;
154 
158  void RemoveBehavior(const gd::String& name);
159 
164  bool RenameBehavior(const gd::String& name, const gd::String& newName);
165 
175  gd::Behavior* AddNewBehavior(const gd::Project& project,
176  const gd::String& type,
177  const gd::String& name);
178 
183  const std::map<gd::String, std::unique_ptr<gd::Behavior>>&
185  return behaviors.GetAllBehaviorContents();
186  };
188 
193 
197  const gd::VariablesContainer& GetVariables() const { return objectVariables; }
198 
203  gd::VariablesContainer& GetVariables() { return objectVariables; }
205 
211 
215  const gd::EffectsContainer& GetEffects() const { return effectsContainer; }
216 
221  gd::EffectsContainer& GetEffects() { return effectsContainer; }
223 
228 
232  void SerializeTo(SerializerElement& element) const;
233 
238  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
239 
244  Object& ResetPersistentUuid();
245 
250  const gd::String& GetPersistentUuid() const;
252 
253  protected:
254  gd::MemoryTracked _memoryTracked{this, "gdObject"};
255 
259  std::unique_ptr<gd::ObjectConfiguration> configuration;
270 
278  void Init(const gd::Object& object);
279 };
280 
286 struct ObjectHasName : public std::binary_function<std::unique_ptr<gd::Object>,
287  gd::String,
288  bool> {
289  bool operator()(const std::unique_ptr<gd::Object>& object,
290  const gd::String& name) const {
291  return object->GetName() == name;
292  }
293 };
294 
295 } // 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
Contains effects applied to an entity on screen (i.e: a Layer or an Object).
Definition: EffectsContainer.h:30
A non-copyable, non-movable member object that registers/unregisters its owner with MemoryTrackedRegi...
Definition: MemoryTrackedRegistry.h:129
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:39
Object(const gd::Object &object)
Definition: Object.h:60
const gd::String & GetType() const
Return the type of the object.
Definition: Object.h:125
const gd::String & GetAssetStoreId() const
Return the asset store id of the object.
Definition: Object.h:117
gd::EffectsContainer effectsContainer
The effects container for the object.
Definition: Object.h:267
gd::VariablesContainer objectVariables
List of the variables of the object.
Definition: Object.h:265
void SetAssetStoreId(const gd::String &assetStoreId_)
Change the asset store id of the object.
Definition: Object.h:111
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:184
gd::VariablesContainer & GetVariables()
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:203
gd::BehaviorsContainer behaviors
Definition: Object.h:261
gd::String name
The full name of the object.
Definition: Object.h:256
void SetType(const gd::String &type_)
Change the type of the object.
Definition: Object.h:121
gd::String persistentUuid
Definition: Object.h:268
virtual std::unique_ptr< gd::Object > Clone() const
Definition: Object.h:83
gd::EffectsContainer & GetEffects()
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:221
gd::String assetStoreId
Definition: Object.h:257
void SetName(const gd::String &name_)
Change the name of the object with the name passed as parameter.
Definition: Object.h:103
Object & operator=(const gd::Object &object)
Definition: Object.h:65
const gd::String & GetName() const
Return the name of the object.
Definition: Object.h:107
const gd::VariablesContainer & GetVariables() const
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:197
const gd::EffectsContainer & GetEffects() const
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:215
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
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
Functor testing object name.
Definition: Object.h:288