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  const gd::String &hint) override {
111  if (expression) expression->SetParameterHint(hint);
112  if (condition) condition->SetParameterHint(hint);
113  if (action) action->SetParameterHint(hint);
114  return *this;
115  };
116 
121  if (expression) expression->SetHidden();
122  if (condition) condition->SetHidden();
123  if (action) action->SetHidden();
124  return *this;
125  };
126 
132  const gd::String &message) override {
133  if (expression) expression->SetDeprecationMessage(message);
134  if (condition) condition->SetDeprecationMessage(message);
135  if (action) action->SetDeprecationMessage(message);
136  return *this;
137  }
138 
143  const gd::String &capability) {
144  if (expression) expression->SetRequiresBaseObjectCapability(capability);
145  if (condition) condition->SetRequiresBaseObjectCapability(capability);
146  if (action) action->SetRequiresBaseObjectCapability(capability);
147  return *this;
148  }
149 
155  const gd::String &type, const ParameterOptions &options) {
156  if (condition)
157  condition->UseStandardRelationalOperatorParameters(type, options);
158  if (action) action->UseStandardOperatorParameters(type, options);
159  return *this;
160  }
161 
162  MultipleInstructionMetadata &SetFunctionName(const gd::String &functionName) override {
163  if (expression) expression->SetFunctionName(functionName);
164  if (condition) condition->SetFunctionName(functionName);
165  if (action) action->SetFunctionName(functionName);
166  return *this;
167  }
168 
169  MultipleInstructionMetadata &SetGetter(const gd::String &getter) {
170  if (expression) expression->SetFunctionName(getter);
171  if (condition) condition->SetFunctionName(getter);
172  if (action) action->SetGetter(getter);
173  return *this;
174  }
175 
180  MultipleInstructionMetadata &SetIncludeFile(const gd::String &includeFile) override {
181  if (expression)
182  expression->SetIncludeFile(includeFile);
183  if (condition)
184  condition->SetIncludeFile(includeFile);
185  if (action) action->SetIncludeFile(includeFile);
186  return *this;
187  }
188 
189  MultipleInstructionMetadata &AddIncludeFile(const gd::String &includeFile) override {
190  if (expression)
191  expression->GetCodeExtraInformation().AddIncludeFile(includeFile);
192  if (condition)
193  condition->AddIncludeFile(includeFile);
194  if (action) action->AddIncludeFile(includeFile);
195  return *this;
196  }
197 
201  const std::vector<gd::String> &GetIncludeFiles() const override {
202  if (expression)
203  return expression->GetCodeExtraInformation().GetIncludeFiles();
204  if (condition)
205  return condition->GetIncludeFiles();
206  if (action) return action->GetIncludeFiles();
207  // It can't actually happen.
208  throw std::logic_error("no instruction metadata");
209  }
210 
215  if (expression) expression->SetPrivate();
216  if (condition) condition->SetPrivate();
217  if (action) action->SetPrivate();
218  return *this;
219  }
220 
225  if (expression) expression->SetHelpPath(path);
226  if (condition) condition->SetHelpPath(path);
227  if (action) action->SetHelpPath(path);
228  return *this;
229  }
230 
235  if (condition) condition->MarkAsSimple();
236  if (action) action->MarkAsSimple();
237  return *this;
238  }
239 
244  if (condition) condition->MarkAsAdvanced();
245  if (action) action->MarkAsAdvanced();
246  return *this;
247  }
248 
253  if (condition) condition->MarkAsComplex();
254  if (action) action->MarkAsComplex();
255  return *this;
256  }
257 
262  if (condition) condition->SetRelevantForLayoutEventsOnly();
263  if (action) action->SetRelevantForLayoutEventsOnly();
264  return *this;
265  }
266 
271  if (condition) condition->SetRelevantForFunctionEventsOnly();
272  if (action) action->SetRelevantForFunctionEventsOnly();
273  return *this;
274  }
275 
280  if (condition) condition->SetRelevantForAsynchronousFunctionEventsOnly();
281  if (action) action->SetRelevantForAsynchronousFunctionEventsOnly();
282  return *this;
283  }
284 
289  if (condition) condition->SetRelevantForCustomObjectEventsOnly();
290  if (action) action->SetRelevantForCustomObjectEventsOnly();
291  return *this;
292  }
293 
298  : expression(nullptr), condition(nullptr), action(nullptr){};
299 
300  private:
302  gd::InstructionMetadata &condition_)
303  : expression(&expression_), condition(&condition_), action(nullptr){};
304  MultipleInstructionMetadata(gd::ExpressionMetadata &expression_,
305  gd::InstructionMetadata &condition_,
306  gd::InstructionMetadata &action_)
307  : expression(&expression_), condition(&condition_), action(&action_){};
308  MultipleInstructionMetadata(gd::InstructionMetadata &condition_,
309  gd::InstructionMetadata &action_)
310  : expression(nullptr), condition(&condition_), action(&action_){};
311 
312  gd::ExpressionMetadata *expression;
313  gd::InstructionMetadata *condition;
314  gd::InstructionMetadata *action;
315 };
316 
317 } // 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:256
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 & SetParameterHint(const gd::String &hint) override
Set a hint attached to the last added parameter. See gd::InstructionMetadata::SetParameterHint.
Definition: ExpressionMetadata.h:242
ExpressionMetadata & GetCodeExtraInformation()
Return the structure containing the information about code generation for the expression.
Definition: ExpressionMetadata.h:386
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:350
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:328
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:302
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:338
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:424
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:407
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:289
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:542
InstructionMetadata & SetIncludeFile(const gd::String &includeFile) override
Erase any existing include file and add the specified include.
Definition: InstructionMetadata.h:560
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:569
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: InstructionMetadata.h:580
InstructionMetadata & SetParameterExtraInfo(const gd::String &extraInfo) override
Set the additional information, used for some parameters with special type (for example,...
Definition: InstructionMetadata.h:332
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:302
InstructionMetadata & SetFunctionName(const gd::String &functionName_) override
Definition: InstructionMetadata.h:465
InstructionMetadata & SetParameterHint(const gd::String &hint) override
Set a hint attached to the last added parameter. Hints are short reminders about how the parameter sh...
Definition: InstructionMetadata.h:318
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:416
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:142
MultipleInstructionMetadata & SetRelevantForLayoutEventsOnly() override
Definition: MultipleInstructionMetadata.h:261
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: MultipleInstructionMetadata.h:201
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:180
MultipleInstructionMetadata & SetRelevantForCustomObjectEventsOnly() override
Definition: MultipleInstructionMetadata.h:288
MultipleInstructionMetadata & UseStandardParameters(const gd::String &type, const ParameterOptions &options)
Definition: MultipleInstructionMetadata.h:154
MultipleInstructionMetadata & MarkAsSimple()
Definition: MultipleInstructionMetadata.h:234
MultipleInstructionMetadata & SetRelevantForAsynchronousFunctionEventsOnly() override
Definition: MultipleInstructionMetadata.h:279
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:131
MultipleInstructionMetadata & MarkAsAdvanced()
Definition: MultipleInstructionMetadata.h:243
MultipleInstructionMetadata & SetRelevantForFunctionEventsOnly() override
Definition: MultipleInstructionMetadata.h:270
MultipleInstructionMetadata & SetHelpPath(const gd::String &path)
Definition: MultipleInstructionMetadata.h:224
MultipleInstructionMetadata & SetFunctionName(const gd::String &functionName) override
Set the function that should be called when generating the source code from events.
Definition: MultipleInstructionMetadata.h:162
MultipleInstructionMetadata & AddIncludeFile(const gd::String &includeFile) override
Add a file to the already existing include files.
Definition: MultipleInstructionMetadata.h:189
MultipleInstructionMetadata & SetParameterExtraInfo(const gd::String &defaultValue) override
Definition: MultipleInstructionMetadata.h:87
MultipleInstructionMetadata & SetPrivate() override
Definition: MultipleInstructionMetadata.h:214
MultipleInstructionMetadata()
Don't use, only here to fulfill Emscripten bindings requirements.
Definition: MultipleInstructionMetadata.h:297
MultipleInstructionMetadata & MarkAsComplex()
Definition: MultipleInstructionMetadata.h:252
MultipleInstructionMetadata & SetHidden() override
Definition: MultipleInstructionMetadata.h:120
MultipleInstructionMetadata & SetParameterHint(const gd::String &hint) override
Definition: MultipleInstructionMetadata.h:109
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24
Definition: ParameterOptions.h:15