Skip to content

Commit 3260860

Browse files
committed
formatting
1 parent 9e7ab01 commit 3260860

File tree

15 files changed

+118
-129
lines changed

15 files changed

+118
-129
lines changed

addons/form/nodes/Boundaries.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ class_name Boundaries extends Resource
2323

2424
## Determines if the subject is within the boundaries
2525
func has(subject: int) -> bool:
26-
return (max == 0 || subject <= max) && (min == 0 || subject >= min)
26+
return (max == 0||subject <= max)&&(min == 0||subject >= min)

addons/form/nodes/Form.gd

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class_name Form extends Control
1212
submit_button.pressed.disconnect(submit)
1313
submit_button = new_val
1414
## Handles the submission of the form.
15-
@export var protocol:Protocol
15+
@export var protocol: Protocol
1616

1717
## Submits the form data to the protocol if the data is valid.
1818
func submit():
1919
var fields := generate_fields_dict(true)
2020
var valid := true
2121
for field in fields.values():
22-
if field["label"] != null && !field["label"].indicate_validity():
22+
if field["label"] != null&&!field["label"].indicate_validity():
2323
valid = false
2424
if !valid:
2525
return
@@ -34,19 +34,19 @@ func generate_fields_dict(
3434
## return { { "label": ..., "input": ... }, ... }
3535
## else:
3636
## return { input, ... }
37-
include_labels: bool = false,
37+
include_labels: bool=false,
3838
## The node to generate the dictionary from.
3939
## This is mainly used for recursion.
40-
subject: Node = self,
40+
subject: Node=self,
4141
## The dictionary to add the fields to.
4242
## This is mainly used for recursion.
43-
fields := {}
43+
fields:={}
4444
) -> Dictionary:
4545
var labeled_inputs := []
4646

4747
for child in subject.get_children():
4848
# If the child is a label with an associated input, add it to the dictionary.
49-
if child is FormLabel && child.input != null:
49+
if child is FormLabel&&child.input != null:
5050
var key := generate_unique_key(child, fields)
5151
if include_labels:
5252
fields[key] = {
@@ -60,11 +60,11 @@ func generate_fields_dict(
6060
elif child.get_child_count() > 0:
6161
# Add the child's children to the dictionary as they are returned from the recursive call.
6262
fields.merge(generate_fields_dict(include_labels, child, fields))
63-
63+
6464
# Before we checked only inputs that have labels, so this adds the remaining ones.
6565
for child in subject.get_children():
6666
# If it's an input and it hasn't been added yet, add it.
67-
if Form.is_input(child) && ! labeled_inputs.has(child):
67+
if Form.is_input(child)&&!labeled_inputs.has(child):
6868
var key := generate_unique_key(child, fields)
6969
if include_labels:
7070
fields[key] = {
@@ -102,13 +102,13 @@ static func is_input(subject: Node) -> bool:
102102
(
103103
subject is BaseButton
104104
# meaning a button, but not one that just opens a popup
105-
&&! subject is MenuButton
105+
&&!subject is MenuButton
106106
)
107107
# or subject is input field
108-
|| subject is LineEdit
109-
|| subject is TextEdit
110-
|| subject is ItemList
111-
|| subject is Slider
112-
|| subject is SpinBox
113-
|| subject is GraphEdit
108+
||subject is LineEdit
109+
||subject is TextEdit
110+
||subject is ItemList
111+
||subject is Slider
112+
||subject is SpinBox
113+
||subject is GraphEdit
114114
)

addons/form/nodes/FormLabel.gd

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
## Label for input controls
33
class_name FormLabel extends Label
44

5-
65
## Input control to label
76
@export var input: Control:
87
set(new_val):
9-
if new_val == null || Form.is_input(new_val):
8+
if new_val == null||Form.is_input(new_val):
109
if input != null:
1110
input.gui_input.disconnect(_on_gui_input)
1211
input = new_val
1312
mode = mode # run setter
1413
indicate_required()
15-
if validate_on_input && input != null:
14+
if validate_on_input&&input != null:
1615
input.gui_input.connect(_on_gui_input)
1716
else:
18-
printerr(get_class(),": input must be a input button or input field")
17+
printerr(get_class(), ": input must be a input button or input field")
1918
## "Input value must not be empty"
2019
@export var input_required := false:
2120
set(new_val):
@@ -33,8 +32,8 @@ class_name FormLabel extends Label
3332
## The style to apply to the input when valid
3433
var valid_style: StyleBox:
3534
get:
36-
if input && _valid_style == null:
37-
_valid_style = input.get_theme_stylebox("normal")
35+
if input&&_valid_style == null:
36+
_valid_style = input.get_theme_stylebox("normal")
3837
return _valid_style
3938
## Internal storage for valid_style
4039
var _valid_style
@@ -58,7 +57,7 @@ enum Mode {
5857
if new_val == null:
5958
new_val = Mode.SEPARATE
6059
mode = new_val
61-
60+
6261
if mode == Mode.SEPARATE:
6362
visible = true
6463
else:
@@ -73,15 +72,14 @@ enum Mode {
7372
input[prop] = ""
7473
found = true
7574
break
76-
if !found && mode == Mode.IN_INPUT:
75+
if !found&&mode == Mode.IN_INPUT:
7776
push_error("Input ", input.get_instance_id(), " has no placeholder_text or text property")
7877
mode = Mode.SEPARATE
7978
visible = true
8079

81-
8280
## Sets the label text to the input's name if it is empty and runs necessary setters
8381
func _enter_tree():
84-
if input != null && text in [null, ""]:
82+
if input != null&&text in [null, ""]:
8583
text = input.name
8684
if !visibility_changed.is_connected(update_display_mode):
8785
visibility_changed.connect(update_display_mode)
@@ -91,9 +89,9 @@ func _enter_tree():
9189
## If the label is not visible and the mode is Mode.SEPARATE, the mode is set to Mode.HIDDEN.
9290
## Else the mode setter is run (mode = mode).
9391
func update_display_mode():
94-
if visible && (mode == Mode.IN_INPUT || mode == Mode.HIDDEN):
92+
if visible&&(mode == Mode.IN_INPUT||mode == Mode.HIDDEN):
9593
mode = Mode.SEPARATE
96-
elif !visible && mode == Mode.SEPARATE:
94+
elif !visible&&mode == Mode.SEPARATE:
9795
mode = Mode.HIDDEN
9896
else:
9997
# run setter
@@ -102,7 +100,7 @@ func update_display_mode():
102100
## Add or remove the required_hint if input_required
103101
func indicate_required():
104102
# if * needed but not present
105-
if input_required && required_hint not in ["", null] && !text.ends_with(required_hint):
103+
if input_required&&required_hint not in ["", null]&&!text.ends_with(required_hint):
106104
# add
107105
text += required_hint
108106
# if * present but not needed
@@ -114,16 +112,16 @@ func indicate_required():
114112
## Change style based on validity and return validity or default if input is not validatable
115113
func indicate_validity(
116114
## the default value to return if input is not validatable
117-
default := true
115+
default:=true
118116
) -> bool:
119117
var valid = default
120118
# no input = not validatable -> valid = default
121119
if input:
122120
var broken_rules := {}
123121
var value = Protocol.new().get_value(input)
124-
var input_has_not_null_validator = has_property(input, "validator") && input.validator != null
125-
126-
if input_required && (value == null || ((value is String || value is StringName) && value == "")):
122+
var input_has_not_null_validator = has_property(input, "validator")&&input.validator != null
123+
124+
if input_required&&(value == null||((value is String||value is StringName)&&value == "")):
127125
# input is required but empty -> valid = false
128126
broken_rules["required"] = true
129127
valid = false
@@ -135,7 +133,7 @@ func indicate_validity(
135133
broken_rules = input.validator.broken_rules
136134
else: # Has a text value or doesn't have to be true, has no validation rules. -> valid = true
137135
valid = true
138-
136+
139137
if !valid:
140138
print("Input ", input.get_instance_id(), " breaks the following rule(s):")
141139
print(broken_rules)
@@ -155,18 +153,18 @@ func indicate_validity(
155153
return valid
156154

157155
## Return validity of "Subject has property_name and it is not a method"
158-
func has_property(subject:Object, property_name: StringName) -> bool:
159-
return property_name in subject && !subject.has_method(property_name)
156+
func has_property(subject: Object, property_name: StringName) -> bool:
157+
return property_name in subject&&!subject.has_method(property_name)
160158

161159
## Indicate validity on GUI input if event is relevant and validate_on_input
162160
func _on_gui_input(event: InputEvent):
163-
if validate_on_input && !(event is InputEventMouseMotion) && Form.is_input(input) && (
164-
event is InputEventMouseButton && event.button_index == MOUSE_BUTTON_LEFT && !event.pressed && ( # left click release
161+
if validate_on_input&&!(event is InputEventMouseMotion)&&Form.is_input(input)&&(
162+
event is InputEventMouseButton&&event.button_index == MOUSE_BUTTON_LEFT&&!event.pressed&&( # left click release
165163
input is BaseButton
166-
|| input is Slider
167-
|| input is SpinBox
168-
|| input is GraphEdit
164+
||input is Slider
165+
||input is SpinBox
166+
||input is GraphEdit
169167
)
170-
|| event is InputEventKey
168+
||event is InputEventKey
171169
):
172170
indicate_validity.call_deferred() # ensure value is updated before validation

addons/form/nodes/ListFilter.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ enum Match {
1313
@export var elements: Array[String]
1414

1515
## Returns wether the subject is represented in the list
16-
func is_represented_in(subject: String)-> bool:
16+
func is_represented_in(subject: String) -> bool:
1717
for element in elements:
1818
if subject.contains(element):
19-
if !bool(match): # If any element is present and AT_LEAST_ONE must be, return true
19+
if !bool(match ): # If any element is present and AT_LEAST_ONE must be, return true
2020
return true
2121
## else, keep looking
22-
elif bool(match): # If any element is not present but ALL must be, return false
22+
elif bool(match ): # If any element is not present but ALL must be, return false
2323
return false
2424
# If we get here, either every element is present and ALL must be, or no element is present and AT_LEAST_ONE must be
25-
return bool(match)
25+
return bool(match )
2626

2727
## Returns the output of elements.size()
2828
func size() -> int:

addons/form/nodes/Protocol.gd

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func submit(
3636
fields: Dictionary
3737
) -> int:
3838
push_error("not implemented")
39-
return -1
39+
return - 1
4040

4141
## Finds the value of the given Node based on its type.
4242
## Throws an error if the type is unknown.
@@ -53,7 +53,7 @@ func submit(
5353
func get_value(subject: Node) -> Variant:
5454
if subject is BaseButton:
5555
return subject.button_pressed
56-
elif subject is LineEdit || subject is TextEdit:
56+
elif subject is LineEdit||subject is TextEdit:
5757
return subject.text
5858
elif subject is ItemList:
5959
var items: Array[Dictionary] = []
@@ -65,7 +65,7 @@ func get_value(subject: Node) -> Variant:
6565
"metadata": subject.get_item_metadata(i)
6666
})
6767
return items
68-
elif subject is Slider || subject is SpinBox:
68+
elif subject is Slider||subject is SpinBox:
6969
return subject.value
7070
elif subject is GraphEdit:
7171
return subject.get_connection_list()
@@ -80,15 +80,14 @@ func sanitize(
8080
## Any other type will be returned as is.
8181
subject: Variant,
8282
## Stores every instance of every character that was caught by the sanitization in order of appearance.
83-
jail := [],
83+
jail:=[],
8484
## The sanitization method to use.
85-
sanitization_override := sanitization,
85+
sanitization_override:=sanitization,
8686
## Whether to sanitize Dictionary keys. Note that this is passed down recursively.
87-
sanitize_keys := false
87+
sanitize_keys:=false
8888
) -> Variant:
8989
var sanitized := subject
9090

91-
9291
match typeof(subject):
9392
TYPE_DICTIONARY:
9493
sanitized = {}
@@ -112,7 +111,7 @@ func sanitize(
112111
jail.append(char)
113112
else:
114113
subject += char
115-
114+
116115
# Sanitization
117116
var escape_char = "\\"
118117
if OS.get_name() == "Windows":
@@ -145,7 +144,7 @@ func sanitize(
145144
var result := regex.search_all(subject)
146145
var matches := []
147146
for match in result:
148-
var matchstr = match.get_string()
147+
var matchstr = match .get_string()
149148
matches.append(matchstr)
150149
jail.append(matchstr)
151150
for char in subject:

addons/form/nodes/Protocols/FileProtocol.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ func submit(
3030
if DirAccess.dir_exists_absolute(target_dir) == false:
3131
push_error("Target directory does not exist.")
3232
return 0
33-
33+
3434
var file_name := generate_file_name(fields)
3535

3636
if FileAccess.file_exists(target_dir + "/" + file_name):
3737
push_error("File already exists.")
3838
return 0
39-
39+
4040
var values = fields.values().map(func(input: Node):
4141
return get_value(input)
4242
)

0 commit comments

Comments
 (0)