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::String& GetHelpUrl() const { return helpUrl; }
230 
235  helpUrl = helpUrl_;
236  return *this;
237  }
238 
242  bool IsDeprecated() const { return isDeprecated; }
243 
247  EventsFunction& SetDeprecated(bool _isDeprecated) {
248  isDeprecated = _isDeprecated;
249  return *this;
250  }
251 
256  const gd::String& GetDeprecationMessage() const { return deprecationMessage; }
257 
263  deprecationMessage = message;
264  return *this;
265  }
266 
270  const gd::EventsList& GetEvents() const { return events; };
271 
275  gd::EventsList& GetEvents() { return events; };
276 
284  const gd::ParameterMetadataContainer& GetParametersForEvents(
285  const gd::EventsFunctionsContainer& functionsContainer) const;
286 
298  return parameters;
299  };
300 
304  ParameterMetadataContainer& GetParameters() { return parameters; };
305 
310  ObjectGroupsContainer& GetObjectGroups() { return objectGroups; }
311 
316  const ObjectGroupsContainer& GetObjectGroups() const { return objectGroups; }
317 
321 
324  void SerializeTo(gd::SerializerElement& element) const;
325 
329  void UnserializeFrom(gd::Project& project,
330  const gd::SerializerElement& element);
332 
333  private:
334  gd::String name;
335  gd::String fullName;
336  gd::String description;
337  gd::String sentence;
338  gd::String group;
339  gd::String getterName;
340  gd::ValueTypeMetadata expressionType;
341  gd::EventsList events;
342  FunctionType functionType;
343  ParameterMetadataContainer parameters;
344  mutable gd::ParameterMetadataContainer actionWithOperationParameters;
345  gd::ObjectGroupsContainer objectGroups;
346  bool isPrivate = false;
347  bool isAsync = false;
348  gd::String helpUrl;
349  bool isDeprecated = false;
350  gd::String deprecationMessage;
351 };
352 
353 } // 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:304
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:297
EventsFunction & SetAsync(bool _isAsync)
Sets the asynchronicity of the function.
Definition: EventsFunction.h:221
const gd::String & GetDeprecationMessage() const
Get the deprecation message that explains why the function is deprecated and what to use instead.
Definition: EventsFunction.h:256
const gd::EventsList & GetEvents() const
Return the events.
Definition: EventsFunction.h:270
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:310
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
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:262
FunctionType GetFunctionType() const
Get the type of the function.
Definition: EventsFunction.h:170
gd::EventsList & GetEvents()
Return the events.
Definition: EventsFunction.h:275
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
const gd::String & GetHelpUrl() const
Get the help URL for this function.
Definition: EventsFunction.h:229
EventsFunction & SetDeprecated(bool _isDeprecated)
Sets whether the function is deprecated.
Definition: EventsFunction.h:247
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
EventsFunction & SetHelpUrl(const gd::String &helpUrl_)
Set the help URL for this function.
Definition: EventsFunction.h:234
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:242
const ObjectGroupsContainer & GetObjectGroups() const
Return a const reference to the object groups that can be used in the function.
Definition: EventsFunction.h:316
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: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: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