Re-Enabled streamdeck plugin

This commit is contained in:
2025-07-19 18:23:35 +10:00
parent 1ad3dc37ec
commit 7f9b652918
6 changed files with 96 additions and 18 deletions

View File

@@ -1,12 +1,19 @@
@tool
extends EditorPlugin
## StreamDeck Editor Plugin
##
## This plugin integrates Elgato StreamDeck hardware with the PNGTuber application.
## It registers the ElgatoStreamDeck singleton for WebSocket communication with StreamDeck software.
const AUTOLOAD_NAME = "ElgatoStreamDeck"
## Called when the plugin enters the editor tree
## Registers the StreamDeck singleton autoload
func _enter_tree():
add_autoload_singleton(AUTOLOAD_NAME, "res://addons/godot-streamdeck-addon/singleton.gd")
pass
## Called when the plugin exits the editor tree
## Removes the StreamDeck singleton autoload
func _exit_tree():
remove_autoload_singleton(AUTOLOAD_NAME)
pass

View File

@@ -1,17 +1,27 @@
extends Node
## StreamDeck Integration Singleton
##
## This singleton manages WebSocket communication with Elgato StreamDeck software.
## It handles button press events and translates them into application actions like
## costume changes, signal emissions, and scene management.
## Button actions supported by the StreamDeck plugin
const ButtonAction = {
EMIT_SIGNAL = "games.boyne.godot.emitsignal",
SWITCH_SCENE = "games.boyne.godot.switchscene",
RELOAD_SCENE = "games.boyne.godot.reloadscene",
}
## Button events from StreamDeck hardware
const ButtonEvent = {
KEY_UP = "keyUp",
KEY_DOWN = "keyDown"
}
## Emitted when a StreamDeck button is released
signal on_key_up
## Emitted when a StreamDeck button is pressed
signal on_key_down
const PLUGIN_NAME = "games.boyne.godot.sdPlugin"
@@ -19,19 +29,36 @@ const WEBSOCKET_URL = "127.0.0.1:%s/ws"
var _socket := WebSocketPeer.new()
var _config := ConfigFile.new()
var _is_connected := false
## Initialize StreamDeck connection if enabled in settings
func _ready() -> void:
_check_and_connect()
## Check settings and connect/disconnect as needed
func _check_and_connect() -> void:
var should_connect = Saving.settings.get("useStreamDeck", false)
if Saving.settings.has("useStreamDeck"):
if !Saving.settings["useStreamDeck"]:
return
else:
return
_load_config(_get_config_path())
_socket.connect_to_url(_get_websocket_url())
if should_connect and not _is_connected:
_load_config(_get_config_path())
_socket.connect_to_url(_get_websocket_url())
_is_connected = true
set_process(true)
elif not should_connect and _is_connected:
_socket.close()
_is_connected = false
set_process(false)
## Process WebSocket communication each frame
## Handles incoming button events and routes them to appropriate actions
func _process(delta) -> void:
if not _is_connected:
return
# Check if setting was changed and we need to disconnect
if not Saving.settings.get("useStreamDeck", false):
_check_and_connect()
return
_socket.poll()
var state = _socket.get_ready_state()
@@ -68,9 +95,13 @@ func _process(delta) -> void:
WebSocketPeer.STATE_CLOSED:
set_process(false)
## Get the WebSocket URL with port from config
## Returns: String URL for WebSocket connection
func _get_websocket_url() -> String:
return WEBSOCKET_URL % _config.get_value("bridge", "port", "8080")
## Get the platform-specific path to StreamDeck plugin config
## Returns: String path to plugin.ini file
func _get_config_path() -> String:
match OS.get_name():
"Windows":
@@ -79,6 +110,14 @@ func _get_config_path() -> String:
return "%s/com.elgato.StreamDeck/Plugins/%s/plugin.ini" % [OS.get_config_dir(), PLUGIN_NAME]
return ""
## Load configuration from StreamDeck plugin directory
## @param path: String path to the config file
func _load_config(path: String) -> void:
var file = FileAccess.open(path, FileAccess.READ)
_config.parse(file.get_as_text())
if file:
_config.parse(file.get_as_text())
file.close()
## Force reconnection check - called when settings change
func refresh_connection() -> void:
_check_and_connect()