GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
EventsFunction.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 #if defined(GD_IDE_ONLY)
7 #ifndef GDCORE_EVENTSFUNCTION_H
8 #define GDCORE_EVENTSFUNCTION_H
9 
10 #include <vector>
11 
12 #include "GDCore/Events/EventsList.h"
13 #include "GDCore/Project/ObjectGroupsContainer.h"
14 #include "GDCore/String.h"
15 #include "GDCore/Extensions/Metadata/ValueTypeMetadata.h"
16 // TODO: In theory (for separation of concerns between Project and
17 // extensions/events), this include should be removed and gd::ParameterMetadata
18 // replaced by a new gd::EventsFunctionParameter class.
19 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
20 namespace gd {
21 class SerializerElement;
22 class Project;
23 class EventsFunctionsContainer;
24 } // namespace gd
25 
26 namespace gd {
27 
39 class GD_CORE_API EventsFunction {
40  public:
42  virtual ~EventsFunction(){};
43 
48  EventsFunction* Clone() const { return new EventsFunction(*this); };
49 
54  const gd::String& GetDescription() const { return description; };
55 
59  EventsFunction& SetDescription(const gd::String& description_) {
60  description = description_;
61  return *this;
62  }
63 
68  const gd::String& GetName() const { return name; };
69 
75  name = name_;
76  return *this;
77  }
78 
82  const gd::String& GetFullName() const { return fullName; };
83 
87  EventsFunction& SetFullName(const gd::String& fullName_) {
88  fullName = fullName_;
89  return *this;
90  }
91 
96  const gd::String& GetSentence() const { return sentence; };
97 
102  EventsFunction& SetSentence(const gd::String& sentence_) {
103  sentence = sentence_;
104  return *this;
105  }
106 
110  const gd::String& GetGroup() const { return group; };
111 
116  group = group_;
117  return *this;
118  }
119 
124  const gd::String& GetGetterName() const { return getterName; };
125 
130  EventsFunction& SetGetterName(const gd::String& getterName_) {
131  getterName = getterName_;
132  return *this;
133  }
134 
139  expressionType = type;
140  return *this;
141  }
142 
146  const gd::ValueTypeMetadata& GetExpressionType() const { return expressionType; }
147 
151  gd::ValueTypeMetadata& GetExpressionType() { return expressionType; }
152 
153  enum FunctionType {
154  Action,
155  Condition,
156  Expression,
157  ExpressionAndCondition,
158  ActionWithOperator };
159 
163  EventsFunction& SetFunctionType(FunctionType type) {
164  functionType = type;
165  return *this;
166  }
167 
171  FunctionType GetFunctionType() const { return functionType; }
172 
176  bool IsAction() const {
177  return functionType == gd::EventsFunction::Action ||
178  functionType == gd::EventsFunction::ActionWithOperator;
179  }
180 
186  bool IsExpression() const {
187  return functionType == gd::EventsFunction::Expression ||
188  functionType == gd::EventsFunction::ExpressionAndCondition;
189  }
190 
196  bool IsCondition() const {
197  return functionType == gd::EventsFunction::Condition ||
198  functionType == gd::EventsFunction::ExpressionAndCondition;
199  }
200 
204  bool IsPrivate() const { return isPrivate; }
205 
209  EventsFunction& SetPrivate(bool _isPrivate) {
210  isPrivate = _isPrivate;
211  return *this;
212  }
213 
217  bool IsAsync() const { return isAsync; }
218 
222  EventsFunction& SetAsync(bool _isAsync) {
223  isAsync = _isAsync;
224  return *this;
225  }
226 
230  const gd::EventsList& GetEvents() const { return events; };
231 
235  gd::EventsList& GetEvents() { return events; };
236 
244  const std::vector<gd::ParameterMetadata>& GetParametersForEvents(
245  const gd::EventsFunctionsContainer& functionsContainer) const;
246 
257  const std::vector<gd::ParameterMetadata>& GetParameters() const {
258  return parameters;
259  };
260 
264  std::vector<gd::ParameterMetadata>& GetParameters() { return parameters; };
265 
270  ObjectGroupsContainer& GetObjectGroups() { return objectGroups; }
271 
276  const ObjectGroupsContainer& GetObjectGroups() const { return objectGroups; }
277 
281 
284  void SerializeTo(gd::SerializerElement& element) const;
285 
289  void UnserializeFrom(gd::Project& project,
290  const gd::SerializerElement& element);
292 
293  private:
294  gd::String name;
295  gd::String fullName;
296  gd::String description;
297  gd::String sentence;
298  gd::String group;
299  gd::String getterName;
300  gd::ValueTypeMetadata expressionType;
301  gd::EventsList events;
302  FunctionType functionType;
303  std::vector<gd::ParameterMetadata> parameters;
304  mutable std::vector<gd::ParameterMetadata> actionWithOperationParameters;
305  gd::ObjectGroupsContainer objectGroups;
306  bool isPrivate = false;
307  bool isAsync = false;
308 };
309 
310 } // namespace gd
311 
312 #endif // GDCORE_EVENTSFUNCTION_H
313 #endif
Events that can be generated as a stand-alone function, and used as a condition, action or expression...
Definition: EventsFunction.h:39
const gd::String & GetFullName() const
Get the name of the function, that is displayed in the editor.
Definition: EventsFunction.h:82
EventsFunction & SetAsync(bool _isAsync)
Sets the asynchronicity of the function.
Definition: EventsFunction.h:222
const gd::EventsList & GetEvents() const
Return the events.
Definition: EventsFunction.h:230
std::vector< gd::ParameterMetadata > & GetParameters()
Return the parameters.
Definition: EventsFunction.h:264
const gd::String & GetGroup() const
Get the group of the instruction in the editor.
Definition: EventsFunction.h:110
EventsFunction & SetFunctionType(FunctionType type)
Set the type of the function.
Definition: EventsFunction.h:163
EventsFunction & SetPrivate(bool _isPrivate)
Sets the privateness of the function.
Definition: EventsFunction.h:209
const gd::ValueTypeMetadata & GetExpressionType() const
Get the type of the expression.
Definition: EventsFunction.h:146
ObjectGroupsContainer & GetObjectGroups()
Return a reference to the object groups that can be used in the function.
Definition: EventsFunction.h:270
bool IsExpression() const
Return true if the function is an expression.
Definition: EventsFunction.h:186
bool IsAction() const
Return true if the function is an action.
Definition: EventsFunction.h:176
EventsFunction & SetDescription(const gd::String &description_)
Set the description of the function, to be displayed in the editor.
Definition: EventsFunction.h:59
FunctionType GetFunctionType() const
Get the type of the function.
Definition: EventsFunction.h:171
gd::EventsList & GetEvents()
Return the events.
Definition: EventsFunction.h:235
gd::ValueTypeMetadata & GetExpressionType()
Get the type of the expression.
Definition: EventsFunction.h:151
EventsFunction * Clone() const
Return a pointer to a new EventsFunction constructed from this one.
Definition: EventsFunction.h:48
EventsFunction & SetName(const gd::String &name_)
Set the name of the function, to be used for the action/condition/expression name.
Definition: EventsFunction.h:74
EventsFunction & SetGroup(const gd::String &group_)
Set the group of the instruction in the editor.
Definition: EventsFunction.h:115
bool IsAsync() const
Returns true if the function is async.
Definition: EventsFunction.h:217
bool IsCondition() const
Return true if the function is a condition.
Definition: EventsFunction.h:196
EventsFunction & SetExpressionType(const gd::ValueTypeMetadata &type)
Set the type of the expression.
Definition: EventsFunction.h:138
const std::vector< gd::ParameterMetadata > & GetParameters() const
Return the parameters of the function that are filled in the editor.
Definition: EventsFunction.h:257
const gd::String & GetSentence() const
Get the sentence of the function, that is used for the condition/action in the Events Editor.
Definition: EventsFunction.h:96
const gd::String & GetName() const
Get the name of the function, to be used for the action/condition/expression name.
Definition: EventsFunction.h:68
const ObjectGroupsContainer & GetObjectGroups() const
Return a const reference to the object groups that can be used in the function.
Definition: EventsFunction.h:276
EventsFunction & SetGetterName(const gd::String &getterName_)
Set the name of the ExpressionAndCondition to use as an operand that is defined in the editor.
Definition: EventsFunction.h:130
const gd::String & GetGetterName() const
Get the name of the ExpressionAndCondition to use as an operand that is defined in the editor.
Definition: EventsFunction.h:124
bool IsPrivate() const
Returns true if the function is private.
Definition: EventsFunction.h:204
EventsFunction & SetSentence(const gd::String &sentence_)
Set the sentence of the function, to be used for the condition/action in the Events Editor.
Definition: EventsFunction.h:102
const gd::String & GetDescription() const
Get the description of the function, that is displayed in the editor.
Definition: EventsFunction.h:54
EventsFunction & SetFullName(const gd::String &fullName_)
Set the name of the function, to be displayed in the editor.
Definition: EventsFunction.h:87
Used as a base class for classes that will own events-backed functions.
Definition: EventsFunctionsContainer.h:27
A list of events.
Definition: EventsList.h:33
Class representing an expression used as a parameter of a gd::Instruction. This class is nothing more...
Definition: Expression.h:30
A container for objects groups.
Definition: ObjectGroupsContainer.h:29
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
String represents an UTF8 encoded string.
Definition: String.h:31
Define a type for parameters of a function (action, condition or expression) or the returned value of...
Definition: ValueTypeMetadata.h:26
Definition: CommonTools.h:24