-
Notifications
You must be signed in to change notification settings - Fork 716
/
EventsFunction.h
172 lines (148 loc) · 4.4 KB
/
EventsFunction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#if defined(GD_IDE_ONLY)
#ifndef GDCORE_EVENTSFUNCTION_H
#define GDCORE_EVENTSFUNCTION_H
#include <vector>
#include "GDCore/Events/EventsList.h"
#include "GDCore/String.h"
// TODO: In theory (for separation of concerns between Project and
// extensions/events), this include should be removed and gd::ParameterMetadata
// replaced by a new gd::EventsFunctionParameter class.
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
namespace gd {
class SerializerElement;
class Project;
} // namespace gd
namespace gd {
/**
* \brief Events that can be generated as a stand-alone function, and used
* as a condition, action or expression.
*
* \note The code generation can be done using gd::EventsCodeGenerator
*
* \note The conversion to an extension is not in GDCore and should be done
* by the IDE (see EventsFunctionsExtensionsLoader)
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API EventsFunction {
public:
EventsFunction();
virtual ~EventsFunction(){};
/**
* \brief Return a pointer to a new EventsFunction constructed from
* this one.
*/
EventsFunction* Clone() const { return new EventsFunction(*this); };
/**
* \brief Get the description of the function, that is displayed in the
* editor.
*/
const gd::String& GetDescription() const { return description; };
/**
* \brief Set the description of the function, to be displayed in the editor.
*/
EventsFunction& SetDescription(const gd::String& description_) {
description = description_;
return *this;
}
/**
* \brief Get the name of the function, to be used for the
* action/condition/expression name.
*/
const gd::String& GetName() const { return name; };
/**
* \brief Set the name of the function, to be used for the
* action/condition/expression name.
*/
EventsFunction& SetName(const gd::String& name_) {
name = name_;
return *this;
}
/**
* \brief Get the name of the function, that is displayed in the editor.
*/
const gd::String& GetFullName() const { return fullName; };
/**
* \brief Set the name of the function, to be displayed in the editor.
*/
EventsFunction& SetFullName(const gd::String& fullName_) {
fullName = fullName_;
return *this;
}
/**
* \brief Get the sentence of the function, that is used for the
* condition/action in the Events Editor.
*/
const gd::String& GetSentence() const { return sentence; };
/**
* \brief Set the sentence of the function, to be used for the
* condition/action in the Events Editor.
*/
EventsFunction& SetSentence(const gd::String& sentence_) {
sentence = sentence_;
return *this;
}
enum FunctionType { Action, Condition, Expression, StringExpression };
/**
* \brief Set the type of the function
*/
EventsFunction& SetFunctionType(FunctionType type) {
functionType = type;
return *this;
};
/**
* \brief Get the type of the function
*/
FunctionType GetFunctionType() const { return functionType; };
/**
* \brief Return the events.
*/
const gd::EventsList& GetEvents() const { return events; };
/**
* \brief Return the events.
*/
gd::EventsList& GetEvents() { return events; };
/**
* \brief Return the parameters of the function.
*
* \note During code/extension generation, new parameters are added
* to the generated function, like "runtimeScene" and "eventsFunctionContext".
* This should be transparent to the user.
*/
const std::vector<gd::ParameterMetadata>& GetParameters() const {
return parameters;
};
/**
* \brief Return the parameters.
*/
std::vector<gd::ParameterMetadata>& GetParameters() { return parameters; };
/** \name Serialization
*/
///@{
/**
* \brief Serialize the EventsFunction to the specified element
*/
void SerializeTo(gd::SerializerElement& element) const;
/**
* \brief Load the EventsFunction from the specified element
*/
void UnserializeFrom(gd::Project& project,
const gd::SerializerElement& element);
///@}
private:
gd::String name;
gd::String fullName;
gd::String description;
gd::String sentence;
gd::EventsList events;
FunctionType functionType;
std::vector<gd::ParameterMetadata> parameters;
};
} // namespace gd
#endif // GDCORE_EVENTSFUNCTION_H
#endif