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 "GDCore/Project/Object.h"
13 #include "GDCore/Project/Project.h"
14 #include "GDCore/Project/EventsBasedObject.h"
15 #include "GDCore/Project/PropertyDescriptor.h"
16 #include "GDCore/Serialization/Serializer.h"
17 #include "GDCore/Serialization/SerializerElement.h"
18 #include "GDCore/Extensions/Builtin/SpriteExtension/SpriteAnimationList.h"
19 
20 using namespace gd;
21 
22 namespace gd {
31  public:
32  CustomObjectConfiguration(const Project& project_, const String& type_)
33  : project(&project_) {
34  SetType(type_);
35  }
36  std::unique_ptr<gd::ObjectConfiguration> Clone() const override;
37 
42  : ObjectConfiguration(object) {
43  Init(object);
44  };
45 
50  if ((this) != &object) {
51  ObjectConfiguration::operator=(object);
52  Init(object);
53  }
54  return *this;
55  }
56 
57  std::map<gd::String, gd::PropertyDescriptor> GetProperties() const override;
58  bool UpdateProperty(const gd::String& name, const gd::String& value) override;
59 
60  std::map<gd::String, gd::PropertyDescriptor> GetInitialInstanceProperties(
61  const gd::InitialInstance& instance,
62  gd::Project& project,
63  gd::Layout& scene) override;
65  const gd::String& name,
66  const gd::String& value,
67  gd::Project& project,
68  gd::Layout& scene) override;
69 
70  void ExposeResources(gd::ArbitraryResourceWorker& worker) override;
71 
72  gd::ObjectConfiguration &GetChildObjectConfiguration(const gd::String& objectName);
73 
77  const SpriteAnimationList& GetAnimations() const;
78 
83 
84 protected:
85  void DoSerializeTo(SerializerElement& element) const override;
86  void DoUnserializeFrom(Project& project, const SerializerElement& element) override;
87 
88  private:
89  const Project* project;
91  gd::SerializerElement objectContent;
92  std::map<gd::String, std::unique_ptr<gd::ObjectConfiguration>> childObjectConfigurations;
93 
94  static gd::ObjectConfiguration badObjectConfiguration;
95 
96  SpriteAnimationList animations;
97 
107  void Init(const gd::CustomObjectConfiguration& object);
108 };
109 
110 } // 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:30
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:151
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:76
void DoUnserializeFrom(Project &project, const SerializerElement &element) override
Derived object configuration can redefine this method to load custom attributes.
Definition: CustomObjectConfiguration.cpp:133
void DoSerializeTo(SerializerElement &element) const override
Derived object configuration can redefine this method to save custom attributes.
Definition: CustomObjectConfiguration.cpp:117
std::map< gd::String, gd::PropertyDescriptor > GetInitialInstanceProperties(const gd::InitialInstance &instance, gd::Project &project, gd::Layout &scene) override
Called when the IDE wants to know about the custom properties of an initial instance of this object c...
Definition: CustomObjectConfiguration.cpp:92
CustomObjectConfiguration(const gd::CustomObjectConfiguration &object)
Definition: CustomObjectConfiguration.h:41
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:65
const SpriteAnimationList & GetAnimations() const
Return the animation configuration for Animatable custom objects.
Definition: CustomObjectConfiguration.cpp:207
CustomObjectConfiguration & operator=(const gd::CustomObjectConfiguration &object)
Definition: CustomObjectConfiguration.h:49
bool UpdateInitialInstanceProperty(gd::InitialInstance &instance, const gd::String &name, const gd::String &value, gd::Project &project, gd::Layout &scene) override
Called when the IDE wants to update a custom property of an initial instance of this object configura...
Definition: CustomObjectConfiguration.cpp:106
std::unique_ptr< gd::ObjectConfiguration > Clone() const override
Definition: CustomObjectConfiguration.cpp:34
Represents an instance of an object to be created on a layout start up.
Definition: InitialInstance.h:25
Represent a layout ( also called a scene ) of a project.
Definition: Layout.h:39
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:31
Definition: CommonTools.h:24