From d06e9b03551f01df82a6fe3bbb74046bb65b6c88 Mon Sep 17 00:00:00 2001 From: The 64th Gamer <69170079+The64thGamer@users.noreply.github.com> Date: Mon, 7 Apr 2025 06:22:40 -0600 Subject: [PATCH] Nodes visually connect and send signals --- Scripts/GL_Node.gd | 36 +++++++++++++++++----------- Scripts/GL_Node_Point.gd | 51 +++++++++++++++++++++++++++++++--------- Scripts/GL_Sine.gd | 4 ++-- 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/Scripts/GL_Node.gd b/Scripts/GL_Node.gd index c0c7617..969e598 100644 --- a/Scripts/GL_Node.gd +++ b/Scripts/GL_Node.gd @@ -29,18 +29,26 @@ func _update_visuals(): if child.name != "Title": child.queue_free() for key in rows: - if rows[key].get("type","default") == "default": - var nodeRow = load("res://Scenes/Nodes/Node Row.tscn").instantiate() - holder.add_child(nodeRow) - (nodeRow.get_node("Label") as Label).text = str(key) - var input = nodeRow.get_node("Input") as GL_Node_Point - var output = nodeRow.get_node("Output") as GL_Node_Point - input.valueName = str(key) - input.mainNode = self - output.valueName = str(key) - output.mainNode = self - _set_inout_type(nodeRow.get_node("Input") as Button,rows[key]["input"]) - _set_inout_type(nodeRow.get_node("Output") as Button,rows[key]["output"]) + var nodeRow = load("res://Scenes/Nodes/Node Row.tscn").instantiate() + holder.add_child(nodeRow) + nodeRow.name = str(key) + (nodeRow.get_node("Label") as Label).text = str(key) + var input = nodeRow.get_node("Input") as GL_Node_Point + var output = nodeRow.get_node("Output") as GL_Node_Point + input.valueName = str(key) + input.mainNode = self + output.valueName = str(key) + output.mainNode = self + _set_inout_type(nodeRow.get_node("Input") as Button,rows[key]["input"]) + _set_inout_type(nodeRow.get_node("Output") as Button,rows[key]["output"]) + +func give_input_point_pos(name:String) -> Vector2: + var holder = get_node("Holder").get_node(name) + if holder == null: + return global_position + else: + holder = holder.get_node("Input") as GL_Node_Point + return holder.global_position + Vector2(holder.size.x/2,holder.size.y/2) func _set_inout_type(label:Button, value): match typeof(value): @@ -67,7 +75,7 @@ func _recieve_input(inputName:String,value): if rows.has(inputName): rows[inputName]["input"] = value -func _send_input(output_name: String, value): +func _send_input(output_name: String): if not rows.has(output_name): return @@ -76,7 +84,7 @@ func _send_input(output_name: String, value): var target = conn.get("target", null) var input_name = conn.get("input_name", null) if target and input_name: - target._recieve_input(input_name, value) + target._recieve_input(input_name, rows[output_name]["output"]) func _create_connection(target:GL_Node,input_name:String,output_name:String): if not rows.has(output_name): diff --git a/Scripts/GL_Node_Point.gd b/Scripts/GL_Node_Point.gd index 5ec33fc..286c2c1 100644 --- a/Scripts/GL_Node_Point.gd +++ b/Scripts/GL_Node_Point.gd @@ -7,22 +7,51 @@ var dragging:bool var previewLine:Line2D = null var mouseInside:bool var lastToDrag:bool +var allLines: Array func _process(delta): if dragging: if previewLine == null: - previewLine = Line2D.new() - previewLine.position = Vector2.ZERO - add_child(previewLine) - previewLine.width = 5 - previewLine.default_color = Color.WHITE - previewLine.add_point(Vector2.ZERO) - previewLine.add_point(Vector2.ZERO) - previewLine.points[0] = Vector2(size.x / 2, size.y / 2) - previewLine.begin_cap_mode = Line2D.LINE_CAP_ROUND - previewLine.end_cap_mode = Line2D.LINE_CAP_ROUND + previewLine = _create_line() previewLine.points[1] = get_viewport().get_mouse_position() - previewLine.global_position + + var connections = mainNode.rows[valueName].get("connections",[]) + if connections != []: + var iter = 0 + for child:Line2D in allLines: + var output = mainNode.rows[valueName]["output"] + match typeof(output): + TYPE_FLOAT: + child.default_color = Color(0.254902 * output, 0.411765 * output, 0.882353 * output, 1) + TYPE_BOOL: + if output: + child.default_color = Color.ORANGE + else: + child.default_color = Color.BLACK + TYPE_COLOR: + child.default_color = output + child.points[1] = (connections[iter]["target"] as GL_Node).give_input_point_pos(connections[iter]["input_name"]) - child.global_position + iter += 1 +func _create_line() -> Line2D: + var previewLine = Line2D.new() + previewLine.position = Vector2.ZERO + previewLine.width = 5 + previewLine.default_color = Color.WHITE + previewLine.add_point(Vector2.ZERO) + previewLine.add_point(Vector2.ZERO) + previewLine.points[0] = Vector2(size.x / 2, size.y / 2) + previewLine.begin_cap_mode = Line2D.LINE_CAP_ROUND + previewLine.end_cap_mode = Line2D.LINE_CAP_ROUND + add_child(previewLine) + return previewLine + +func update_lines(): + for child in allLines: + child.queue_free() + allLines = [] + for child in mainNode.rows[valueName].get("connections",[]): + allLines.append(_create_line()) func _input(event): if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: @@ -46,7 +75,6 @@ func _finish_drag(): previewLine.queue_free() dragging = false elif mouseInside: - print("YESSS") for node in get_tree().get_nodes_in_group("Outputs"): if node is GL_Node_Point: node._node_connect(mainNode,valueName) @@ -55,3 +83,4 @@ func _node_connect(node:GL_Node,inputValue:String): if not lastToDrag: return mainNode._create_connection(node,inputValue,valueName) + update_lines() diff --git a/Scripts/GL_Sine.gd b/Scripts/GL_Sine.gd index 26cb53e..ba20afd 100644 --- a/Scripts/GL_Sine.gd +++ b/Scripts/GL_Sine.gd @@ -3,10 +3,10 @@ extends GL_Node func _ready(): _set_title("Sine") _create_row("Output",null,0.0) - _create_row("Length",1.0,null) + _create_row("Length",0.01,null) pass func _process(delta): super._process(delta) rows["Output"]["output"] = sin(Time.get_ticks_msec() * rows["Length"].get("input",1)) - pass + _send_input("Output")