GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ValueTypeMetadata.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 
7 #ifndef VALUE_TYPE_METADATA_H
8 #define VALUE_TYPE_METADATA_H
9 #include <map>
10 #include <memory>
11 
12 #include "GDCore/String.h"
13 namespace gd {
14 class SerializerElement;
15 } // namespace gd
16 
17 namespace gd {
18 
26 class GD_CORE_API ValueTypeMetadata {
27  public:
29  virtual ~ValueTypeMetadata(){};
30 
34  const gd::String &GetName() const { return name; }
35 
40  name = name_;
41  return *this;
42  }
43 
49  const gd::String &GetExtraInfo() const { return supplementaryInformation; }
50 
56  ValueTypeMetadata &SetExtraInfo(const gd::String &supplementaryInformation_) {
57  supplementaryInformation = supplementaryInformation_;
58  return *this;
59  }
60 
64  bool IsOptional() const { return optional; }
65 
69  ValueTypeMetadata &SetOptional(bool optional_ = true) {
70  optional = optional_;
71  return *this;
72  }
73 
77  const gd::String &GetDefaultValue() const { return defaultValue; }
78 
82  ValueTypeMetadata &SetDefaultValue(const gd::String &defaultValue_) {
83  defaultValue = defaultValue_;
84  return *this;
85  }
86 
90  bool IsDefined() const {
91  return !name.empty();
92  }
93 
98  bool IsObject() const {
100  }
101 
105  bool IsBehavior() const {
107  }
108 
113  bool IsNumber() const {
114  return gd::ValueTypeMetadata::IsTypeValue("number", name);
115  }
116 
120  bool IsString() const {
121  return gd::ValueTypeMetadata::IsTypeValue("string", name);
122  }
123 
127  bool IsBoolean() const {
128  return gd::ValueTypeMetadata::IsTypeValue("boolean", name);
129  }
130 
137  bool IsVariable() const {
139  }
140 
147  static bool IsVariable(const gd::String &type) {
148  return gd::ValueTypeMetadata::GetPrimitiveValueType(type) == "variable";
149  }
150 
155  bool IsVariableOnly() const {
156  return
157  // Any variable.
158  name == "variable" ||
159  // Old, "pre-scoped" variables:
160  name == "objectvar" || name == "globalvar" ||
161  name == "scenevar";
162  }
163 
171  }
172 
178  static bool IsTypeLegacyPreScopedVariable(const gd::String &type) {
179  return type == "scenevar" || type == "globalvar" || type == "objectvar";
180  }
181 
186  static bool IsTypeObject(const gd::String &parameterType) {
187  return parameterType == "object" || parameterType == "objectPtr" ||
188  parameterType == "objectList" ||
189  parameterType == "objectListOrEmptyIfJustDeclared" ||
190  parameterType == "objectListOrEmptyWithoutPicking";
191  }
192 
196  static bool IsTypeBehavior(const gd::String &parameterType) {
197  return parameterType == "behavior";
198  }
199 
208  static bool IsTypeExpression(const gd::String &type,
209  const gd::String &parameterType) {
210  if (type == "number") {
211  return parameterType == "number" || parameterType == "expression" ||
212  parameterType == "camera" || parameterType == "forceMultiplier";
213  } else if (type == "string") {
214  // "key" and "mouse" are not mapped her, see GetPrimitiveValueType.
215  return parameterType == "string" || parameterType == "layer" ||
216  parameterType == "color" || parameterType == "file" ||
217  parameterType == "stringWithSelector" ||
218  parameterType == "sceneName" ||
219  parameterType == "layerEffectName" ||
220  parameterType == "layerEffectParameterName" ||
221  parameterType == "objectEffectName" ||
222  parameterType == "objectEffectParameterName" ||
223  parameterType == "objectPointName" ||
224  parameterType == "objectAnimationName" ||
225  parameterType == "functionParameterName" ||
226  parameterType == "externalLayoutName" ||
227  parameterType == "leaderboardId" ||
228  parameterType == "keyboardKey" ||
229  parameterType == "mouseButton" ||
230  parameterType == "identifier";
231  } else if (type == "boolean") {
232  return parameterType == "yesorno" || parameterType == "trueorfalse";
233  } else if (type == "variable") {
234  return
235  // Any variable.
236  parameterType == "variable" ||
237  parameterType == "variableOrProperty" ||
238  parameterType == "variableOrPropertyOrParameter" ||
239  // Old, "pre-scoped" variables:
240  parameterType == "objectvar" || parameterType == "globalvar" ||
241  parameterType == "scenevar";
242  } else if (type == "resource") {
243  return parameterType == "fontResource" ||
244  parameterType == "audioResource" ||
245  parameterType == "videoResource" ||
246  parameterType == "bitmapFontResource" ||
247  parameterType == "imageResource" ||
248  parameterType == "jsonResource" ||
249  parameterType == "tilemapResource" ||
250  parameterType == "tilesetResource" ||
251  parameterType == "model3DResource" ||
252  parameterType == "atlasResource" ||
253  parameterType == "spineResource" ||
254  // Deprecated, old parameter types:
255  parameterType == "soundfile" ||
256  parameterType == "musicfile";
257  }
258  return false;
259  }
260 
265  static bool IsTypeValue(const gd::String &type,
266  const gd::String &parameterType) {
267  if (gd::ValueTypeMetadata::IsTypeExpression(type, parameterType)) {
268  return true;
269  }
270  // These 2 parameter types are not strings from the outside of a function as
271  // the generator add quote around a text, but from the events inside of the
272  // function the parameter is a string.
273  //
274  // See EventsCodeGenerator::GenerateParameterCodes
275  if (type == "string") {
276  return parameterType == "key" || parameterType == "mouse";
277  }
278  return false;
279  }
280 
288  static const gd::String &GetExpressionPrimitiveValueType(const gd::String &parameterType);
289 
297  static const gd::String &GetPrimitiveValueType(const gd::String &parameterType);
298  static const gd::String numberType;
299  static const gd::String stringType;
300  static const gd::String variableType;
301  static const gd::String booleanType;
302 
307  static const gd::String &ConvertPropertyTypeToValueType(const gd::String &propertyType);
308 
312 
315  void SerializeTo(gd::SerializerElement &element) const;
316 
320  void UnserializeFrom(const gd::SerializerElement &element);
322 
323  private:
324  gd::String name;
325  gd::String supplementaryInformation;
326  bool optional;
327  gd::String defaultValue;
329 
330  static const gd::String numberValueType;
331  static const gd::String booleanValueType;
332  static const gd::String stringValueType;
333  static const gd::String colorValueType;
334  static const gd::String choiceValueType;
335  static const gd::String behaviorValueType;
336  static const gd::String leaderboardIdValueType;
337  static const gd::String objectAnimationNameValueType;
338  static const gd::String keyboardKeyValueType;
339 };
340 
341 } // namespace gd
342 
343 #endif // VALUE_TYPE_METADATA_H
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
ValueTypeMetadata & SetName(const gd::String &name_)
Set the string representation of the type.
Definition: ValueTypeMetadata.h:39
static bool IsTypeBehavior(const gd::String &parameterType)
Return true if the type is "behavior".
Definition: ValueTypeMetadata.h:196
static bool IsTypeExpression(const gd::String &type, const gd::String &parameterType)
Return true if the type is an expression of the given type from the caller point of view.
Definition: ValueTypeMetadata.h:208
const gd::String & GetDefaultValue() const
Get the default value for the parameter.
Definition: ValueTypeMetadata.h:77
bool IsString() const
Return true if the type is a string.
Definition: ValueTypeMetadata.h:120
const gd::String & GetExtraInfo() const
Return an optional additional information, used for some parameters with special type (for example,...
Definition: ValueTypeMetadata.h:49
ValueTypeMetadata & SetDefaultValue(const gd::String &defaultValue_)
Set the default value, if the parameter is optional.
Definition: ValueTypeMetadata.h:82
const gd::String & GetName() const
Return the string representation of the type.
Definition: ValueTypeMetadata.h:34
static bool IsTypeLegacyPreScopedVariable(const gd::String &type)
Return true if the type is a variable but from a specific scope (scene, project or object)....
Definition: ValueTypeMetadata.h:178
bool IsDefined() const
Return true if the type is defined.
Definition: ValueTypeMetadata.h:90
ValueTypeMetadata & SetOptional(bool optional_=true)
Set if the parameter is optional.
Definition: ValueTypeMetadata.h:69
bool IsVariableOnly() const
Return true if the type of the parameter is a variable and not a property or a parameter.
Definition: ValueTypeMetadata.h:155
bool IsLegacyPreScopedVariable() const
Return true if the type is a variable but from a specific scope (scene, project or object)....
Definition: ValueTypeMetadata.h:169
bool IsOptional() const
Return true if the parameter is optional.
Definition: ValueTypeMetadata.h:64
static bool IsVariable(const gd::String &type)
Return true if the type of the parameter is a variable.
Definition: ValueTypeMetadata.h:147
bool IsBoolean() const
Return true if the type is a boolean.
Definition: ValueTypeMetadata.h:127
bool IsObject() const
Return true if the type is representing one object (or more, i.e: an object group).
Definition: ValueTypeMetadata.h:98
bool IsBehavior() const
Return true if the type is "behavior".
Definition: ValueTypeMetadata.h:105
static bool IsTypeObject(const gd::String &parameterType)
Return true if the type is representing one object (or more, i.e: an object group).
Definition: ValueTypeMetadata.h:186
bool IsVariable() const
Return true if the type of the parameter is a variable.
Definition: ValueTypeMetadata.h:137
static const gd::String & GetPrimitiveValueType(const gd::String &parameterType)
Return the primitive type from the parameter type. Declinations of "number" and "string" types (like ...
Definition: ValueTypeMetadata.cpp:55
ValueTypeMetadata & SetExtraInfo(const gd::String &supplementaryInformation_)
Set an optional additional information, used for some parameters with special type (for example,...
Definition: ValueTypeMetadata.h:56
bool IsNumber() const
Return true if the type is an expression of the given type.
Definition: ValueTypeMetadata.h:113
static bool IsTypeValue(const gd::String &type, const gd::String &parameterType)
Return true if the type is a value of the given primitive type from the function events point of view...
Definition: ValueTypeMetadata.h:265
Definition: CommonTools.h:24