From 36c6077c5322528dc0f86fa5cdf9b657b5dcd262 Mon Sep 17 00:00:00 2001 From: The 64th Gamer <69170079+The64thGamer@users.noreply.github.com> Date: Sun, 6 Apr 2025 02:42:03 -0600 Subject: [PATCH] refactor, sine node --- Scripts/GL_Node.gd | 30 +++++++++++++++++++----------- Scripts/GL_Sine.gd | 11 +++++++++++ Scripts/GL_Sine.gd.uid | 1 + 3 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 Scripts/GL_Sine.gd create mode 100644 Scripts/GL_Sine.gd.uid diff --git a/Scripts/GL_Node.gd b/Scripts/GL_Node.gd index 3b980a5..291f88c 100644 --- a/Scripts/GL_Node.gd +++ b/Scripts/GL_Node.gd @@ -1,4 +1,5 @@ extends Node2D +class_name GL_Node var rows : Dictionary # 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(): if child.name != "Title": child.queue_free() - for row in rows: - if row.get("type","default") == "default": + for key in rows: + if rows[key].get("type","default") == "default": var nodeRow = load("res://Scenes/Nodes/Node Row.tscn") holder.call_deferred("add_child",nodeRow) - (nodeRow.get_node("Label") as Label).text = row.get("name","???") - _set_inout_type(nodeRow.get_node("Input") as Label,row.get("input","null")) - _set_inout_type(nodeRow.get_node("Output") as Label,row.get("output","null")) + (nodeRow.get_node("Label") as Label).text = str(key) + _set_inout_type(nodeRow.get_node("Input") as Label,rows[key].get("input","null")) + _set_inout_type(nodeRow.get_node("Output") as Label,rows[key].get("output","null")) -func _set_inout_type(label : Label , type : String): - match type: - "null": +func _set_inout_type(label:Label, value): + match typeof(value): + _: label.visible = false - "float": + TYPE_FLOAT: label.text = "◉" label.add_theme_color_override("font_color", Color.ROYAL_BLUE) - "bool": + TYPE_BOOL: label.text = "◆" label.add_theme_color_override("font_color", Color.ORANGE) - "color": + TYPE_COLOR: label.text = "▲" 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() diff --git a/Scripts/GL_Sine.gd b/Scripts/GL_Sine.gd new file mode 100644 index 0000000..fcc4c97 --- /dev/null +++ b/Scripts/GL_Sine.gd @@ -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 diff --git a/Scripts/GL_Sine.gd.uid b/Scripts/GL_Sine.gd.uid new file mode 100644 index 0000000..65febb9 --- /dev/null +++ b/Scripts/GL_Sine.gd.uid @@ -0,0 +1 @@ +uid://cetd8fp5y2ls0