mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
add utility method to connect to a signal safely (#103)
Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/103 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
parent
18b83f5b26
commit
f43c5ecafd
2 changed files with 14 additions and 4 deletions
|
@ -76,10 +76,10 @@ signal renamed(new_name: String)
|
|||
|
||||
|
||||
func connect_rpc_signals() -> void:
|
||||
port_added.connect(RPCSignalLayer._on_node_port_added.bind(self))
|
||||
ports_updated.connect(RPCSignalLayer._on_node_ports_updated.bind(self))
|
||||
port_value_updated.connect(RPCSignalLayer._on_node_port_value_updated.bind(self))
|
||||
renamed.connect(RPCSignalLayer._on_node_renamed.bind(self))
|
||||
Util.safe_connect(port_added, RPCSignalLayer._on_node_port_added.bind(self))
|
||||
Util.safe_connect(ports_updated, RPCSignalLayer._on_node_ports_updated.bind(self))
|
||||
Util.safe_connect(port_value_updated, RPCSignalLayer._on_node_port_value_updated.bind(self))
|
||||
Util.safe_connect(renamed, RPCSignalLayer._on_node_renamed.bind(self))
|
||||
|
||||
|
||||
## Add an input port to this node. Usually only used at initialization.
|
||||
|
|
10
classes/util.gd
Normal file
10
classes/util.gd
Normal file
|
@ -0,0 +1,10 @@
|
|||
# (c) 2023-present Eroax
|
||||
# (c) 2023-present Yagich
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
class_name Util
|
||||
|
||||
|
||||
## Connects the [param p_func] to [param p_signal] if that connection doesn't already exist.
|
||||
static func safe_connect(p_signal: Signal, p_func: Callable) -> void:
|
||||
if not p_signal.is_connected(p_func):
|
||||
p_signal.connect(p_func)
|
Loading…
Reference in a new issue