Skip to content

Commit

Permalink
WIP fix my rebase, weird type casting is weird
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmccall committed Jun 19, 2024
1 parent 02eba02 commit 7f9a689
Show file tree
Hide file tree
Showing 6 changed files with 578 additions and 179 deletions.
8 changes: 8 additions & 0 deletions addons/block_code/types/types.gd
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ static func dijkstra(source: Variant.Type):


static func can_cast(type: Variant.Type, parent_type: Variant.Type) -> bool:
print("CAN CAST ", type, " -> ", parent_type)
if type == parent_type:
return true

if type == TYPE_NIL or parent_type == TYPE_NIL:
return true

if cast_graph.has(type) and cast_graph.has(parent_type):
dijkstra(type)
return dist[parent_type] < INT_MAX
Expand All @@ -116,6 +120,10 @@ static func cast(val: String, type: Variant.Type, parent_type: Variant.Type):
if type == parent_type:
return val

if type == TYPE_NIL or parent_type == TYPE_NIL:
print("CAST NIL", val)
return val

if cast_graph.has(type) and cast_graph.has(parent_type):
dijkstra(type)
if dist[parent_type] < INT_MAX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://addons/block_code/ui/blocks/parameter_block/parameter_block.gd" id="1_0hajy"]
[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"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dbera"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8gcat"]
bg_color = Color(1, 1, 1, 1)
border_width_left = 3
border_width_top = 3
Expand All @@ -19,15 +19,14 @@ offset_right = 16.0
offset_bottom = 8.0
size_flags_horizontal = 0
script = ExtResource("1_0hajy")
defaults = null
block_name = "parameter_block"
label = "Param"
block_type = 3

[node name="Panel" type="Panel" parent="."]
unique_name_in_owner = true
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_dbera")
theme_override_styles/panel = SubResource("StyleBoxFlat_8gcat")

[node name="DragDropArea" parent="." instance=ExtResource("2_gy5co")]
layout_mode = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ func get_string() -> String:

if option:
return _option_input.get_item_text(_option_input.selected).to_snake_case()

print("GET STRING ", input, " with ", variant_type)

match variant_type:
TYPE_STRING:
TYPE_STRING, TYPE_NODE_PATH:
return "'%s'" % input.replace("\\", "\\\\").replace("'", "\\'")
TYPE_VECTOR2:
return "Vector2(%s)" % input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ size_flags_horizontal = 3

[node name="BoolInput" type="MarginContainer" parent="InputSwitcher"]
unique_name_in_owner = true
visible = false
layout_mode = 2
theme_override_constants/margin_left = 8

Expand Down
57 changes: 26 additions & 31 deletions addons/block_code/ui/picker/categories/category_factory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ static func get_general_categories() -> Array[BlockCategory]:
variable_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.STRING
b.variant_type = TYPE_STRING
b.block_format = "Get String {var: STRING}"
b.statement = "VAR_DICT[{var}]"
variable_list.append(b)

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

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

b = BLOCKS["parameter_block"].instantiate()
b.block_format = "To String {int: INT}"
b.statement = "str({int})"
b.variant_type = TYPE_STRING
b.block_format = "To String {value: NIL}"
b.statement = "str({value})"
variable_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.INT
b.block_format = "Get Int {var: INT} from {node: NODE}"
b.statement = "{node}.VAR_DICT[{var}]"
b.variant_type = TYPE_INT
b.block_format = "Get Int {var: INT} from {node: NODE_PATH}"
b.statement = "get_node({node}).VAR_DICT[{var}]"
variable_list.append(b)

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

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.NODE
b.variant_type = TYPE_NODE_PATH
b.block_format = "This node"
b.statement = "self"
type_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.NODE
b.block_format = "%{name: STRING}"
b.statement = "%{name}"
b.statement = "get_path()"
type_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.STRING
b.block_format = "As String {value}"
b.statement = "String({value})"
b.variant_type = TYPE_NODE_PATH
b.block_format = "%{name: NIL}"
b.statement = "%{name}.get_path()"
type_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.INT
b.block_format = "As int {value}"
b.variant_type = TYPE_INT
b.block_format = "As int {value: NIL}"
b.statement = "int({value})"
type_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.FLOAT
b.block_format = "As float {value}"
b.variant_type = TYPE_FLOAT
b.block_format = "As float {value: NIL}"
b.statement = "float({value})"
type_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.BOOL
b.block_format = "As boolean {value}"
b.variant_type = TYPE_BOOL
b.block_format = "As boolean {value: NIL}"
b.statement = "bool({value})"
type_list.append(b)

b = BLOCKS["parameter_block"].instantiate()
b.block_type = Types.BlockType.VARIANT
b.block_format = "Get property {key: STRING} from {node: NODE}"
b.statement = "{node}.get({key})"
b.variant_type = TYPE_NIL
b.block_format = "Get property {key: STRING} from {node: NODE_PATH}"
b.statement = "get_node({node}).get({key})"
type_list.append(b)

b = BLOCKS["statement_block"].instantiate()
b.block_format = "Set property {key: STRING} in {node: NODE} to {value: VARIANT}"
b.statement = "{node}.set({key}, {value})"
b.block_format = "Set property {key: STRING} in {node: NODE_PATH} to {value: NIL}"
b.statement = "get_node({node}).set({key}, {value})"
type_list.append(b)

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

0 comments on commit 7f9a689

Please sign in to comment.