Skip to content

Commit 2508145

Browse files
committed
Add functions to processors in doc
1 parent 6fb03eb commit 2508145

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

doc/files/JSON-CONFIG-PROCESSOR.md

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ extends JSONConfigProcessor
4545
# Overwrite the '_postprocess' method
4646
func _postprocess(minimum: int):
4747
# Set a global variable called 'min'
48-
set_variable("min", minimum)
48+
set_variable("min", minimum)
4949
5050
# It is a postprocessor, so it must return a value
51-
return minimum
51+
return minimum
5252
```
5353

5454
The 'set_max' postprocessor:
@@ -59,10 +59,10 @@ extends JSONConfigProcessor
5959
# Overwrite the '_postprocess' method
6060
func _postprocess(maximum: int):
6161
# Set a global variable called 'max'
62-
set_variable("max", maximum)
62+
set_variable("max", maximum)
6363
6464
# It is a postprocessor, so it must return a value
65-
return maximum
65+
return maximum
6666
```
6767

6868
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
7373
# Overwrite the '_preprocess' method
7474
func _preprocess():
7575
# Check if the global variable min exists
76-
if has_variable("min"):
76+
if has_variable("min"):
7777
# Set the integer minimum value
78-
get_property().set_min_value(get_variable("min"))
78+
get_property().set_min_value(get_variable("min"))
7979
# Check if the global variable max exists
80-
if has_variable("max"):
80+
if has_variable("max"):
8181
# Set the integer maximum value
82-
get_property().set_max_value(get_variable("max"))
82+
get_property().set_max_value(get_variable("max"))
8383
8484
# It is a preprocessor, so it does not return a value
8585
```
@@ -120,22 +120,22 @@ extends JSONConfigProcessor
120120
121121
122122
enum Genders{
123-
MALE,
124-
FEMALE,
125-
NON_BINARY
123+
MALE,
124+
FEMALE,
125+
NON_BINARY
126126
}
127127
128128
129129
func _postprocess(gender: String):
130-
match gender:
130+
match gender:
131131
"MALE":
132132
return Genders.MALE
133133
"FEMALE":
134134
return Genders.FEMALE
135135
"NON_BINARY":
136136
return Genders.NON_BINARY
137137
138-
return -1
138+
return -1
139139
```
140140

141141
Then we can create the following JSON configuration file:
@@ -180,19 +180,19 @@ extends JSONConfigProcessor
180180
181181
182182
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
196196
```
197197

198198
Now we can create the following JSON configuration file:
@@ -238,3 +238,15 @@ Returned error:
238238
}
239239
]
240240
```
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

Comments
 (0)