GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
MultipleInstructionMetadata.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-present Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
9 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
10 #include "GDCore/String.h"
11 #include "ParameterOptions.h"
12 
13 namespace gd {} // namespace gd
14 
15 namespace gd {
16 
25  public:
26  static MultipleInstructionMetadata WithExpressionAndCondition(
27  gd::ExpressionMetadata &expression, gd::InstructionMetadata &condition) {
28  return MultipleInstructionMetadata(expression, condition);
29  }
30  static MultipleInstructionMetadata WithExpressionAndConditionAndAction(
31  gd::ExpressionMetadata &expression,
32  gd::InstructionMetadata &condition,
33  gd::InstructionMetadata &action) {
34  return MultipleInstructionMetadata(expression, condition, action);
35  }
36  static MultipleInstructionMetadata WithConditionAndAction(
38  return MultipleInstructionMetadata(condition, action);
39  }
40 
45  const gd::String &type,
46  const gd::String &label,
47  const gd::String &supplementaryInformation = "",
48  bool parameterIsOptional = false) override {
49  if (expression)
50  expression->AddParameter(
51  type, label, supplementaryInformation, parameterIsOptional);
52  if (condition)
53  condition->AddParameter(
54  type, label, supplementaryInformation, parameterIsOptional);
55  if (action)
56  action->AddParameter(
57  type, label, supplementaryInformation, parameterIsOptional);
58  return *this;
59  }
60 
65  const gd::String &type, const gd::String &supplementaryInformation) override {
66  if (expression)
67  expression->AddCodeOnlyParameter(type, supplementaryInformation);
68  if (condition)
69  condition->AddCodeOnlyParameter(type, supplementaryInformation);
70  if (action) action->AddCodeOnlyParameter(type, supplementaryInformation);
71  return *this;
72  }
73 
77  MultipleInstructionMetadata &SetDefaultValue(const gd::String &defaultValue) override {
78  if (expression) expression->SetDefaultValue(defaultValue);
79  if (condition) condition->SetDefaultValue(defaultValue);
80  if (action) action->SetDefaultValue(defaultValue);
81  return *this;
82  };
83 
88  const gd::String &defaultValue) override {
89  if (expression) expression->SetParameterExtraInfo(defaultValue);
90  if (condition) condition->SetParameterExtraInfo(defaultValue);
91  if (action) action->SetParameterExtraInfo(defaultValue);
92  return *this;
93  };
94 
99  const gd::String &longDescription) override {
100  if (expression) expression->SetParameterLongDescription(longDescription);
101  if (condition) condition->SetParameterLongDescription(longDescription);
102  if (action) action->SetParameterLongDescription(longDescription);
103  return *this;
104  };
105 
110  if (expression) expression->SetHidden();
111  if (condition) condition->SetHidden();
112  if (action) action->SetHidden();
113  return *this;
114  };
115 
121  const gd::String &message) override {
122  if (expression) expression->SetDeprecationMessage(message);
123  if (condition) condition->SetDeprecationMessage(message);
124  if (action) action->SetDeprecationMessage(message);
125  return *this;
126  }
127 
132  const gd::String &capability) {
133  if (expression) expression->SetRequiresBaseObjectCapability(capability);
134  if (condition) condition->SetRequiresBaseObjectCapability(capability);
135  if (action) action->SetRequiresBaseObjectCapability(capability);
136  return *this;
137  }
138 
144  const gd::String &type, const ParameterOptions &options) {
145  if (condition)
146  condition->UseStandardRelationalOperatorParameters(type, options);
147  if (action) action->UseStandardOperatorParameters(type, options);
148  return *this;
149  }
150 
151  MultipleInstructionMetadata &SetFunctionName(const gd::String &functionName) override {
152  if (expression) expression->SetFunctionName(functionName);
153  if (condition) condition->SetFunctionName(functionName);
154  if (action) action->SetFunctionName(functionName);
155  return *this;
156  }
157 
158  MultipleInstructionMetadata &SetGetter(const gd::String &getter) {
159  if (expression) expression->SetFunctionName(getter);
160  if (condition) condition->SetFunctionName(getter);
161  if (action) action->SetGetter(getter);
162  return *this;
163  }
164 
169  MultipleInstructionMetadata &SetIncludeFile(const gd::String &includeFile) override {
170  if (expression)
171  expression->SetIncludeFile(includeFile);
172  if (condition)
173  condition->SetIncludeFile(includeFile);
174  if (action) action->SetIncludeFile(includeFile);
175  return *this;
176  }
177 
178  MultipleInstructionMetadata &AddIncludeFile(const gd::String &includeFile) override {
179  if (expression)
180  expression->GetCodeExtraInformation().AddIncludeFile(includeFile);
181  if (condition)
182  condition->AddIncludeFile(includeFile);
183  if (action) action->AddIncludeFile(includeFile);
184  return *this;
185  }
186 
190  const std::vector<gd::String> &GetIncludeFiles() const override {
191  if (expression)
192  return expression->GetCodeExtraInformation().GetIncludeFiles();
193  if (condition)
194  return condition->GetIncludeFiles();
195  if (action) return action->GetIncludeFiles();
196  // It can't actually happen.
197  throw std::logic_error("no instruction metadata");
198  }
199 
204  if (expression) expression->SetPrivate();
205  if (condition) condition->SetPrivate();
206  if (action) action->SetPrivate();
207  return *this;
208  }
209 
214  if (expression) expression->SetHelpPath(path);
215  if (condition) condition->SetHelpPath(path);
216  if (action) action->SetHelpPath(path);
217  return *this;
218  }
219 
224  if (condition) condition->MarkAsSimple();
225  if (action) action->MarkAsSimple();
226  return *this;
227  }
228 
233  if (condition) condition->MarkAsAdvanced();
234  if (action) action->MarkAsAdvanced();
235  return *this;
236  }
237 
242  if (condition) condition->MarkAsComplex();
243  if (action) action->MarkAsComplex();
244  return *this;
245  }
246 
251  if (condition) condition->SetRelevantForLayoutEventsOnly();
252  if (action) action->SetRelevantForLayoutEventsOnly();
253  return *this;
254  }
255 
260  if (condition) condition->SetRelevantForFunctionEventsOnly();
261  if (action) action->SetRelevantForFunctionEventsOnly();
262  return *this;
263  }
264 
269  if (condition) condition->SetRelevantForAsynchronousFunctionEventsOnly();
270  if (action) action->SetRelevantForAsynchronousFunctionEventsOnly();
271  return *this;
272  }
273 
278  if (condition) condition->SetRelevantForCustomObjectEventsOnly();
279  if (action) action->SetRelevantForCustomObjectEventsOnly();
280  return *this;
281  }
282 
287  : expression(nullptr), condition(nullptr), action(nullptr){};
288 
289  private:
291  gd::InstructionMetadata &condition_)
292  : expression(&expression_), condition(&condition_), action(nullptr){};
293  MultipleInstructionMetadata(gd::ExpressionMetadata &expression_,
294  gd::InstructionMetadata &condition_,
295  gd::InstructionMetadata &action_)
296  : expression(&expression_), condition(&condition_), action(&action_){};
297  MultipleInstructionMetadata(gd::InstructionMetadata &condition_,
298  gd::InstructionMetadata &action_)
299  : expression(nullptr), condition(&condition_), action(&action_){};
300 
301  gd::ExpressionMetadata *expression;
302  gd::InstructionMetadata *condition;
303  gd::InstructionMetadata *action;
304 };
305 
306 } // namespace gd
Describe user-friendly information about an expression or an instruction (action or condition),...
Definition: AbstractFunctionMetadata.h:36
Describe user-friendly information about an expression, its parameters and the function name as well ...
Definition: ExpressionMetadata.h:47
ExpressionMetadata & SetParameterExtraInfo(const gd::String &extraInfo) override
Set the additional information, used for some parameters with special type (for example,...
Definition: ExpressionMetadata.h:243
gd::ExpressionMetadata & AddParameter(const gd::String &type, const gd::String &label, const gd::String &supplementaryInformation="", bool parameterIsOptional=false) override
Definition: ExpressionMetadata.cpp:36
ExpressionMetadata & SetHelpPath(const gd::String &path)
Definition: ExpressionMetadata.h:113
ExpressionMetadata & GetCodeExtraInformation()
Return the structure containing the information about code generation for the expression.
Definition: ExpressionMetadata.h:373
ExpressionMetadata & SetHidden() override
Set the expression as not shown in the IDE.
Definition: ExpressionMetadata.cpp:31
ExpressionMetadata & SetDeprecationMessage(const gd::String &message) override
Set the deprecation message that explains why the expression is deprecated and what to use instead.
Definition: ExpressionMetadata.h:79
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: ExpressionMetadata.h:337
ExpressionMetadata & SetDefaultValue(const gd::String &defaultValue) override
Definition: ExpressionMetadata.h:215
ExpressionMetadata & SetIncludeFile(const gd::String &includeFile) override
Erase any existing include file and add the specified include.
Definition: ExpressionMetadata.h:315
ExpressionMetadata & SetRequiresBaseObjectCapability(const gd::String &capability)
Mark this (object) expression as requiring the specified capability, offered by the base object....
Definition: ExpressionMetadata.cpp:72
ExpressionMetadata & SetFunctionName(const gd::String &functionName) override
Set the function name which will be used when generating the code.
Definition: ExpressionMetadata.h:289
ExpressionMetadata & SetParameterLongDescription(const gd::String &longDescription) override
Set the long description shown in the editor for the last added parameter.
Definition: ExpressionMetadata.h:229
gd::ExpressionMetadata & AddCodeOnlyParameter(const gd::String &type, const gd::String &supplementaryInformation) override
Definition: ExpressionMetadata.cpp:65
ExpressionMetadata & AddIncludeFile(const gd::String &includeFile) override
Add a file to the already existing include files.
Definition: ExpressionMetadata.h:325
ExpressionMetadata & SetPrivate() override
Definition: ExpressionMetadata.h:128
Describe user-friendly information about an instruction (action or condition), its parameters and the...
Definition: InstructionMetadata.h:39
InstructionMetadata & MarkAsComplex()
Consider that the instruction is complex for a user to understand.
Definition: InstructionMetadata.h:394
InstructionMetadata & SetDeprecationMessage(const gd::String &message) override
Set the deprecation message that explains why the instruction is deprecated and what to use instead.
Definition: InstructionMetadata.h:207
InstructionMetadata & UseStandardOperatorParameters(const gd::String &type, const ParameterOptions &options)
Add the default parameters for an instruction manipulating the specified type ("string",...
Definition: InstructionMetadata.cpp:96
InstructionMetadata & MarkAsSimple()
Consider that the instruction is easy for a user to understand.
Definition: InstructionMetadata.h:377
InstructionMetadata & SetDefaultValue(const gd::String &defaultValue_) override
Set the default value used in editor (or if an optional parameter is empty during code generation) fo...
Definition: InstructionMetadata.h:274
InstructionMetadata & SetRelevantForAsynchronousFunctionEventsOnly() override
Definition: InstructionMetadata.h:155
InstructionMetadata & SetHelpPath(const gd::String &path)
Definition: InstructionMetadata.h:87
InstructionMetadata & SetGetter(const gd::String &getter)
Definition: InstructionMetadata.h:512
InstructionMetadata & SetIncludeFile(const gd::String &includeFile) override
Erase any existing include file and add the specified include.
Definition: InstructionMetadata.h:530
InstructionMetadata & SetRelevantForLayoutEventsOnly() override
Definition: InstructionMetadata.h:139
InstructionMetadata & UseStandardRelationalOperatorParameters(const gd::String &type, const ParameterOptions &options)
Add the default parameters for an instruction comparing the specified type ("string",...
Definition: InstructionMetadata.cpp:161
InstructionMetadata & SetPrivate() override
Definition: InstructionMetadata.h:102
InstructionMetadata & AddIncludeFile(const gd::String &includeFile) override
Add a file to the already existing include files.
Definition: InstructionMetadata.h:539
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: InstructionMetadata.h:550
InstructionMetadata & SetParameterExtraInfo(const gd::String &extraInfo) override
Set the additional information, used for some parameters with special type (for example,...
Definition: InstructionMetadata.h:302
InstructionMetadata & SetRequiresBaseObjectCapability(const gd::String &capability)
Mark this (object) instruction as requiring the specified capability, offered by the base object....
Definition: InstructionMetadata.cpp:214
InstructionMetadata & AddParameter(const gd::String &type, const gd::String &label, const gd::String &supplementaryInformation="", bool parameterIsOptional=false) override
Add a parameter to the instruction metadata.
Definition: InstructionMetadata.cpp:55
InstructionMetadata & SetRelevantForFunctionEventsOnly() override
Definition: InstructionMetadata.h:147
InstructionMetadata & SetParameterLongDescription(const gd::String &longDescription) override
Set the long description shown in the editor for the last added parameter.
Definition: InstructionMetadata.h:287
InstructionMetadata & SetFunctionName(const gd::String &functionName_) override
Definition: InstructionMetadata.h:435
InstructionMetadata & SetRelevantForCustomObjectEventsOnly() override
Definition: InstructionMetadata.h:163
InstructionMetadata & MarkAsAdvanced()
Consider that the instruction is harder for a user to understand than a normal instruction.
Definition: InstructionMetadata.h:386
InstructionMetadata & AddCodeOnlyParameter(const gd::String &type, const gd::String &supplementaryInformation) override
Add a parameter not displayed in editor.
Definition: InstructionMetadata.cpp:85
InstructionMetadata & SetHidden() override
Set the instruction to be hidden in the IDE.
Definition: InstructionMetadata.h:198
A "composite" metadata that can be used to easily declare both an expression and a related condition ...
Definition: MultipleInstructionMetadata.h:24
MultipleInstructionMetadata & SetRequiresBaseObjectCapability(const gd::String &capability)
Definition: MultipleInstructionMetadata.h:131
MultipleInstructionMetadata & SetRelevantForLayoutEventsOnly() override
Definition: MultipleInstructionMetadata.h:250
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: MultipleInstructionMetadata.h:190
MultipleInstructionMetadata & SetDefaultValue(const gd::String &defaultValue) override
Definition: MultipleInstructionMetadata.h:77
MultipleInstructionMetadata & AddParameter(const gd::String &type, const gd::String &label, const gd::String &supplementaryInformation="", bool parameterIsOptional=false) override
Definition: MultipleInstructionMetadata.h:44
MultipleInstructionMetadata & SetIncludeFile(const gd::String &includeFile) override
Definition: MultipleInstructionMetadata.h:169
MultipleInstructionMetadata & SetRelevantForCustomObjectEventsOnly() override
Definition: MultipleInstructionMetadata.h:277
MultipleInstructionMetadata & UseStandardParameters(const gd::String &type, const ParameterOptions &options)
Definition: MultipleInstructionMetadata.h:143
MultipleInstructionMetadata & MarkAsSimple()
Definition: MultipleInstructionMetadata.h:223
MultipleInstructionMetadata & SetRelevantForAsynchronousFunctionEventsOnly() override
Definition: MultipleInstructionMetadata.h:268
MultipleInstructionMetadata & SetParameterLongDescription(const gd::String &longDescription) override
Definition: MultipleInstructionMetadata.h:98
MultipleInstructionMetadata & AddCodeOnlyParameter(const gd::String &type, const gd::String &supplementaryInformation) override
Definition: MultipleInstructionMetadata.h:64
MultipleInstructionMetadata & SetDeprecationMessage(const gd::String &message) override
Set the deprecation message that explains why the instruction is deprecated and what to use instead.
Definition: MultipleInstructionMetadata.h:120
MultipleInstructionMetadata & MarkAsAdvanced()
Definition: MultipleInstructionMetadata.h:232
MultipleInstructionMetadata & SetRelevantForFunctionEventsOnly() override
Definition: MultipleInstructionMetadata.h:259
MultipleInstructionMetadata & SetHelpPath(const gd::String &path)
Definition: MultipleInstructionMetadata.h:213
MultipleInstructionMetadata & SetFunctionName(const gd::String &functionName) override
Set the function that should be called when generating the source code from events.
Definition: MultipleInstructionMetadata.h:151
MultipleInstructionMetadata & AddIncludeFile(const gd::String &includeFile) override
Add a file to the already existing include files.
Definition: MultipleInstructionMetadata.h:178
MultipleInstructionMetadata & SetParameterExtraInfo(const gd::String &defaultValue) override
Definition: MultipleInstructionMetadata.h:87
MultipleInstructionMetadata & SetPrivate() override
Definition: MultipleInstructionMetadata.h:203
MultipleInstructionMetadata()
Don't use, only here to fulfill Emscripten bindings requirements.
Definition: MultipleInstructionMetadata.h:286
MultipleInstructionMetadata & MarkAsComplex()
Definition: MultipleInstructionMetadata.h:241
MultipleInstructionMetadata & SetHidden() override
Definition: MultipleInstructionMetadata.h:109
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24
Definition: ParameterOptions.h:15