miggor-StreamGraph/graph_node_renderer/obs_websocket_setup_dialog.gd
Eroax b8e65edcef Implement a temporary system for saving Credentials. (#38)
This handles adding the functionality for saving the Token and Channel for Twitch, as well as the Port and Password for OBS when handling connections.

Co-authored-by: Eroax <eroaxe.business@gmail.com>
Reviewed-on: https://codeberg.org/Eroax/StreamGraph/pulls/38
2024-01-15 05:35:16 +00:00

75 lines
1.8 KiB
GDScript

# (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 OBSWebsocketSetupDialog
@onready var port_spin_box: SpinBox = %PortSpinBox
@onready var password_line_edit: LineEdit = %PasswordLineEdit
@onready var connect_button: Button = %ConnectButton
signal connect_button_pressed(state: ConnectionState)
enum ConnectionState {
DISCONNECTED,
CONNECTING,
CONNECTED,
}
var state: ConnectionState
@onready var _old_port: int = port_spin_box.value
@onready var _old_password: String = password_line_edit.text
func get_port() -> int:
return int(port_spin_box.value)
func get_password() -> String:
return password_line_edit.text
func set_button_state(p_state: ConnectionState) -> void:
connect_button.disabled = p_state == ConnectionState.CONNECTING
state = p_state
match p_state:
ConnectionState.DISCONNECTED:
connect_button.text = "Connect"
ConnectionState.CONNECTING:
connect_button.text = "Connecting..."
ConnectionState.CONNECTED:
Connections.save_credentials({"port" : get_port(), "password" : get_password()}, "OBS")
connect_button.text = "Disconnect"
func _ready() -> void:
var loaded_creds = Connections.load_credentials("OBS")
if loaded_creds != null:
password_line_edit.text = loaded_creds.data.password
port_spin_box.value = loaded_creds.data.port
connect_button.pressed.connect(
func():
connect_button_pressed.emit(state)
)
canceled.connect(
func():
print("canceled")
port_spin_box.value = float(_old_port)
password_line_edit.text = _old_password
)
confirmed.connect(
func():
print("confirmed")
_old_port = int(port_spin_box.value)
_old_password = password_line_edit.text
)