GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
CustomObjectConfiguration.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 "GDCore/Project/ObjectConfiguration.h"
9 
10 #include <map>
11 #include <memory>
12 #include <unordered_set>
13 #include "GDCore/Project/Object.h"
14 #include "GDCore/Project/Project.h"
15 #include "GDCore/Project/EventsBasedObject.h"
16 #include "GDCore/Project/PropertyDescriptor.h"
17 #include "GDCore/Serialization/Serializer.h"
18 #include "GDCore/Serialization/SerializerElement.h"
19 #include "GDCore/Extensions/Builtin/SpriteExtension/SpriteAnimationList.h"
20 
21 using namespace gd;
22 
23 namespace gd {
32 public:
33  CustomObjectConfiguration(const Project &project_, const String &type_)
34  : project(&project_) {
35  SetType(type_);
36  }
37  std::unique_ptr<gd::ObjectConfiguration> Clone() const override;
38 
43  : ObjectConfiguration(object) {
44  Init(object);
45  };
46 
51  if ((this) != &object) {
52  ObjectConfiguration::operator=(object);
53  Init(object);
54  }
55  return *this;
56  }
57 
58  std::map<gd::String, gd::PropertyDescriptor> GetProperties() const override;
59  bool UpdateProperty(const gd::String& name, const gd::String& value) override;
60  bool RenameProperty(const gd::String& oldName, const gd::String& newName) override;
61 
62  std::map<gd::String, gd::PropertyDescriptor> GetInitialInstanceProperties(
63  const gd::InitialInstance& instance) override;
65  const gd::String& name,
66  const gd::String& value) override;
67 
68  void ExposeResources(gd::ArbitraryResourceWorker& worker) override;
69 
70 
74  const gd::String &GetVariantName() const { return variantName; };
75 
79  void SetVariantName(const gd::String &variantName_) {
80  variantName = variantName_;
81  }
82 
93 
94  bool IsMarkedAsOverridingEventsBasedObjectChildrenConfiguration() const {
95  return isMarkedAsOverridingEventsBasedObjectChildrenConfiguration;
96  }
97 
98  void SetMarkedAsOverridingEventsBasedObjectChildrenConfiguration(
99  bool isOverridingEventsBasedObjectChildrenConfiguration_) {
100  isMarkedAsOverridingEventsBasedObjectChildrenConfiguration =
101  isOverridingEventsBasedObjectChildrenConfiguration_;
102  }
103 
104  void ClearChildrenConfiguration();
105 
107  GetChildObjectConfiguration(const gd::String &objectName);
108 
109  std::size_t GetAnimationsCount() const override;
110 
111  const gd::String &GetAnimationName(size_t index) const override;
112 
113  bool HasAnimationNamed(const gd::String &animationName) const override;
114 
118  const SpriteAnimationList& GetAnimations() const;
119 
124 
125  enum EdgeAnchor {
126  NoAnchor = 0,
127  MinEdge = 1,
128  MaxEdge = 2,
129  Proportional = 3,
130  Center = 4,
131  };
132 
133  static const gd::CustomObjectConfiguration::EdgeAnchor
134  GetEdgeAnchorFromString(const gd::String &value);
135 
141  bool IsChildObjectFolded(const gd::String& childName) const {
142  return unfoldedChildren.find(childName) == unfoldedChildren.end();
143  }
144 
150  void SetChildObjectFolded(const gd::String& childName, bool folded) {
151  if (!folded)
152  unfoldedChildren.insert(childName);
153  else
154  unfoldedChildren.erase(childName);
155  }
156 
157 protected:
158  void DoSerializeTo(SerializerElement& element) const override;
159  void DoUnserializeFrom(Project& project, const SerializerElement& element) override;
160 
161  private:
162  const gd::EventsBasedObject* GetEventsBasedObject() const;
163 
164  bool IsOverridingEventsBasedObjectChildrenConfiguration() const;
165 
166  const Project* project = nullptr;
168  gd::SerializerElement objectContent;
169  std::unordered_set<gd::String> unfoldedChildren;
170 
171  gd::String variantName = "";
172  bool isMarkedAsOverridingEventsBasedObjectChildrenConfiguration = false;
173  mutable std::map<gd::String, std::unique_ptr<gd::ObjectConfiguration>> childObjectConfigurations;
174 
175  static gd::ObjectConfiguration badObjectConfiguration;
176 
177  SpriteAnimationList animations;
178 
188  void Init(const gd::CustomObjectConfiguration& object);
189 };
190 
191 } // namespace gd
ArbitraryResourceWorker is used so as to inventory resources and sometimes update them.
Definition: ArbitraryResourceWorker.h:44
A gd::ObjectConfiguration that stores its content in JSON and is composed of other configuration acco...
Definition: CustomObjectConfiguration.h:31
void SetChildObjectFolded(const gd::String &childName, bool folded)
Definition: CustomObjectConfiguration.h:150
void ExposeResources(gd::ArbitraryResourceWorker &worker) override
Called ( e.g. during compilation ) so as to inventory internal resources and sometimes update their f...
Definition: CustomObjectConfiguration.cpp:217
bool UpdateProperty(const gd::String &name, const gd::String &value) override
Called when the IDE wants to update a custom property of the object configuration.
Definition: CustomObjectConfiguration.cpp:119
void DoUnserializeFrom(Project &project, const SerializerElement &element) override
Derived object configuration can redefine this method to load custom attributes.
Definition: CustomObjectConfiguration.cpp:194
void DoSerializeTo(SerializerElement &element) const override
Derived object configuration can redefine this method to save custom attributes.
Definition: CustomObjectConfiguration.cpp:173
std::size_t GetAnimationsCount() const override
Return the number of animations declared in this object configuration.
Definition: CustomObjectConfiguration.cpp:293
bool IsForcedToOverrideEventsBasedObjectChildrenConfiguration() const
Definition: CustomObjectConfiguration.cpp:50
CustomObjectConfiguration(const gd::CustomObjectConfiguration &object)
Definition: CustomObjectConfiguration.h:42
void SetVariantName(const gd::String &variantName_)
Set the name of the events-based object variant used by this custom object.
Definition: CustomObjectConfiguration.h:79
std::map< gd::String, gd::PropertyDescriptor > GetProperties() const override
Called when the IDE wants to know about the custom properties of the object configuration.
Definition: CustomObjectConfiguration.cpp:108
const SpriteAnimationList & GetAnimations() const
Return the animation configuration for Animatable custom objects.
Definition: CustomObjectConfiguration.cpp:307
bool IsChildObjectFolded(const gd::String &childName) const
Definition: CustomObjectConfiguration.h:141
std::map< gd::String, gd::PropertyDescriptor > GetInitialInstanceProperties(const gd::InitialInstance &instance) override
Called when the IDE wants to know about the custom properties of an initial instance of this object c...
Definition: CustomObjectConfiguration.cpp:149
CustomObjectConfiguration & operator=(const gd::CustomObjectConfiguration &object)
Definition: CustomObjectConfiguration.h:50
const gd::String & GetVariantName() const
Get the name of the events-based object variant used by this custom object.
Definition: CustomObjectConfiguration.h:74
const gd::String & GetAnimationName(size_t index) const override
Return the name of an animation declared in this object configuration.
Definition: CustomObjectConfiguration.cpp:298
bool UpdateInitialInstanceProperty(gd::InitialInstance &instance, const gd::String &name, const gd::String &value) override
Called when the IDE wants to update a custom property of an initial instance of this object configura...
Definition: CustomObjectConfiguration.cpp:162
bool RenameProperty(const gd::String &oldName, const gd::String &newName) override
Called when the IDE wants to rename a custom property of the object configuration.
Definition: CustomObjectConfiguration.cpp:134
bool HasAnimationNamed(const gd::String &animationName) const override
Return true if an animation is declared in this object configuration for a given name.
Definition: CustomObjectConfiguration.cpp:302
std::unique_ptr< gd::ObjectConfiguration > Clone() const override
Definition: CustomObjectConfiguration.cpp:38
Represents an object that is implemented with events.
Definition: EventsBasedObject.h:32
Represents an instance of an object to be created on a layout start up.
Definition: InitialInstance.h:29
Base class used to represent an object configuration. For example, this can be the animations in a sp...
Definition: ObjectConfiguration.h:38
void SetType(const gd::String &type_)
Change the type of the object.
Definition: ObjectConfiguration.h:64
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
A list of animations, containing directions with images and collision mask.
Definition: SpriteAnimationList.h:30
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24