From e5d2cefa10a34728a06bf3c29266626c6027772f Mon Sep 17 00:00:00 2001 From: Dylan McCall Date: Thu, 24 Oct 2024 20:59:54 -0700 Subject: [PATCH] Add parameters list to block tooltips --- .../block_code/code_generation/block_definition.gd | 9 +++++++++ addons/block_code/ui/blocks/block/block.gd | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/addons/block_code/code_generation/block_definition.gd b/addons/block_code/code_generation/block_definition.gd index 26ac9e70..bab521c6 100644 --- a/addons/block_code/code_generation/block_definition.gd +++ b/addons/block_code/code_generation/block_definition.gd @@ -81,6 +81,15 @@ func _to_string(): return "%s - %s" % [name, target_node_class] +func get_input_parameters() -> Dictionary: + var result: Dictionary + for item in parse_display_template(display_template): + if item.has("in_parameter"): + var parameter = item.get("in_parameter") + result[parameter["name"]] = parameter["type"] + return result + + func get_output_parameters() -> Dictionary: var result: Dictionary for item in parse_display_template(display_template): diff --git a/addons/block_code/ui/blocks/block/block.gd b/addons/block_code/ui/blocks/block/block.gd index 989e48b8..1af0cdc4 100644 --- a/addons/block_code/ui/blocks/block/block.gd +++ b/addons/block_code/ui/blocks/block/block.gd @@ -224,6 +224,20 @@ func _get_tooltip(at_position: Vector2) -> String: lines.append("") lines.append("[code]{0}[/code]".format([definition.code_template.strip_edges()])) + var input_parameters := definition.get_input_parameters() + var output_parameters := definition.get_output_parameters() + + if input_parameters or output_parameters: + lines.append("") + + for parameter_name in input_parameters: + var parameter_type = input_parameters[parameter_name] + lines.append("{0}: [b]{1}[/b]".format([parameter_name, type_string(parameter_type)])) + + for parameter_name in output_parameters: + var parameter_type = output_parameters[parameter_name] + lines.append("{0}: [b]{1}[/b]".format([parameter_name, type_string(parameter_type)])) + if definition.variant_type != Variant.Type.TYPE_NIL: lines.append("") lines.append("Type: [b]{0}[/b]".format([type_string(definition.variant_type)]))