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 #pragma once
7 
8 #include <vector>
9 
10 #include "GDCore/Events/EventsList.h"
11 #include "GDCore/Project/ObjectGroupsContainer.h"
12 #include "GDCore/Project/ParameterMetadataContainer.h"
13 #include "GDCore/String.h"
14 #include "GDCore/Extensions/Metadata/ValueTypeMetadata.h"
15 // TODO: In theory (for separation of concerns between Project and
16 // extensions/events), this include should be removed and gd::ParameterMetadata
17 // replaced by a new gd::EventsFunctionParameter class.
18 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
19 namespace gd {
20 class SerializerElement;
21 class Project;
22 class EventsFunctionsContainer;
23 } // namespace gd
24 
25 namespace gd {
26 
38 class GD_CORE_API EventsFunction {
39  public:
41  virtual ~EventsFunction(){};
42 
47  EventsFunction* Clone() const { return new EventsFunction(*this); };
48 
53  const gd::String& GetDescription() const { return description; };
54 
58  EventsFunction& SetDescription(const gd::String& description_) {
59  description = description_;
60  return *this;
61  }
62 
67  const gd::String& GetName() const { return name; };
68 
74  name = name_;
75  return *this;
76  }
77 
81  const gd::String& GetFullName() const { return fullName; };
82 
86  EventsFunction& SetFullName(const gd::String& fullName_) {
87  fullName = fullName_;
88  return *this;
89  }
90 
95  const gd::String& GetSentence() const { return sentence; };
96 
101  EventsFunction& SetSentence(const gd::String& sentence_) {
102  sentence = sentence_;
103  return *this;
104  }
105 
109  const gd::String& GetGroup() const { return group; };
110 
115  group = group_;
116  return *this;
117  }
118 
123  const gd::String& GetGetterName() const { return getterName; };
124 
129  EventsFunction& SetGetterName(const gd::String& getterName_) {
130  getterName = getterName_;
131  return *this;
132  }
133 
138  expressionType = type;
139  return *this;
140  }
141 
145  const gd::ValueTypeMetadata& GetExpressionType() const { return expressionType; }
146 
150  gd::ValueTypeMetadata& GetExpressionType() { return expressionType; }
151 
152  enum FunctionType {
153  Action,
154  Condition,
155  Expression,
156  ExpressionAndCondition,
157  ActionWithOperator };
158 
162  EventsFunction& SetFunctionType(FunctionType type) {
163  functionType = type;
164  return *this;
165  }
166 
170  FunctionType GetFunctionType() const { return functionType; }
171 
175  bool IsAction() const {
176  return functionType == gd::EventsFunction::Action ||
177  functionType == gd::EventsFunction::ActionWithOperator;
178  }
179 
185  bool IsExpression() const {
186  return functionType == gd::EventsFunction::Expression ||
187  functionType == gd::EventsFunction::ExpressionAndCondition;
188  }
189 
195  bool IsCondition() const {
196  return functionType == gd::EventsFunction::Condition ||
197  functionType == gd::EventsFunction::ExpressionAndCondition;
198  }
199 
203  bool IsPrivate() const { return isPrivate; }
204 
208  EventsFunction& SetPrivate(bool _isPrivate) {
209  isPrivate = _isPrivate;
210  return *this;
211  }
212 
216  bool IsAsync() const { return isAsync; }
217 
221  EventsFunction& SetAsync(bool _isAsync) {
222  isAsync = _isAsync;
223  return *this;
224  }
225 
229  const gd::EventsList& GetEvents() const { return events; };
230 
234  gd::EventsList& GetEvents() { return events; };
235 
243  const gd::ParameterMetadataContainer& GetParametersForEvents(
244  const gd::EventsFunctionsContainer& functionsContainer) const;
245 
257  return parameters;
258  };
259 
263  ParameterMetadataContainer& GetParameters() { return parameters; };
264 
269  ObjectGroupsContainer& GetObjectGroups() { return objectGroups; }
270 
275  const ObjectGroupsContainer& GetObjectGroups() const { return objectGroups; }
276 
280 
283  void SerializeTo(gd::SerializerElement& element) const;
284 
288  void UnserializeFrom(gd::Project& project,
289  const gd::SerializerElement& element);
291 
292  private:
293  gd::String name;
294  gd::String fullName;
295  gd::String description;
296  gd::String sentence;
297  gd::String group;
298  gd::String getterName;
299  gd::ValueTypeMetadata expressionType;
300  gd::EventsList events;
301  FunctionType functionType;
302  ParameterMetadataContainer parameters;
303  mutable gd::ParameterMetadataContainer actionWithOperationParameters;
304  gd::ObjectGroupsContainer objectGroups;
305  bool isPrivate = false;
306  bool isAsync = false;
307 };
308 
309 } // namespace gd
Events that can be generated as a stand-alone function, and used as a condition, action or expression...
Definition: EventsFunction.h:38
ParameterMetadataContainer & GetParameters()
Return the parameters.
Definition: EventsFunction.h:263
const gd::String & GetFullName() const
Get the name of the function, that is displayed in the editor.
Definition: EventsFunction.h:81
const ParameterMetadataContainer & GetParameters() const
Return the parameters of the function that are filled in the editor.
Definition: EventsFunction.h:256
EventsFunction & SetAsync(bool _isAsync)
Sets the asynchronicity of the function.
Definition: EventsFunction.h:221
const gd::EventsList & GetEvents() const
Return the events.
Definition: EventsFunction.h:229
const gd::String & GetGroup() const
Get the group of the instruction in the editor.
Definition: EventsFunction.h:109
EventsFunction & SetFunctionType(FunctionType type)
Set the type of the function.
Definition: EventsFunction.h:162
EventsFunction & SetPrivate(bool _isPrivate)
Sets the privateness of the function.
Definition: EventsFunction.h:208
const gd::ValueTypeMetadata & GetExpressionType() const
Get the type of the expression.
Definition: EventsFunction.h:145
ObjectGroupsContainer & GetObjectGroups()
Return a reference to the object groups that can be used in the function.
Definition: EventsFunction.h:269
bool IsExpression() const
Return true if the function is an expression.
Definition: EventsFunction.h:185
bool IsAction() const
Return true if the function is an action.
Definition: EventsFunction.h:175
EventsFunction & SetDescription(const gd::String &description_)
Set the description of the function, to be displayed in the editor.
Definition: EventsFunction.h:58
FunctionType GetFunctionType() const
Get the type of the function.
Definition: EventsFunction.h:170
gd::EventsList & GetEvents()
Return the events.
Definition: EventsFunction.h:234
gd::ValueTypeMetadata & GetExpressionType()
Get the type of the expression.
Definition: EventsFunction.h:150
EventsFunction * Clone() const
Return a pointer to a new EventsFunction constructed from this one.
Definition: EventsFunction.h:47
EventsFunction & SetName(const gd::String &name_)
Set the name of the function, to be used for the action/condition/expression name.
Definition: EventsFunction.h:73
EventsFunction & SetGroup(const gd::String &group_)
Set the group of the instruction in the editor.
Definition: EventsFunction.h:114
bool IsAsync() const
Returns true if the function is async.
Definition: EventsFunction.h:216
bool IsCondition() const
Return true if the function is a condition.
Definition: EventsFunction.h:195
EventsFunction & SetExpressionType(const gd::ValueTypeMetadata &type)
Set the type of the expression.
Definition: EventsFunction.h:137
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:95
const gd::String & GetName() const
Get the name of the function, to be used for the action/condition/expression name.
Definition: EventsFunction.h:67
const ObjectGroupsContainer & GetObjectGroups() const
Return a const reference to the object groups that can be used in the function.
Definition: EventsFunction.h:275
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:129
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:123
bool IsPrivate() const
Returns true if the function is private.
Definition: EventsFunction.h:203
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:101
const gd::String & GetDescription() const
Get the description of the function, that is displayed in the editor.
Definition: EventsFunction.h:53
EventsFunction & SetFullName(const gd::String &fullName_)
Set the name of the function, to be displayed in the editor.
Definition: EventsFunction.h:86
Used as a base class for classes that will own events-backed functions.
Definition: EventsFunctionsContainer.h:27
A list of events.
Definition: EventsList.h:32
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
Used as a base class for classes that will own events-backed functions.
Definition: ParameterMetadataContainer.h:26
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
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