refactor, sine node

This commit is contained in:
The 64th Gamer 2025-04-06 02:42:03 -06:00
parent 5accf456dc
commit 36c6077c53
3 changed files with 31 additions and 11 deletions

View file

@ -1,4 +1,5 @@
extends Node2D extends Node2D
class_name GL_Node
var rows : Dictionary var rows : Dictionary
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
@ -20,24 +21,31 @@ func _update_visuals():
for child in holder.get_children(): for child in holder.get_children():
if child.name != "Title": if child.name != "Title":
child.queue_free() child.queue_free()
for row in rows: for key in rows:
if row.get("type","default") == "default": if rows[key].get("type","default") == "default":
var nodeRow = load("res://Scenes/Nodes/Node Row.tscn") var nodeRow = load("res://Scenes/Nodes/Node Row.tscn")
holder.call_deferred("add_child",nodeRow) holder.call_deferred("add_child",nodeRow)
(nodeRow.get_node("Label") as Label).text = row.get("name","???") (nodeRow.get_node("Label") as Label).text = str(key)
_set_inout_type(nodeRow.get_node("Input") as Label,row.get("input","null")) _set_inout_type(nodeRow.get_node("Input") as Label,rows[key].get("input","null"))
_set_inout_type(nodeRow.get_node("Output") as Label,row.get("output","null")) _set_inout_type(nodeRow.get_node("Output") as Label,rows[key].get("output","null"))
func _set_inout_type(label : Label , type : String): func _set_inout_type(label:Label, value):
match type: match typeof(value):
"null": _:
label.visible = false label.visible = false
"float": TYPE_FLOAT:
label.text = "" label.text = ""
label.add_theme_color_override("font_color", Color.ROYAL_BLUE) label.add_theme_color_override("font_color", Color.ROYAL_BLUE)
"bool": TYPE_BOOL:
label.text = "" label.text = ""
label.add_theme_color_override("font_color", Color.ORANGE) label.add_theme_color_override("font_color", Color.ORANGE)
"color": TYPE_COLOR:
label.text = "" label.text = ""
label.add_theme_color_override("font_color", Color.WHITE_SMOKE) label.add_theme_color_override("font_color", Color.WHITE_SMOKE)
func _set_title(name:String):
(get_node("Node").get_node("Holder").get_node("Title") as Label).text = name
func _create_row(name:String,input,output):
rows[name] = {"input": input, "output": output}
_update_visuals()

11
Scripts/GL_Sine.gd Normal file
View file

@ -0,0 +1,11 @@
extends GL_Node
func _ready():
_set_title("Sine")
_create_row("Output",null,0.0)
_create_row("Length",1.0,null)
pass
func _process(delta):
rows["Output"]["output"] = sin(Time.get_ticks_msec() * rows["Length"].get("input",1))
pass

1
Scripts/GL_Sine.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://cetd8fp5y2ls0