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 
131  void SetResourcesPreloading(gd::String resourcesPreloading_) {
132  resourcesPreloading = resourcesPreloading_;
133  }
134 
140  return resourcesPreloading;
141  }
142 
144 
149 
154  std::vector<gd::String> GetAllBehaviorNames() const;
155 
159  Behavior& GetBehavior(const gd::String& name);
160 
164  const Behavior& GetBehavior(const gd::String& name) const;
165 
169  bool HasBehaviorNamed(const gd::String& name) const;
170 
174  void RemoveBehavior(const gd::String& name);
175 
180  bool RenameBehavior(const gd::String& name, const gd::String& newName);
181 
191  gd::Behavior* AddNewBehavior(const gd::Project& project,
192  const gd::String& type,
193  const gd::String& name);
194 
199  const std::map<gd::String, std::unique_ptr<gd::Behavior>>&
201  return behaviors.GetAllBehaviorContents();
202  };
204 
209 
213  const gd::VariablesContainer& GetVariables() const { return objectVariables; }
214 
219  gd::VariablesContainer& GetVariables() { return objectVariables; }
221 
227 
231  const gd::EffectsContainer& GetEffects() const { return effectsContainer; }
232 
237  gd::EffectsContainer& GetEffects() { return effectsContainer; }
239 
244 
248  void SerializeTo(SerializerElement& element) const;
249 
254  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
255 
260  Object& ResetPersistentUuid();
261 
266  const gd::String& GetPersistentUuid() const;
268 
269  protected:
270  gd::MemoryTracked _memoryTracked{this, "gdObject"};
271 
275  std::unique_ptr<gd::ObjectConfiguration> configuration;
286 
287  gd::String resourcesPreloading = "with-scene";
288 
296  void Init(const gd::Object& object);
297 };
298 
304 struct ObjectHasName : public std::binary_function<std::unique_ptr<gd::Object>,
305  gd::String,
306  bool> {
307  bool operator()(const std::unique_ptr<gd::Object>& object,
308  const gd::String& name) const {
309  return object->GetName() == name;
310  }
311 };
312 
313 } // 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:238
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:283
void SetResourcesPreloading(gd::String resourcesPreloading_)
Definition: Object.h:131
gd::VariablesContainer objectVariables
List of the variables of the object.
Definition: Object.h:281
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:200
gd::VariablesContainer & GetVariables()
Provide access to the gd::VariablesContainer member containing the object variables.
Definition: Object.h:219
gd::BehaviorsContainer behaviors
Definition: Object.h:277
gd::String name
The full name of the object.
Definition: Object.h:272
void SetType(const gd::String &type_)
Change the type of the object.
Definition: Object.h:121
gd::String persistentUuid
Definition: Object.h:284
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:237
const gd::String & GetResourcesPreloading() const
Definition: Object.h:139
gd::String assetStoreId
Definition: Object.h:273
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:213
const gd::EffectsContainer & GetEffects() const
Provide access to the gd::EffectsContainer member containing the effects.
Definition: Object.h:231
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:306