From f57374f3e209c591f9c3cbb586365f9c02b15a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Thu, 22 Feb 2024 07:23:25 +0000 Subject: [PATCH] add send id system (#75) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addresses https://codeberg.org/StreamGraph/StreamGraph/issues/59#issuecomment-1572604 Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/75 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- classes/deck/deck_node.gd | 16 +++++++++++++--- classes/deck/nodes/general/delay.gd | 2 +- classes/deck/nodes/general/if_true.gd | 4 ++-- classes/deck/nodes/general/is_equal.gd | 2 +- classes/deck/nodes/general/print.gd | 2 +- classes/deck/nodes/general/set_deck_var.gd | 2 +- classes/deck/nodes/group/group_node.gd | 4 ++-- classes/deck/nodes/group/group_output_node.gd | 4 ++-- classes/deck/nodes/obs/obs_scene_list.gd | 2 +- .../deck/nodes/obs/obs_set_source_transform.gd | 2 +- classes/deck/nodes/obs/obs_switch_scene.gd | 2 +- .../nodes/obs/obs_websocket_generic_request.gd | 2 +- classes/deck/nodes/test/test_types.gd | 2 +- .../twitch/twitch_add_eventsub_subscription.gd | 2 +- classes/deck/nodes/twitch/twitch_join_chat.gd | 2 +- classes/deck/nodes/twitch/twitch_leave_chat.gd | 2 +- .../twitch_remove_eventsub_subscription.gd | 2 +- classes/deck/nodes/twitch/twitch_send_chat.gd | 2 +- script_templates/DeckNode/node_template.gd | 2 +- 19 files changed, 34 insertions(+), 24 deletions(-) diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index 45601e1..11cdfa7 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -20,6 +20,8 @@ var incoming_connections: Dictionary ## A list of [Port]s on this node. var ports: Array[Port] +var _last_send_id: String + ## The deck this node belongs to. var _belonging_to: Deck ## A unique identifier for this node. @@ -127,18 +129,26 @@ func remove_port(port_idx: int) -> void: ## Send data to all outgoing connections on port [param from_output_port]. -func send(from_output_port: int, data: Variant, extra_data: Array = []) -> void: +func send(from_output_port: int, data: Variant, send_id: String = UUID.v4()) -> void: if outgoing_connections.get(from_output_port) == null: return for node: String in outgoing_connections[from_output_port]: for input_port: int in outgoing_connections[from_output_port][node]: - get_node(node)._receive(input_port, data, extra_data) + get_node(node).handle_receive(input_port, data, send_id) + + +func handle_receive(to_input_port: int, data: Variant, send_id: String) -> void: + if send_id == _last_send_id: + return + + _last_send_id = send_id + _receive(to_input_port, data) ## Virtual function that's called when this node receives data from another node's [method send] call. @warning_ignore("unused_parameter") -func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: +func _receive(to_input_port: int, data: Variant) -> void: pass diff --git a/classes/deck/nodes/general/delay.gd b/classes/deck/nodes/general/delay.gd index faacb00..2b1bbf5 100644 --- a/classes/deck/nodes/general/delay.gd +++ b/classes/deck/nodes/general/delay.gd @@ -17,7 +17,7 @@ func _init(): -func _receive(_to_input_port : int, data: Variant, _extra_data: Array = []) -> void: +func _receive(_to_input_port : int, data: Variant) -> void: thread = Thread.new() thread.start(handle_delay.bind(data)) diff --git a/classes/deck/nodes/general/if_true.gd b/classes/deck/nodes/general/if_true.gd index fcba112..4bffcde 100644 --- a/classes/deck/nodes/general/if_true.gd +++ b/classes/deck/nodes/general/if_true.gd @@ -25,9 +25,9 @@ func _init() -> void: ) -func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: +func _receive(to_input_port: int, data: Variant) -> void: if to_input_port != 1: return if await resolve_input_port_value_async(0): - send(0, data, extra_data) + send(0, data) diff --git a/classes/deck/nodes/general/is_equal.gd b/classes/deck/nodes/general/is_equal.gd index b819427..8bb5a6d 100644 --- a/classes/deck/nodes/general/is_equal.gd +++ b/classes/deck/nodes/general/is_equal.gd @@ -34,7 +34,7 @@ func _value_request(_on_port: int) -> Variant: return a == b -func _receive(on_port: int, data: Variant, _extra_data: Array = []) -> void: +func _receive(on_port: int, data: Variant) -> void: if on_port == 0: var b = await resolve_input_port_value_async(1) if data == b: diff --git a/classes/deck/nodes/general/print.gd b/classes/deck/nodes/general/print.gd index 3f17de6..7ee2697 100644 --- a/classes/deck/nodes/general/print.gd +++ b/classes/deck/nodes/general/print.gd @@ -32,7 +32,7 @@ func _init() -> void: ) -func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: +func _receive(to_input_port: int, data: Variant) -> void: if to_input_port != 1: return diff --git a/classes/deck/nodes/general/set_deck_var.gd b/classes/deck/nodes/general/set_deck_var.gd index 50e72aa..52646a9 100644 --- a/classes/deck/nodes/general/set_deck_var.gd +++ b/classes/deck/nodes/general/set_deck_var.gd @@ -34,7 +34,7 @@ func _init() -> void: ) -func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> void: +func _receive(to_input_port: int, _data: Variant) -> void: if to_input_port != 2: return diff --git a/classes/deck/nodes/group/group_node.gd b/classes/deck/nodes/group/group_node.gd index 25430fd..38ceab6 100644 --- a/classes/deck/nodes/group/group_node.gd +++ b/classes/deck/nodes/group/group_node.gd @@ -73,8 +73,8 @@ func recalculate_ports() -> void: 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 _receive(to_input_port: int, data: Variant): + input_node.send(get_input_ports()[to_input_port].index_of_type, data) func _value_request(from_port: int) -> Variant: diff --git a/classes/deck/nodes/group/group_output_node.gd b/classes/deck/nodes/group/group_output_node.gd index 9bc90fc..e9351a7 100644 --- a/classes/deck/nodes/group/group_output_node.gd +++ b/classes/deck/nodes/group/group_output_node.gd @@ -74,5 +74,5 @@ func _post_load() -> void: ) -func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: - group_node.send(group_node.get_output_ports()[to_input_port].index_of_type, data, extra_data) +func _receive(to_input_port: int, data: Variant) -> void: + group_node.send(group_node.get_output_ports()[to_input_port].index_of_type, data) diff --git a/classes/deck/nodes/obs/obs_scene_list.gd b/classes/deck/nodes/obs/obs_scene_list.gd index 5cb873a..c6c09af 100644 --- a/classes/deck/nodes/obs/obs_scene_list.gd +++ b/classes/deck/nodes/obs/obs_scene_list.gd @@ -26,7 +26,7 @@ func _init() -> void: ) -func _receive(on_virtual_port: int, _data: Variant, _extra_data: Array = []) -> void: +func _receive(on_virtual_port: int, _data: Variant) -> void: if on_virtual_port != 0: return diff --git a/classes/deck/nodes/obs/obs_set_source_transform.gd b/classes/deck/nodes/obs/obs_set_source_transform.gd index a3c3496..e2c1aff 100644 --- a/classes/deck/nodes/obs/obs_set_source_transform.gd +++ b/classes/deck/nodes/obs/obs_set_source_transform.gd @@ -46,7 +46,7 @@ func _init() -> void: ) -func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> void: +func _receive(to_input_port: int, _data: Variant) -> void: #{ "scene_item_transform": { "alignment": 5, "bounds_alignment": 0, "bounds_height": 0, "bounds_type": "OBS_BOUNDS_NONE", "bounds_width": 0, "crop_bottom": 0, "crop_left": 0, "crop_right": 0, "crop_top": 0, "height": 257, "position_x": 1800, "position_y": 414, "rotation": 0, "scale_x": 1, "scale_y": 1, "source_height": 257, "source_width": 146, "width": 146 }} if to_input_port != 3: return diff --git a/classes/deck/nodes/obs/obs_switch_scene.gd b/classes/deck/nodes/obs/obs_switch_scene.gd index ab57754..f8b8d3b 100644 --- a/classes/deck/nodes/obs/obs_switch_scene.gd +++ b/classes/deck/nodes/obs/obs_switch_scene.gd @@ -25,7 +25,7 @@ func _init() -> void: ) -func _receive(on_input_port: int, _data: Variant, _extra_data: Array = []) -> void: +func _receive(on_input_port: int, _data: Variant) -> void: if on_input_port != 1: return diff --git a/classes/deck/nodes/obs/obs_websocket_generic_request.gd b/classes/deck/nodes/obs/obs_websocket_generic_request.gd index 9a0653d..b2732fb 100644 --- a/classes/deck/nodes/obs/obs_websocket_generic_request.gd +++ b/classes/deck/nodes/obs/obs_websocket_generic_request.gd @@ -37,7 +37,7 @@ func _init() -> void: ) -func _receive(on_virtual_port: int, _data: Variant, _extra_data: Array = []) -> void: +func _receive(on_virtual_port: int, _data: Variant) -> void: if on_virtual_port != 2: return diff --git a/classes/deck/nodes/test/test_types.gd b/classes/deck/nodes/test/test_types.gd index af1faf7..5f55db0 100644 --- a/classes/deck/nodes/test/test_types.gd +++ b/classes/deck/nodes/test/test_types.gd @@ -28,7 +28,7 @@ func _init() -> void: add_input_port(DeckType.Types.BOOL, "Send", "button") -func _receive(to_input_port: int, data: Variant, _extra_data: Array = []) -> void: +func _receive(to_input_port: int, data: Variant) -> void: if to_input_port == 6: send(0, false) send(1, 1.0) diff --git a/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd b/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd index 33d8e2a..2efe1ea 100644 --- a/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd +++ b/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd @@ -23,7 +23,7 @@ func _init(): -func _receive(to_input_port, _data: Variant, _extra_data: Array = []): +func _receive(to_input_port, _data: Variant): if to_input_port != 2: diff --git a/classes/deck/nodes/twitch/twitch_join_chat.gd b/classes/deck/nodes/twitch/twitch_join_chat.gd index 93c1102..171851e 100644 --- a/classes/deck/nodes/twitch/twitch_join_chat.gd +++ b/classes/deck/nodes/twitch/twitch_join_chat.gd @@ -19,7 +19,7 @@ func _init(): -func _receive(to_input_port, _data: Variant, _extra_data: Array = []): +func _receive(to_input_port, _data: Variant): if to_input_port != 1: diff --git a/classes/deck/nodes/twitch/twitch_leave_chat.gd b/classes/deck/nodes/twitch/twitch_leave_chat.gd index 5f727b4..31fdc5d 100644 --- a/classes/deck/nodes/twitch/twitch_leave_chat.gd +++ b/classes/deck/nodes/twitch/twitch_leave_chat.gd @@ -19,7 +19,7 @@ func _init(): -func _receive(to_input_port, _data: Variant, _extra_data: Array = []): +func _receive(to_input_port, _data: Variant): if to_input_port != 1: diff --git a/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd b/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd index f8c0021..b4c7287 100644 --- a/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd +++ b/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd @@ -17,7 +17,7 @@ func _init(): -func _receive(to_input_port, _data: Variant, _extra_data: Array = []): +func _receive(to_input_port, _data: Variant): if to_input_port != 1: diff --git a/classes/deck/nodes/twitch/twitch_send_chat.gd b/classes/deck/nodes/twitch/twitch_send_chat.gd index 59fc7ab..b988ad0 100644 --- a/classes/deck/nodes/twitch/twitch_send_chat.gd +++ b/classes/deck/nodes/twitch/twitch_send_chat.gd @@ -28,7 +28,7 @@ func _init(): -func _receive(to_input_port, _data: Variant, _extra_data: Array = []): +func _receive(to_input_port, _data: Variant): if to_input_port != 2: diff --git a/script_templates/DeckNode/node_template.gd b/script_templates/DeckNode/node_template.gd index 6f9f72c..207afda 100644 --- a/script_templates/DeckNode/node_template.gd +++ b/script_templates/DeckNode/node_template.gd @@ -13,5 +13,5 @@ func _init() -> void: -func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: +func _receive(to_input_port: int, data: Variant) -> void: pass