Nodes visually connect and send signals

This commit is contained in:
The 64th Gamer 2025-04-07 06:22:40 -06:00
parent ea1bff6ec6
commit d06e9b0355
3 changed files with 64 additions and 27 deletions

View file

@ -29,9 +29,9 @@ 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.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
@ -42,6 +42,14 @@ func _update_visuals():
_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):
TYPE_FLOAT:
@ -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):

View file

@ -7,13 +7,35 @@ 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 = _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
add_child(previewLine)
previewLine.width = 5
previewLine.default_color = Color.WHITE
previewLine.add_point(Vector2.ZERO)
@ -21,8 +43,15 @@ func _process(delta):
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.points[1] = get_viewport().get_mouse_position() - previewLine.global_position
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()

View file

@ -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")