GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
BehaviorsContainer.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/EffectsContainer.h"
14 #include "GDCore/Project/MemoryTrackedRegistry.h"
15 #include "GDCore/Project/ObjectConfiguration.h"
16 #include "GDCore/Project/VariablesContainer.h"
17 #include "GDCore/String.h"
18 #include "GDCore/Tools/MakeUnique.h"
19 #include "GDCore/Vector2.h"
20 
21 namespace gd {
22 class PropertyDescriptor;
23 class Project;
24 class Layout;
25 class ArbitraryResourceWorker;
26 class InitialInstance;
27 class SerializerElement;
28 class EffectsContainer;
29 } // namespace gd
30 
31 namespace gd {
32 
38 class GD_CORE_API BehaviorsContainer {
39 public:
43  BehaviorsContainer(bool isOverriding = false);
44 
48  BehaviorsContainer(const gd::BehaviorsContainer &behaviorsContainer) {
49  Init(behaviorsContainer);
50  };
51 
56  operator=(const gd::BehaviorsContainer &behaviorsContainer) {
57  if ((this) != &behaviorsContainer)
58  Init(behaviorsContainer);
59  return *this;
60  }
61 
65  virtual ~BehaviorsContainer();
66 
71 
76  std::vector<gd::String> GetAllBehaviorNames() const;
77 
81  Behavior &GetBehavior(const gd::String &name);
82 
86  const Behavior &GetBehavior(const gd::String &name) const;
87 
91  bool HasBehaviorNamed(const gd::String &name) const;
92 
96  void RemoveBehavior(const gd::String &name);
97 
102  bool RenameBehavior(const gd::String &name, const gd::String &newName);
103 
113  gd::Behavior *AddNewBehavior(const gd::Project &project,
114  const gd::String &type, const gd::String &name);
115 
120  const std::map<gd::String, std::unique_ptr<gd::Behavior>> &
122  return behaviors;
123  };
125 
130 
134  void SerializeTo(SerializerElement &element) const;
135 
140  void UnserializeFrom(gd::Project &project, const SerializerElement &element);
141 
142 protected:
143  bool isOverriding = false;
144  std::map<gd::String, std::unique_ptr<gd::Behavior>>
148 
156  void Init(const gd::BehaviorsContainer &behaviorsContainer);
157 
158 private:
159  gd::MemoryTracked _memoryTracked{this, "BehaviorsContainer"};
160 };
161 
162 } // 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
BehaviorsContainer & operator=(const gd::BehaviorsContainer &behaviorsContainer)
Definition: BehaviorsContainer.h:56
BehaviorsContainer(const gd::BehaviorsContainer &behaviorsContainer)
Definition: BehaviorsContainer.h:48
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: BehaviorsContainer.h:121
std::map< gd::String, std::unique_ptr< gd::Behavior > > behaviors
Definition: BehaviorsContainer.h:145
A non-copyable, non-movable member object that registers/unregisters its owner with MemoryTrackedRegi...
Definition: MemoryTrackedRegistry.h:238
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
Definition: CommonTools.h:24