Skip to content

Commit dd230f9

Browse files
committed
TemplateEditor: Remove the OPTION parameter type
Instead, we infer that a parameter has a set of options by the existence of an OptionData as its default value. https://phabricator.endlessm.com/T35564
1 parent c12d856 commit dd230f9

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

addons/block_code/blocks/graphics/animationplayer_play.tres

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://c5e1byehtxwc0"]
1+
[gd_resource type="Resource" load_steps=6 format=3 uid="uid://c5e1byehtxwc0"]
22

33
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_emeuv"]
44
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/option_data.gd" id="1_xu43h"]
@@ -9,6 +9,11 @@ script = ExtResource("1_xu43h")
99
selected = 0
1010
items = ["ahead", "backwards"]
1111

12+
[sub_resource type="Resource" id="Resource_qpxn2"]
13+
script = ExtResource("1_xu43h")
14+
selected = 0
15+
items = []
16+
1217
[resource]
1318
script = ExtResource("1_emeuv")
1419
name = &"animationplayer_play"
@@ -17,13 +22,14 @@ description = "Play the animation."
1722
category = "Graphics | Animation"
1823
type = 2
1924
variant_type = 0
20-
display_template = "Play {animation: OPTION} {direction: OPTION}"
25+
display_template = "Play {animation: NIL} {direction: NIL}"
2126
code_template = "if \"{direction}\" == \"ahead\":
2227
play(\"{animation}\")
2328
else:
2429
play_backwards(\"{animation}\")
2530
"
2631
defaults = {
32+
"animation": SubResource("Resource_qpxn2"),
2733
"direction": SubResource("Resource_vnp2w")
2834
}
2935
signal_name = ""

addons/block_code/blocks/logic/compare.tres

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ description = ""
1616
category = "Logic | Comparison"
1717
type = 3
1818
variant_type = 1
19-
display_template = "{float1: FLOAT} {op: OPTION} {float2: FLOAT}"
19+
display_template = "{float1: FLOAT} {op: NIL} {float2: FLOAT}"
2020
code_template = "{float1} {op} {float2}"
2121
defaults = {
2222
"float1": 1.0,

addons/block_code/blocks/sounds/pause_continue_sound.tres

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[sub_resource type="Resource" id="Resource_lalgp"]
77
script = ExtResource("1_ilhdq")
88
selected = 0
9-
items = ["Pause", "Continue"]
9+
items = ["pause", "continue"]
1010

1111
[resource]
1212
script = ExtResource("1_q04gm")
@@ -16,7 +16,7 @@ description = "Pause/Continue the audio stream"
1616
category = "Sounds"
1717
type = 2
1818
variant_type = 0
19-
display_template = "{pause: OPTION} the sound {name: STRING}"
19+
display_template = "{pause: NIL} the sound {name: STRING}"
2020
code_template = "var __sound_node = get_node({name})
2121
if \"{pause}\" == \"pause\":
2222
__sound_node.stream_paused = true

addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,11 @@ func _append_input_parameter(parameter_format: String, id: int):
111111
parameter_input.placeholder = parameter["name"]
112112
parameter_input.variant_type = parameter["type"]
113113

114-
if parameter["is_option"] and default_value is OptionData:
114+
if default_value is OptionData:
115115
var option_data := default_value as OptionData
116116
parameter_input.option_data = option_data
117117
if option_data.selected < option_data.items.size():
118118
parameter_input.default_value = option_data.items[option_data.selected]
119-
elif parameter["is_option"]:
120-
push_warning("The block parameter %s in %s appears to be an option, but no option data is provided" % [parameter_format, parent_block])
121119
else:
122120
parameter_input.default_value = default_value
123121

@@ -146,7 +144,6 @@ func _parse_parameter_format(parameter_format: String) -> Dictionary:
146144
var parameter_name: String
147145
var parameter_type_str: String
148146
var parameter_type: Variant.Type
149-
var is_option: bool
150147
var split := parameter_format.split(":", true, 1)
151148

152149
if len(split) == 0:
@@ -158,9 +155,7 @@ func _parse_parameter_format(parameter_format: String) -> Dictionary:
158155
if len(split) > 1:
159156
parameter_type_str = split[1].strip_edges()
160157

161-
if parameter_type_str and parameter_type_str == "OPTION":
162-
is_option = true
163-
elif parameter_type_str:
158+
if parameter_type_str:
164159
parameter_type = Types.STRING_TO_VARIANT_TYPE[parameter_type_str]
165160

166-
return {"name": parameter_name, "type": parameter_type, "is_option": is_option}
161+
return {"name": parameter_name, "type": parameter_type}

0 commit comments

Comments
 (0)