From 0d546f4fc41d868ec53132ccec55e77602716069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sat, 16 Mar 2024 08:32:28 +0000 Subject: [PATCH] add a way to start RPC from default renderer (#112) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/112 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- graph_node_renderer/deck_holder_renderer.gd | 35 ++++++++++++- graph_node_renderer/deck_holder_renderer.tscn | 9 +++- graph_node_renderer/rpc_setup_dialog.gd | 50 +++++++++++++++++++ graph_node_renderer/rpc_setup_dialog.tscn | 44 ++++++++++++++++ main.gd | 12 +++++ rpc_renderer/rpc_renderer.gd | 2 - 6 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 graph_node_renderer/rpc_setup_dialog.gd create mode 100644 graph_node_renderer/rpc_setup_dialog.tscn diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index f2d5c95..7335630 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -45,6 +45,7 @@ var recent_path: String enum ConnectionsMenuId { OBS, TWITCH, + RPC, } enum DebugMenuId { @@ -67,9 +68,13 @@ var _deck_to_save: WeakRef @onready var obs_setup_dialog := $OBSWebsocketSetupDialog as OBSWebsocketSetupDialog @onready var twitch_setup_dialog := $Twitch_Setup_Dialog as TwitchSetupDialog +@onready var rpc_setup_dialog := $RPCSetupDialog as RPCSetupDialog + @onready var bottom_dock: BottomDock = %BottomDock -signal quit_completed +signal quit_completed() +signal rpc_start_requested(port: int) +signal rpc_stop_requested() func _ready() -> void: @@ -97,6 +102,32 @@ func _ready() -> void: ) add_recents_to_menu() + var rpc_port: int = RendererPersistence.get_or_create( + PERSISTENCE_NAMESPACE, "config", + "rpc_server_port", 6907 + ) + rpc_setup_dialog.set_port(rpc_port) + rpc_setup_dialog.start_requested.connect( + func(port: int): + rpc_start_requested.emit(port) + RendererPersistence.set_value( + PERSISTENCE_NAMESPACE, "config", + "rpc_server_port", port + ) + ) + rpc_setup_dialog.stop_requested.connect( + func(): + rpc_stop_requested.emit() + ) + + rpc_setup_dialog.confirmed.connect( + func(): + RendererPersistence.set_value( + PERSISTENCE_NAMESPACE, "config", + "rpc_server_port", rpc_setup_dialog.get_port() + ) + ) + tab_container.tab_close_requested.connect( func(tab: int): if tab_container.get_tab_metadata(tab, "dirty") and not tab_container.get_tab_metadata(tab, "group"): @@ -349,6 +380,8 @@ func _on_connections_id_pressed(id: int) -> void: obs_setup_dialog.popup_centered() ConnectionsMenuId.TWITCH: twitch_setup_dialog.popup_centered() + ConnectionsMenuId.RPC: + rpc_setup_dialog.popup_centered() func _on_obs_websocket_setup_dialog_connect_button_pressed(state: OBSWebsocketSetupDialog.ConnectionState) -> void: diff --git a/graph_node_renderer/deck_holder_renderer.tscn b/graph_node_renderer/deck_holder_renderer.tscn index 7acde6f..60070a1 100644 --- a/graph_node_renderer/deck_holder_renderer.tscn +++ b/graph_node_renderer/deck_holder_renderer.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=3 uid="uid://duaah5x0jhkn6"] +[gd_scene load_steps=26 format=3 uid="uid://duaah5x0jhkn6"] [ext_resource type="Script" path="res://graph_node_renderer/deck_holder_renderer.gd" id="1_67g2g"] [ext_resource type="PackedScene" uid="uid://b84f2ngtcm5b8" path="res://graph_node_renderer/tab_container_custom.tscn" id="1_s3ug2"] @@ -14,6 +14,7 @@ [ext_resource type="PackedScene" uid="uid://cuwou2aa7qfc2" path="res://graph_node_renderer/unsaved_changes_dialog_single_deck.tscn" id="8_qf6ve"] [ext_resource type="PackedScene" uid="uid://cvvkj138fg8jg" path="res://graph_node_renderer/unsaved_changes_dialog.tscn" id="9_4n0q6"] [ext_resource type="PackedScene" uid="uid://bu466w2w3q08c" path="res://graph_node_renderer/about_dialog.tscn" id="11_6ln7n"] +[ext_resource type="PackedScene" uid="uid://brfrufvkjwcor" path="res://graph_node_renderer/rpc_setup_dialog.tscn" id="12_1xrfk"] [sub_resource type="InputEventKey" id="InputEventKey_giamc"] device = -1 @@ -129,11 +130,13 @@ unique_name_in_owner = true [node name="Connections" type="PopupMenu" parent="MarginContainer/VSplitContainer/VBoxContainer/MenuBar"] unique_name_in_owner = true -item_count = 2 +item_count = 3 item_0/text = "OBS..." item_0/id = 0 item_1/text = "Twitch.." item_1/id = 1 +item_2/text = "RPC Server..." +item_2/id = 2 [node name="Debug" type="PopupMenu" parent="MarginContainer/VSplitContainer/VBoxContainer/MenuBar"] unique_name_in_owner = true @@ -185,6 +188,8 @@ script = ExtResource("5_3n36q") [node name="Twitch_Setup_Dialog" parent="." instance=ExtResource("7_7rhap")] +[node name="RPCSetupDialog" parent="." instance=ExtResource("12_1xrfk")] + [node name="UnsavedChangesDialogSingleDeck" parent="." instance=ExtResource("8_qf6ve")] [node name="UnsavedChangesDialog" parent="." instance=ExtResource("9_4n0q6")] diff --git a/graph_node_renderer/rpc_setup_dialog.gd b/graph_node_renderer/rpc_setup_dialog.gd new file mode 100644 index 0000000..9a5f81d --- /dev/null +++ b/graph_node_renderer/rpc_setup_dialog.gd @@ -0,0 +1,50 @@ +# (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) +extends ConfirmationDialog +class_name RPCSetupDialog + +@onready var port_spin_box: SpinBox = %PortSpinBox +@onready var start_server_button: Button = %StartServerButton + +var _old_port: int + +var is_started: bool = false + +signal start_requested(port: int) +signal stop_requested() + + +func _ready() -> void: + canceled.connect( + func(): + port_spin_box.value = float(_old_port) + ) + + confirmed.connect( + func(): + _old_port = int(port_spin_box.value) + ) + + +func _on_start_server_button_pressed() -> void: + if not is_started: + start_server_button.text = "Stop" + _old_port = int(port_spin_box.value) + start_requested.emit(int(port_spin_box.value)) + port_spin_box.editable = true + is_started = true + else: + start_server_button.text = "Start" + stop_requested.emit() + port_spin_box.editable = true + is_started = false + + +func set_port(port: int) -> void: + port_spin_box.value = port + _old_port = port + + +func get_port() -> int: + return int(port_spin_box.value) diff --git a/graph_node_renderer/rpc_setup_dialog.tscn b/graph_node_renderer/rpc_setup_dialog.tscn new file mode 100644 index 0000000..6198187 --- /dev/null +++ b/graph_node_renderer/rpc_setup_dialog.tscn @@ -0,0 +1,44 @@ +[gd_scene load_steps=2 format=3 uid="uid://brfrufvkjwcor"] + +[ext_resource type="Script" path="res://graph_node_renderer/rpc_setup_dialog.gd" id="1_7pkns"] + +[node name="RPCSetupDialog" type="ConfirmationDialog"] +title = "RPC Server Setup" +initial_position = 4 +size = Vector2i(320, 135) +script = ExtResource("1_7pkns") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 8.0 +offset_top = 8.0 +offset_right = -8.0 +offset_bottom = -49.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_vertical = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +text = "Port" + +[node name="PortSpinBox" type="SpinBox" parent="VBoxContainer/HBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +max_value = 25565.0 +value = 6907.0 + +[node name="StartServerButton" type="Button" parent="VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 6 +text = "Start" + +[connection signal="pressed" from="VBoxContainer/StartServerButton" to="." method="_on_start_server_button_pressed"] diff --git a/main.gd b/main.gd index bda6cab..ebd7594 100644 --- a/main.gd +++ b/main.gd @@ -8,6 +8,8 @@ const DEFAULT_RENDERER := preload("res://graph_node_renderer/deck_holder_rendere var deck_holder_renderer: DeckHolderRenderer = null var deck_holder_renderer_finished := false +@onready var rpc_renderer := $RPCRenderer as RPCRenderer + func _ready() -> void: get_tree().auto_accept_quit = false @@ -17,6 +19,8 @@ func _ready() -> void: deck_holder_renderer = DEFAULT_RENDERER.instantiate() add_child(deck_holder_renderer) deck_holder_renderer.quit_completed.connect(_on_deck_holder_renderer_quit_completed) + deck_holder_renderer.rpc_start_requested.connect(_on_deck_holder_renderer_rpc_start_requested) + deck_holder_renderer.rpc_stop_requested.connect(_on_deck_holder_renderer_rpc_stop_requested) func _on_deck_holder_renderer_quit_completed() -> void: @@ -26,6 +30,14 @@ func _on_deck_holder_renderer_quit_completed() -> void: get_tree().quit() +func _on_deck_holder_renderer_rpc_start_requested(port: int) -> void: + rpc_renderer.listen(port) + + +func _on_deck_holder_renderer_rpc_stop_requested() -> void: + rpc_renderer.stop() + + func _notification(what: int) -> void: if what == NOTIFICATION_WM_CLOSE_REQUEST: if deck_holder_renderer: diff --git a/rpc_renderer/rpc_renderer.gd b/rpc_renderer/rpc_renderer.gd index 8508d47..8836e26 100644 --- a/rpc_renderer/rpc_renderer.gd +++ b/rpc_renderer/rpc_renderer.gd @@ -93,8 +93,6 @@ func _ready() -> void: _ws.client_connected.connect(_on_ws_client_connected) _ws.client_disconnected.connect(_on_ws_client_disconnected) _ws.message_received.connect(_on_ws_message) - - listen() func listen(port := default_port) -> void: