GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
PropertiesContainer.h
1 #pragma once
2 #include "EventsFunctionsContainer.h"
3 #include "GDCore/Project/PropertyFolderOrProperty.h"
4 #include "GDCore/Tools/SerializableWithNameList.h"
5 #include "NamedPropertyDescriptor.h"
6 
7 namespace gd {
8 
18 public:
19  PropertiesContainer(EventsFunctionsContainer::FunctionOwner owner);
20 
22 
23  PropertiesContainer &operator=(const PropertiesContainer &other);
24 
25  NamedPropertyDescriptor &Insert(const NamedPropertyDescriptor &element,
26  size_t position = (size_t)-1);
27  NamedPropertyDescriptor &InsertNew(const gd::String &name,
28  size_t position = (size_t)-1);
29  bool Has(const gd::String &name) const;
30  NamedPropertyDescriptor &Get(const gd::String &name);
31  const NamedPropertyDescriptor &Get(const gd::String &name) const;
32  NamedPropertyDescriptor &Get(size_t index);
33  const NamedPropertyDescriptor &Get(size_t index) const;
34  void Remove(const gd::String &name);
35  void Move(std::size_t oldIndex, std::size_t newIndex);
36  size_t GetCount() const;
37  std::size_t GetPosition(const NamedPropertyDescriptor &element) const;
38  bool IsEmpty() const;
39  size_t size() const { return GetCount(); }
40  NamedPropertyDescriptor &at(size_t index) { return Get(index); };
41  bool empty() const { return IsEmpty(); }
42  const std::vector<std::unique_ptr<NamedPropertyDescriptor>>& GetInternalVector() const;
43  std::vector<std::unique_ptr<NamedPropertyDescriptor>>& GetInternalVector();
44  void SerializeElementsTo(const gd::String& elementName,
45  SerializerElement& element) const;
46  void UnserializeElementsFrom(const gd::String& elementName,
47  const SerializerElement& element);
48 
49  void ForEachPropertyMatchingSearch(
50  const gd::String &search,
51  std::function<void(const gd::NamedPropertyDescriptor &property)> fn)
52  const {
53  for (const auto &property : properties.GetInternalVector()) {
54  if (property->GetName().FindCaseInsensitive(search) != gd::String::npos)
55  fn(*property);
56  }
57  }
58 
59  EventsFunctionsContainer::FunctionOwner GetOwner() const { return owner; }
60 
68  const gd::String &name,
69  gd::PropertyFolderOrProperty &propertyFolderOrProperty,
70  std::size_t position);
71 
77  std::vector<const PropertyFolderOrProperty *>
79 
80  gd::PropertyFolderOrProperty &GetRootFolder() { return *rootFolder; }
81 
82  void AddMissingPropertiesInRootFolder();
83 
87  void SerializeFoldersTo(SerializerElement &element) const;
88 
92  void UnserializeFoldersFrom(gd::Project &project,
93  const SerializerElement &element);
94 
95 private:
96  EventsFunctionsContainer::FunctionOwner owner;
98  std::unique_ptr<gd::PropertyFolderOrProperty> rootFolder;
99 };
100 
101 } // namespace gd
Used to describe a property shown in a property grid.
Definition: NamedPropertyDescriptor.h:21
const gd::String & GetName() const
Get the name of the property.
Definition: NamedPropertyDescriptor.h:47
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
A container of properties, used for custom behaviors, custom objects, extensions.....
Definition: PropertiesContainer.h:17
std::vector< const PropertyFolderOrProperty * > GetAllPropertyFolderOrProperty() const
Definition: PropertiesContainer.cpp:112
void SerializeFoldersTo(SerializerElement &element) const
Serialize folder structure.
Definition: PropertiesContainer.cpp:154
gd::NamedPropertyDescriptor & InsertNewPropertyInFolder(const gd::String &name, gd::PropertyFolderOrProperty &propertyFolderOrProperty, std::size_t position)
Add a new empty property called name in the given folder at the specified position.
Definition: PropertiesContainer.cpp:101
void UnserializeFoldersFrom(gd::Project &project, const SerializerElement &element)
Unserialize folder structure.
Definition: PropertiesContainer.cpp:158
Class representing a folder structure in order to organize properties in folders (to be used with a P...
Definition: PropertyFolderOrProperty.h:30
A class template that store a list of elements that can be accessed by their names and serialized.
Definition: SerializableWithNameList.h:33
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
size_type FindCaseInsensitive(const String &search, size_type pos=0) const
Do a case-insensitive search.
Definition: String.cpp:663
Definition: CommonTools.h:24