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 
118  group = group_;
119  return *this;
120  }
121 
126  const gd::String& GetGetterName() const { return getterName; };
127 
132  EventsFunction& SetGetterName(const gd::String& getterName_) {
133  getterName = getterName_;
134  return *this;
135  }
136 
141  expressionType = type;
142  return *this;
143  }
144 
148  const gd::ValueTypeMetadata& GetExpressionType() const { return expressionType; }
149 
153  gd::ValueTypeMetadata& GetExpressionType() { return expressionType; }
154 
155  enum FunctionType {
156  Action,
157  Condition,
158  Expression,
159  ExpressionAndCondition,
160  ActionWithOperator };
161 
165  EventsFunction& SetFunctionType(FunctionType type) {
166  functionType = type;
167  return *this;
168  }
169 
173  FunctionType GetFunctionType() const { return functionType; }
174 
178  bool IsAction() const {
179  return functionType == gd::EventsFunction::Action ||
180  functionType == gd::EventsFunction::ActionWithOperator;
181  }
182 
188  bool IsExpression() const {
189  return functionType == gd::EventsFunction::Expression ||
190  functionType == gd::EventsFunction::ExpressionAndCondition;
191  }
192 
198  bool IsCondition() const {
199  return functionType == gd::EventsFunction::Condition ||
200  functionType == gd::EventsFunction::ExpressionAndCondition;
201  }
202 
206  bool IsPrivate() const { return isPrivate; }
207 
211  EventsFunction& SetPrivate(bool _isPrivate) {
212  isPrivate = _isPrivate;
213  return *this;
214  }
215 
219  bool IsAsync() const { return isAsync; }
220 
224  EventsFunction& SetAsync(bool _isAsync) {
225  isAsync = _isAsync;
226  return *this;
227  }
228 
232  const gd::String& GetHelpUrl() const { return helpUrl; }
233 
238  helpUrl = helpUrl_;
239  return *this;
240  }
241 
245  bool IsDeprecated() const { return isDeprecated; }
246 
250  EventsFunction& SetDeprecated(bool _isDeprecated) {
251  isDeprecated = _isDeprecated;
252  return *this;
253  }
254 
259  const gd::String& GetDeprecationMessage() const { return deprecationMessage; }
260 
266  deprecationMessage = message;
267  return *this;
268  }
269 
273  const gd::EventsList& GetEvents() const { return events; };
274 
278  gd::EventsList& GetEvents() { return events; };
279 
287  const gd::ParameterMetadataContainer& GetParametersForEvents(
288  const gd::EventsFunctionsContainer& functionsContainer) const;
289 
301  return parameters;
302  };
303 
307  ParameterMetadataContainer& GetParameters() { return parameters; };
308 
313  ObjectGroupsContainer& GetObjectGroups() { return objectGroups; }
314 
319  const ObjectGroupsContainer& GetObjectGroups() const { return objectGroups; }
320 
324 
327  void SerializeTo(gd::SerializerElement& element) const;
328 
332  void UnserializeFrom(gd::Project& project,
333  const gd::SerializerElement& element);
335 
336  private:
337  gd::String name;
338  gd::String fullName;
339  gd::String description;
340  gd::String sentence;
341  gd::String group;
342  gd::String getterName;
343  gd::ValueTypeMetadata expressionType;
344  gd::EventsList events;
345  FunctionType functionType;
346  ParameterMetadataContainer parameters;
347  mutable gd::ParameterMetadataContainer actionWithOperationParameters;
348  gd::ObjectGroupsContainer objectGroups;
349  bool isPrivate = false;
350  bool isAsync = false;
351  gd::String helpUrl;
352  bool isDeprecated = false;
353  gd::String deprecationMessage;
354 };
355 
356 } // 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:307
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:300
EventsFunction & SetAsync(bool _isAsync)
Sets the asynchronicity of the function.
Definition: EventsFunction.h:224
const gd::String & GetDeprecationMessage() const
Get the deprecation message that explains why the function is deprecated and what to use instead.
Definition: EventsFunction.h:259
const gd::EventsList & GetEvents() const
Return the events.
Definition: EventsFunction.h:273
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:165
EventsFunction & SetPrivate(bool _isPrivate)
Sets the privateness of the function.
Definition: EventsFunction.h:211
const gd::ValueTypeMetadata & GetExpressionType() const
Get the type of the expression.
Definition: EventsFunction.h:148
ObjectGroupsContainer & GetObjectGroups()
Return a reference to the object groups that can be used in the function.
Definition: EventsFunction.h:313
bool IsExpression() const
Return true if the function is an expression.
Definition: EventsFunction.h:188
bool IsAction() const
Return true if the function is an action.
Definition: EventsFunction.h:178
EventsFunction & SetDescription(const gd::String &description_)
Set the description of the function, to be displayed in the editor.
Definition: EventsFunction.h:58
EventsFunction & SetDeprecationMessage(const gd::String &message)
Set the deprecation message that explains why the function is deprecated and what to use instead.
Definition: EventsFunction.h:265
FunctionType GetFunctionType() const
Get the type of the function.
Definition: EventsFunction.h:173
gd::EventsList & GetEvents()
Return the events.
Definition: EventsFunction.h:278
gd::ValueTypeMetadata & GetExpressionType()
Get the type of the expression.
Definition: EventsFunction.h:153
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:117
bool IsAsync() const
Returns true if the function is async.
Definition: EventsFunction.h:219
bool IsCondition() const
Return true if the function is a condition.
Definition: EventsFunction.h:198
const gd::String & GetHelpUrl() const
Get the help URL for this function.
Definition: EventsFunction.h:232
EventsFunction & SetDeprecated(bool _isDeprecated)
Sets whether the function is deprecated.
Definition: EventsFunction.h:250
EventsFunction & SetExpressionType(const gd::ValueTypeMetadata &type)
Set the type of the expression.
Definition: EventsFunction.h:140
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
EventsFunction & SetHelpUrl(const gd::String &helpUrl_)
Set the help URL for this function.
Definition: EventsFunction.h:237
const gd::String & GetName() const
Get the name of the function, to be used for the action/condition/expression name.
Definition: EventsFunction.h:67
bool IsDeprecated() const
Returns true if the function is deprecated.
Definition: EventsFunction.h:245
const ObjectGroupsContainer & GetObjectGroups() const
Return a const reference to the object groups that can be used in the function.
Definition: EventsFunction.h:319
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:132
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:126
bool IsPrivate() const
Returns true if the function is private.
Definition: EventsFunction.h:206
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:30
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