mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
sync port values in group instances
This commit is contained in:
parent
08e6bb2a17
commit
b2d96a471e
4 changed files with 36 additions and 4 deletions
|
@ -39,11 +39,13 @@ signal node_added(node: DeckNode)
|
||||||
## Emitted when a node has been removed from this deck.
|
## Emitted when a node has been removed from this deck.
|
||||||
signal node_removed(node: DeckNode)
|
signal node_removed(node: DeckNode)
|
||||||
|
|
||||||
|
#region group signals
|
||||||
signal node_added_to_group(node: DeckNode, assign_id: String, assign_to_self: bool, deck: Deck)
|
signal node_added_to_group(node: DeckNode, assign_id: String, assign_to_self: bool, deck: Deck)
|
||||||
signal node_removed_from_group(node_id: String, remove_connections: bool, deck: Deck)
|
signal node_removed_from_group(node_id: String, remove_connections: bool, deck: Deck)
|
||||||
signal nodes_connected_in_group(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int, deck: Deck)
|
signal nodes_connected_in_group(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int, deck: Deck)
|
||||||
signal nodes_disconnected_in_group(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int, deck: Deck)
|
signal nodes_disconnected_in_group(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int, deck: Deck)
|
||||||
|
signal node_port_value_updated(node_id: String, port_idx: int, new_value: Variant, deck: Deck)
|
||||||
|
#endregion
|
||||||
|
|
||||||
## Instantiate a node by its' [member DeckNode.node_type] and add it to this deck.[br]
|
## Instantiate a node by its' [member DeckNode.node_type] and add it to this deck.[br]
|
||||||
## See [method add_node_inst] for parameter descriptions.
|
## See [method add_node_inst] for parameter descriptions.
|
||||||
|
@ -74,6 +76,12 @@ func add_node_inst(node: DeckNode, assign_id: String = "", assign_to_self: bool
|
||||||
if is_group && emit_group_signals:
|
if is_group && emit_group_signals:
|
||||||
node_added_to_group.emit(node, assign_id, assign_to_self, self)
|
node_added_to_group.emit(node, assign_id, assign_to_self, self)
|
||||||
|
|
||||||
|
node.port_value_updated.connect(
|
||||||
|
func(port_idx: int, new_value: Variant):
|
||||||
|
if is_group && emit_group_signals:
|
||||||
|
node_port_value_updated.emit(node._id, port_idx, new_value, self)
|
||||||
|
)
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ static func add_group_from_dict(data: Dictionary, deck_id: String, instance_id:
|
||||||
group.node_removed_from_group.connect(DeckHolder._on_node_removed_from_group)
|
group.node_removed_from_group.connect(DeckHolder._on_node_removed_from_group)
|
||||||
group.nodes_connected_in_group.connect(DeckHolder._on_nodes_connected_in_group)
|
group.nodes_connected_in_group.connect(DeckHolder._on_nodes_connected_in_group)
|
||||||
group.nodes_disconnected_in_group.connect(DeckHolder._on_nodes_disconnected_in_group)
|
group.nodes_disconnected_in_group.connect(DeckHolder._on_nodes_disconnected_in_group)
|
||||||
|
group.node_port_value_updated.connect(DeckHolder._on_node_port_value_updated)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +65,7 @@ static func add_empty_group() -> Deck:
|
||||||
group.node_removed_from_group.connect(DeckHolder._on_node_removed_from_group)
|
group.node_removed_from_group.connect(DeckHolder._on_node_removed_from_group)
|
||||||
group.nodes_connected_in_group.connect(DeckHolder._on_nodes_connected_in_group)
|
group.nodes_connected_in_group.connect(DeckHolder._on_nodes_connected_in_group)
|
||||||
group.nodes_disconnected_in_group.connect(DeckHolder._on_nodes_disconnected_in_group)
|
group.nodes_disconnected_in_group.connect(DeckHolder._on_nodes_disconnected_in_group)
|
||||||
|
group.node_port_value_updated.connect(DeckHolder._on_node_port_value_updated)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,4 +160,16 @@ static func _on_nodes_disconnected_in_group(from_node_id: String, to_node_id: St
|
||||||
instance.disconnect_nodes(from_node_id, to_node_id, from_output_port, to_input_port)
|
instance.disconnect_nodes(from_node_id, to_node_id, from_output_port, to_input_port)
|
||||||
instance.emit_group_signals = true
|
instance.emit_group_signals = true
|
||||||
|
|
||||||
|
|
||||||
|
static func _on_node_port_value_updated(node_id: String, port_idx: int, new_value: Variant, deck: Deck) -> void:
|
||||||
|
var group_id := deck.id
|
||||||
|
for instance_id: String in decks[group_id]:
|
||||||
|
if instance_id == deck.instance_id:
|
||||||
|
continue
|
||||||
|
|
||||||
|
var instance: Deck = get_group_instance(group_id, instance_id)
|
||||||
|
instance.emit_group_signals = false
|
||||||
|
instance.get_node(node_id).get_all_ports()[port_idx].set_value_no_signal(new_value)
|
||||||
|
instance.emit_group_signals = true
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -64,6 +64,8 @@ signal incoming_connection_added(from_port: int)
|
||||||
## Emitted when a connection to this node has been removed.
|
## Emitted when a connection to this node has been removed.
|
||||||
signal incoming_connection_removed(from_port: int)
|
signal incoming_connection_removed(from_port: int)
|
||||||
|
|
||||||
|
signal port_value_updated(port_idx: int, new_value: Variant)
|
||||||
|
|
||||||
|
|
||||||
## Add an input port to this node. Usually only used at initialization.
|
## Add an input port to this node. Usually only used at initialization.
|
||||||
func add_input_port(type: DeckType.Types, label: String, descriptor: String = "") -> void:
|
func add_input_port(type: DeckType.Types, label: String, descriptor: String = "") -> void:
|
||||||
|
@ -85,10 +87,15 @@ func add_port(type: DeckType.Types, label: String, port_type: PortType, index_of
|
||||||
var port := Port.new(type, label, ports.size(), port_type, index_of_type, descriptor)
|
var port := Port.new(type, label, ports.size(), port_type, index_of_type, descriptor)
|
||||||
ports.append(port)
|
ports.append(port)
|
||||||
port_added.emit(ports.size() - 1)
|
port_added.emit(ports.size() - 1)
|
||||||
|
port.value_updated.connect(
|
||||||
|
func(new_value: Variant) -> void:
|
||||||
|
port_value_updated.emit(port.index, new_value)
|
||||||
|
)
|
||||||
ports_updated.emit()
|
ports_updated.emit()
|
||||||
|
|
||||||
|
|
||||||
## Remove a port from this node.
|
## Remove a port from this node.
|
||||||
|
## @deprecated
|
||||||
func remove_port(port_idx: int) -> void:
|
func remove_port(port_idx: int) -> void:
|
||||||
outgoing_connections.erase(port_idx)
|
outgoing_connections.erase(port_idx)
|
||||||
incoming_connections.erase(port_idx)
|
incoming_connections.erase(port_idx)
|
||||||
|
|
|
@ -25,7 +25,7 @@ var index_of_type: int
|
||||||
var index: int
|
var index: int
|
||||||
|
|
||||||
## The value of this port.
|
## The value of this port.
|
||||||
var value: Variant: set = set_value
|
var value: Variant
|
||||||
|
|
||||||
signal value_updated(new_value: Variant)
|
signal value_updated(new_value: Variant)
|
||||||
|
|
||||||
|
@ -50,10 +50,13 @@ func _init(
|
||||||
|
|
||||||
|
|
||||||
func set_value(v: Variant) -> void:
|
func set_value(v: Variant) -> void:
|
||||||
|
set_value_no_signal(v)
|
||||||
|
value_updated.emit(value)
|
||||||
|
|
||||||
|
|
||||||
|
func set_value_no_signal(v: Variant) -> void:
|
||||||
if v is Callable:
|
if v is Callable:
|
||||||
value = v.call()
|
value = v.call()
|
||||||
value_updated.emit(value)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
value = v
|
value = v
|
||||||
value_updated.emit(value)
|
|
||||||
|
|
Loading…
Reference in a new issue