mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
c4e35043df
no longer using classes for every type. the type system has been greatly simplified, with the added bonus that it hooks directly into GraphEdit's slot type system. connections will still fail if the type conversion fails, which may be used by other renderers. the type conversion map is straightforward to understand, and easy to extend should the need arise (hopefully it shouldn't). Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/8 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
69 lines
1.6 KiB
GDScript
69 lines
1.6 KiB
GDScript
extends DeckNode
|
|
|
|
var group_id: String
|
|
var input_node: DeckNode
|
|
var output_node: DeckNode
|
|
|
|
var extra_ports: Array
|
|
|
|
|
|
func _init() -> void:
|
|
name = "Group"
|
|
node_type = "group_node"
|
|
props_to_serialize = [&"group_id", &"extra_ports"]
|
|
appears_in_search = false
|
|
|
|
|
|
func _pre_connection() -> void:
|
|
for port_type: PortType in extra_ports:
|
|
var index_of_type: int
|
|
match port_type:
|
|
PortType.OUTPUT:
|
|
add_output_port(DeckType.Types.ANY, "Output %s" % get_output_ports().size())
|
|
PortType.INPUT:
|
|
add_input_port(DeckType.Types.ANY, "Input %s" % get_input_ports().size())
|
|
|
|
|
|
func init_io() -> void:
|
|
var group: Deck = _belonging_to.groups.get(group_id) as Deck
|
|
if !group:
|
|
return
|
|
|
|
input_node = group.get_node(group.group_input_node)
|
|
output_node = group.get_node(group.group_output_node)
|
|
|
|
recalculate_ports()
|
|
setup_connections()
|
|
|
|
|
|
func setup_connections() -> void:
|
|
input_node.ports_updated.connect(recalculate_ports)
|
|
output_node.ports_updated.connect(recalculate_ports)
|
|
|
|
|
|
func recalculate_ports() -> void:
|
|
ports.clear()
|
|
|
|
for output_port: Port in output_node.get_input_ports():
|
|
add_output_port(
|
|
DeckType.Types.ANY,
|
|
"Output %s" % output_port.index
|
|
)
|
|
|
|
for input_port: Port in input_node.get_output_ports():
|
|
add_input_port(
|
|
DeckType.Types.ANY,
|
|
"Input %s" % input_port.index
|
|
)
|
|
|
|
extra_ports.clear()
|
|
for port in ports:
|
|
extra_ports.append(port.port_type)
|
|
|
|
|
|
func _receive(to_input_port: int, data: Variant, extra_data: Array = []):
|
|
input_node.send(get_input_ports()[to_input_port].index_of_type, data, extra_data)
|
|
|
|
|
|
func _value_request(from_port: int) -> Variant:
|
|
return output_node.request_value(from_port)
|