You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/files/JSON-CONFIG-PROCESSOR.md
+38-26Lines changed: 38 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,10 +45,10 @@ extends JSONConfigProcessor
45
45
# Overwrite the '_postprocess' method
46
46
func _postprocess(minimum: int):
47
47
# Set a global variable called 'min'
48
-
set_variable("min", minimum)
48
+
set_variable("min", minimum)
49
49
50
50
# It is a postprocessor, so it must return a value
51
-
return minimum
51
+
return minimum
52
52
```
53
53
54
54
The 'set_max' postprocessor:
@@ -59,10 +59,10 @@ extends JSONConfigProcessor
59
59
# Overwrite the '_postprocess' method
60
60
func _postprocess(maximum: int):
61
61
# Set a global variable called 'max'
62
-
set_variable("max", maximum)
62
+
set_variable("max", maximum)
63
63
64
64
# It is a postprocessor, so it must return a value
65
-
return maximum
65
+
return maximum
66
66
```
67
67
68
68
The 'set_range' preprocessor. It is crucial to notice that we need to check if the variables exists. Just in case the input data is non-valid, and the variables are not declared:
@@ -73,13 +73,13 @@ extends JSONConfigProcessor
73
73
# Overwrite the '_preprocess' method
74
74
func _preprocess():
75
75
# Check if the global variable min exists
76
-
if has_variable("min"):
76
+
if has_variable("min"):
77
77
# Set the integer minimum value
78
-
get_property().set_min_value(get_variable("min"))
78
+
get_property().set_min_value(get_variable("min"))
79
79
# Check if the global variable max exists
80
-
if has_variable("max"):
80
+
if has_variable("max"):
81
81
# Set the integer maximum value
82
-
get_property().set_max_value(get_variable("max"))
82
+
get_property().set_max_value(get_variable("max"))
83
83
84
84
# It is a preprocessor, so it does not return a value
85
85
```
@@ -120,22 +120,22 @@ extends JSONConfigProcessor
120
120
121
121
122
122
enum Genders{
123
-
MALE,
124
-
FEMALE,
125
-
NON_BINARY
123
+
MALE,
124
+
FEMALE,
125
+
NON_BINARY
126
126
}
127
127
128
128
129
129
func _postprocess(gender: String):
130
-
match gender:
130
+
match gender:
131
131
"MALE":
132
132
return Genders.MALE
133
133
"FEMALE":
134
134
return Genders.FEMALE
135
135
"NON_BINARY":
136
136
return Genders.NON_BINARY
137
137
138
-
return -1
138
+
return -1
139
139
```
140
140
141
141
Then we can create the following JSON configuration file:
@@ -180,19 +180,19 @@ extends JSONConfigProcessor
180
180
181
181
182
182
func _postprocess(integer: int):
183
-
# One is not a prime >:(
184
-
if integer == 1:
185
-
add_error({"error": "This is not a prime"})
186
-
return null
187
-
188
-
# A simple prime check
189
-
for i in range(2, sqrt(integer) + 1):
190
-
# If is not prime
191
-
if integer % i == 0:
192
-
add_error({"error": "This is not a prime"})
193
-
return null
194
-
195
-
return integer
183
+
# One is not a prime >:(
184
+
if integer == 1:
185
+
add_error({"error": "This is not a prime"})
186
+
return null
187
+
188
+
# A simple prime check
189
+
for i in range(2, sqrt(integer) + 1):
190
+
# If is not prime
191
+
if integer % i == 0:
192
+
add_error({"error": "This is not a prime"})
193
+
return null
194
+
195
+
return integer
196
196
```
197
197
198
198
Now we can create the following JSON configuration file:
@@ -238,3 +238,15 @@ Returned error:
238
238
}
239
239
]
240
240
```
241
+
## Functions
242
+
243
+
The public methods of this class are:
244
+
245
+
| Name | Params | Description | Returns |
246
+
|-|-|-|-|
247
+
|**add_error**|**error -> Dictionary:** <br> Custom error. | Raises a custom error, if you want it to have the 'as_text' property, include your custom error message in an 'error' property. | Nothing. |
248
+
|**add_warning**|**warning -> Dictionary:** <br> Custom warning. | Raises a custom warning, if you want it to have the 'as_text' property, include your custom warning message in an 'warning' property. | Nothing. |
249
+
|**set_variable**|**name -> String:** <br> Name of the global variable to set. <br> **value -> Variant:** <br> The value assigned to this global variable. | Creates a global variable or modify the value of a previously existing one. | Nothing. |
250
+
|**has_variable**|**name -> String:** <br> Name of the global variable to check. | Checks if the global variable exists. |**bool:** <br> If the global variable exists. |
251
+
|**get_variable**|**name -> String:** <br> Name of the global variable to get. | Gets the value of the specified global variable. |**Variant:** <br> The value of the global variable. If the variable is undefined, it will return null. |
252
+
| **get_property** | None. | Returns the JSON property in which this processor is located. | **JSONProperty:** <br> The JSON property in which this processor is located.
0 commit comments