miggor-StreamGraph/test_node_renderer.gd
2023-06-11 18:39:26 +03:00

53 lines
1.7 KiB
GDScript

extends PanelContainer
@onready var name_label: Label = %NameLabel
@onready var elements_container: VBoxContainer = %ElementsContainer
var node: DeckNode
const PortDrawer := preload("res://port_drawer.gd")
var port_drawer_scene := preload("res://port_drawer.tscn")
# THIS IS SUPER JANK AND A HACK FOR DEMONSTRATION PURPOSES
# PLEASE DO NOT ACTUALLY DO ANYTHING THIS CLASS DOES
# IN THE REAL PROJECT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
func _ready() -> void:
name_label.text = node.name
for i in node.input_ports.size():
var input_port := node.input_ports[i]
var port_drawer: PortDrawer = port_drawer_scene.instantiate()
elements_container.add_child(port_drawer)
port_drawer.set_input_enabled(true)
match input_port.descriptor:
"field":
port_drawer.add_field(input_port.label)
input_port.value_callback = port_drawer.get_text
"button":
port_drawer.add_button(input_port.label)
port_drawer.button_pressed.connect(func():
node._receive(i, DeckType.DeckTypeString.new("memes"))
)
_:
port_drawer.add_label(input_port.label)
for i in node.output_ports.size():
if elements_container.get_child_count() - 1 < i:
var pd: PortDrawer = port_drawer_scene.instantiate()
elements_container.add_child(pd)
var port_drawer: PortDrawer = elements_container.get_child(i)
port_drawer.set_output_enabled(true)
var output_port := node.output_ports[i]
match output_port.descriptor:
"field":
port_drawer.add_field(output_port.label)
output_port.value_callback = port_drawer.get_text
"button":
port_drawer.add_button(output_port.label)
port_drawer.button_pressed.connect(func():
node.send(i, DeckType.DeckTypeBool.new(true))
)
_:
port_drawer.add_label(output_port.label)