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::IsTypeExpression("number", name);
115  }
116 
120  bool IsString() const {
121  return gd::ValueTypeMetadata::IsTypeExpression("string", name);
122  }
123 
127  bool IsBoolean() const {
128  return gd::ValueTypeMetadata::IsTypeExpression("boolean", name);
129  }
130 
137  bool IsVariable() const {
138  return gd::ValueTypeMetadata::IsTypeExpression("variable", name);
139  }
140 
148  }
149 
155  static bool IsTypeLegacyPreScopedVariable(const gd::String &type) {
156  return type == "scenevar" || type == "globalvar" || type == "objectvar";
157  }
158 
163  static bool IsTypeObject(const gd::String &parameterType) {
164  return parameterType == "object" || parameterType == "objectPtr" ||
165  parameterType == "objectList" ||
166  parameterType == "objectListOrEmptyIfJustDeclared" ||
167  parameterType == "objectListOrEmptyWithoutPicking";
168  }
169 
173  static bool IsTypeBehavior(const gd::String &parameterType) {
174  return parameterType == "behavior";
175  }
176 
183  static bool IsTypeExpression(const gd::String &type,
184  const gd::String &parameterType) {
185  if (type == "number") {
186  return parameterType == "number" || parameterType == "expression" ||
187  parameterType == "camera" || parameterType == "forceMultiplier";
188  } else if (type == "string") {
189  return parameterType == "string" || parameterType == "layer" ||
190  parameterType == "color" || parameterType == "file" ||
191  parameterType == "stringWithSelector" ||
192  parameterType == "sceneName" ||
193  parameterType == "layerEffectName" ||
194  parameterType == "layerEffectParameterName" ||
195  parameterType == "objectEffectName" ||
196  parameterType == "objectEffectParameterName" ||
197  parameterType == "objectPointName" ||
198  parameterType == "objectAnimationName" ||
199  parameterType == "functionParameterName" ||
200  parameterType == "externalLayoutName" ||
201  parameterType == "leaderboardId" ||
202  parameterType == "identifier";
203  } else if (type == "boolean") {
204  return parameterType == "yesorno" || parameterType == "trueorfalse";
205  } else if (type == "variable") {
206  return
207  parameterType == "variable" || // Any variable.
208  // Old, "pre-scoped" variables:
209  parameterType == "objectvar" || parameterType == "globalvar" ||
210  parameterType == "scenevar";
211  } else if (type == "resource") {
212  return parameterType == "fontResource" ||
213  parameterType == "soundfile" ||
214  parameterType == "musicfile" ||
215  parameterType == "bitmapFontResource" ||
216  parameterType == "imageResource" ||
217  parameterType == "jsonResource" ||
218  parameterType == "tilemapResource" ||
219  parameterType == "tilesetResource" ||
220  parameterType == "model3DResource" ||
221  parameterType == "atlasResource" ||
222  parameterType == "spineResource";
223  }
224  return false;
225  }
226 
234  static const gd::String &GetExpressionPrimitiveValueType(const gd::String &parameterType);
235 
243  static const gd::String &GetPrimitiveValueType(const gd::String &parameterType);
244  static const gd::String numberType;
245  static const gd::String stringType;
246  static const gd::String variableType;
247  static const gd::String booleanType;
248 
253  static const gd::String &ConvertPropertyTypeToValueType(const gd::String &propertyType);
254 
258 
261  void SerializeTo(gd::SerializerElement &element) const;
262 
266  void UnserializeFrom(const gd::SerializerElement &element);
268 
269  private:
270  gd::String name;
271  gd::String supplementaryInformation;
272  bool optional;
273  gd::String defaultValue;
275 
276  static const gd::String numberValueType;
277  static const gd::String booleanValueType;
278  static const gd::String colorValueType;
279  static const gd::String choiceValueType;
280  static const gd::String stringValueType;
281 };
282 
283 } // namespace gd
284 
285 #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:31
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:173
static bool IsTypeExpression(const gd::String &type, const gd::String &parameterType)
Return true if the type is an expression of the given type.
Definition: ValueTypeMetadata.h:183
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:155
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 IsLegacyPreScopedVariable() const
Return true if the type is a variable but from a specific scope (scene, project or object)....
Definition: ValueTypeMetadata.h:146
bool IsOptional() const
Return true if the parameter is optional.
Definition: ValueTypeMetadata.h:64
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:163
bool IsVariable() const
Return true if the type of the parameter is a number.
Definition: ValueTypeMetadata.h:137
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
Definition: CommonTools.h:24