diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index 2ec6b4a..f6a0615 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -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. diff --git a/classes/util.gd b/classes/util.gd new file mode 100644 index 0000000..ce24d45 --- /dev/null +++ b/classes/util.gd @@ -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)