Skip to content

Commit 7f9a689

Browse files
committed
WIP fix my rebase, weird type casting is weird
1 parent 02eba02 commit 7f9a689

File tree

6 files changed

+578
-179
lines changed

6 files changed

+578
-179
lines changed

addons/block_code/types/types.gd

+8
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ static func dijkstra(source: Variant.Type):
103103

104104

105105
static func can_cast(type: Variant.Type, parent_type: Variant.Type) -> bool:
106+
print("CAN CAST ", type, " -> ", parent_type)
106107
if type == parent_type:
107108
return true
108109

110+
if type == TYPE_NIL or parent_type == TYPE_NIL:
111+
return true
112+
109113
if cast_graph.has(type) and cast_graph.has(parent_type):
110114
dijkstra(type)
111115
return dist[parent_type] < INT_MAX
@@ -116,6 +120,10 @@ static func cast(val: String, type: Variant.Type, parent_type: Variant.Type):
116120
if type == parent_type:
117121
return val
118122

123+
if type == TYPE_NIL or parent_type == TYPE_NIL:
124+
print("CAST NIL", val)
125+
return val
126+
119127
if cast_graph.has(type) and cast_graph.has(parent_type):
120128
dijkstra(type)
121129
if dist[parent_type] < INT_MAX:

addons/block_code/ui/blocks/parameter_block/parameter_block.tscn

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[ext_resource type="Script" path="res://addons/block_code/ui/blocks/parameter_block/parameter_block.gd" id="1_0hajy"]
44
[ext_resource type="PackedScene" uid="uid://c7puyxpqcq6xo" path="res://addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.tscn" id="2_gy5co"]
55

6-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dbera"]
6+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8gcat"]
77
bg_color = Color(1, 1, 1, 1)
88
border_width_left = 3
99
border_width_top = 3
@@ -19,15 +19,14 @@ offset_right = 16.0
1919
offset_bottom = 8.0
2020
size_flags_horizontal = 0
2121
script = ExtResource("1_0hajy")
22-
defaults = null
2322
block_name = "parameter_block"
2423
label = "Param"
2524
block_type = 3
2625

2726
[node name="Panel" type="Panel" parent="."]
2827
unique_name_in_owner = true
2928
layout_mode = 2
30-
theme_override_styles/panel = SubResource("StyleBoxFlat_dbera")
29+
theme_override_styles/panel = SubResource("StyleBoxFlat_8gcat")
3130

3231
[node name="DragDropArea" parent="." instance=ExtResource("2_gy5co")]
3332
layout_mode = 2

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ func get_string() -> String:
132132

133133
if option:
134134
return _option_input.get_item_text(_option_input.selected).to_snake_case()
135+
136+
print("GET STRING ", input, " with ", variant_type)
135137

136138
match variant_type:
137-
TYPE_STRING:
139+
TYPE_STRING, TYPE_NODE_PATH:
138140
return "'%s'" % input.replace("\\", "\\\\").replace("'", "\\'")
139141
TYPE_VECTOR2:
140142
return "Vector2(%s)" % input

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ size_flags_horizontal = 3
156156

157157
[node name="BoolInput" type="MarginContainer" parent="InputSwitcher"]
158158
unique_name_in_owner = true
159+
visible = false
159160
layout_mode = 2
160161
theme_override_constants/margin_left = 8
161162

addons/block_code/ui/picker/categories/category_factory.gd

+26-31
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ static func get_general_categories() -> Array[BlockCategory]:
144144
variable_list.append(b)
145145

146146
b = BLOCKS["parameter_block"].instantiate()
147-
b.block_type = Types.BlockType.STRING
147+
b.variant_type = TYPE_STRING
148148
b.block_format = "Get String {var: STRING}"
149149
b.statement = "VAR_DICT[{var}]"
150150
variable_list.append(b)
151151

152152
b = BLOCKS["parameter_block"].instantiate()
153-
b.block_type = Types.BlockType.STRING
154-
b.block_format = "Get String {var: STRING} from {node: NODE}"
155-
b.statement = "{node}.VAR_DICT[{var}]"
153+
b.variant_type = TYPE_STRING
154+
b.block_format = "Get String {var: STRING} from {node: NODE_PATH}"
155+
b.statement = "get_node({node}).VAR_DICT[{var}]"
156156
variable_list.append(b)
157157

158158
b = BLOCKS["statement_block"].instantiate()
@@ -167,14 +167,15 @@ static func get_general_categories() -> Array[BlockCategory]:
167167
variable_list.append(b)
168168

169169
b = BLOCKS["parameter_block"].instantiate()
170-
b.block_format = "To String {int: INT}"
171-
b.statement = "str({int})"
170+
b.variant_type = TYPE_STRING
171+
b.block_format = "To String {value: NIL}"
172+
b.statement = "str({value})"
172173
variable_list.append(b)
173174

174175
b = BLOCKS["parameter_block"].instantiate()
175-
b.block_type = Types.BlockType.INT
176-
b.block_format = "Get Int {var: INT} from {node: NODE}"
177-
b.statement = "{node}.VAR_DICT[{var}]"
176+
b.variant_type = TYPE_INT
177+
b.block_format = "Get Int {var: INT} from {node: NODE_PATH}"
178+
b.statement = "get_node({node}).VAR_DICT[{var}]"
178179
variable_list.append(b)
179180

180181
var variable_category: BlockCategory = BlockCategory.new("Variables", variable_list, Color("4f975d"))
@@ -183,50 +184,44 @@ static func get_general_categories() -> Array[BlockCategory]:
183184
var type_list: Array[Block] = []
184185

185186
b = BLOCKS["parameter_block"].instantiate()
186-
b.block_type = Types.BlockType.NODE
187+
b.variant_type = TYPE_NODE_PATH
187188
b.block_format = "This node"
188-
b.statement = "self"
189-
type_list.append(b)
190-
191-
b = BLOCKS["parameter_block"].instantiate()
192-
b.block_type = Types.BlockType.NODE
193-
b.block_format = "%{name: STRING}"
194-
b.statement = "%{name}"
189+
b.statement = "get_path()"
195190
type_list.append(b)
196191

197192
b = BLOCKS["parameter_block"].instantiate()
198-
b.block_type = Types.BlockType.STRING
199-
b.block_format = "As String {value}"
200-
b.statement = "String({value})"
193+
b.variant_type = TYPE_NODE_PATH
194+
b.block_format = "%{name: NIL}"
195+
b.statement = "%{name}.get_path()"
201196
type_list.append(b)
202197

203198
b = BLOCKS["parameter_block"].instantiate()
204-
b.block_type = Types.BlockType.INT
205-
b.block_format = "As int {value}"
199+
b.variant_type = TYPE_INT
200+
b.block_format = "As int {value: NIL}"
206201
b.statement = "int({value})"
207202
type_list.append(b)
208203

209204
b = BLOCKS["parameter_block"].instantiate()
210-
b.block_type = Types.BlockType.FLOAT
211-
b.block_format = "As float {value}"
205+
b.variant_type = TYPE_FLOAT
206+
b.block_format = "As float {value: NIL}"
212207
b.statement = "float({value})"
213208
type_list.append(b)
214209

215210
b = BLOCKS["parameter_block"].instantiate()
216-
b.block_type = Types.BlockType.BOOL
217-
b.block_format = "As boolean {value}"
211+
b.variant_type = TYPE_BOOL
212+
b.block_format = "As boolean {value: NIL}"
218213
b.statement = "bool({value})"
219214
type_list.append(b)
220215

221216
b = BLOCKS["parameter_block"].instantiate()
222-
b.block_type = Types.BlockType.VARIANT
223-
b.block_format = "Get property {key: STRING} from {node: NODE}"
224-
b.statement = "{node}.get({key})"
217+
b.variant_type = TYPE_NIL
218+
b.block_format = "Get property {key: STRING} from {node: NODE_PATH}"
219+
b.statement = "get_node({node}).get({key})"
225220
type_list.append(b)
226221

227222
b = BLOCKS["statement_block"].instantiate()
228-
b.block_format = "Set property {key: STRING} in {node: NODE} to {value: VARIANT}"
229-
b.statement = "{node}.set({key}, {value})"
223+
b.block_format = "Set property {key: STRING} in {node: NODE_PATH} to {value: NIL}"
224+
b.statement = "get_node({node}).set({key}, {value})"
230225
type_list.append(b)
231226

232227
var type_category: BlockCategory = BlockCategory.new("Nodes & Types", type_list, Color("c12f8e"))

0 commit comments

Comments
 (0)