From f536ddf213a6e69381705621f8ae2bd42c4bd64d Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Wed, 25 Feb 2026 14:10:41 -0600 Subject: [PATCH] Created SC Editor Plugin Created plugin to interact with StreamController WebSocket plugin, for Linux, to allow Stream Deck Buttons to control the Godot Editor. --- addons/sc_editor/plugin.cfg | 7 +++ addons/sc_editor/plugin.gd | 92 ++++++++++++++++++++++++++++++++++ addons/sc_editor/plugin.gd.uid | 1 + 3 files changed, 100 insertions(+) create mode 100644 addons/sc_editor/plugin.cfg create mode 100644 addons/sc_editor/plugin.gd create mode 100644 addons/sc_editor/plugin.gd.uid diff --git a/addons/sc_editor/plugin.cfg b/addons/sc_editor/plugin.cfg new file mode 100644 index 00000000..4e01b578 --- /dev/null +++ b/addons/sc_editor/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="StreamController Godot Editor" +description="Plugin for connecting to a WebSocket server plugin for StreamController to control the Godot Editor." +author="Mario Steele" +version="1.0" +script="plugin.gd" diff --git a/addons/sc_editor/plugin.gd b/addons/sc_editor/plugin.gd new file mode 100644 index 00000000..069a76d6 --- /dev/null +++ b/addons/sc_editor/plugin.gd @@ -0,0 +1,92 @@ +@tool +extends EditorPlugin + +var _socket: WebSocketPeer +var connection_state: WebSocketPeer.State = WebSocketPeer.STATE_CLOSED +var auto_reconnect: bool = false +var connected: bool = false + +func _enable_plugin() -> void: + pass + +func _disable_plugin() -> void: + pass + + +func _enter_tree() -> void: + print("Plugin enabled") + _socket = WebSocketPeer.new() + connection_state = WebSocketPeer.STATE_CONNECTING + _socket.connect_to_url("localhost:8765") + +func _exit_tree() -> void: + print("Plugin disabled") + if connection_state == WebSocketPeer.STATE_OPEN: + _socket.close(1000, "Plugin Disabled") + _socket = null + + +func _process(d: float) -> void: + if connection_state == WebSocketPeer.STATE_CLOSED: return + + _socket.poll() + var state = _socket.get_ready_state() + if state == WebSocketPeer.STATE_CLOSED and not auto_reconnect: + if connected: + print("Connection closed to StreamController, NOT reconnecting.") + connected = false + connection_state = state + return + + if state == WebSocketPeer.STATE_CLOSED and auto_reconnect: + print("Connection lost to StreamController, attempting to reconnect...") + _socket.connect_to_url("localhost:8765") + connection_state = WebSocketPeer.STATE_CONNECTING + return + + if state == WebSocketPeer.STATE_OPEN and not connected: + print("Connecting to StreamController.") + connected = true + + connection_state = state + if state == WebSocketPeer.STATE_OPEN: + _read_data() + +func _read_data() -> void: + while (_socket.get_available_packet_count()): + var pckt = _socket.get_packet().get_string_from_utf8() + var cmd := JSON.parse_string(pckt) + if cmd == null or cmd is not Dictionary: + print("Invalid Packet received: %s" % pckt) + continue + + if not cmd.has("identifier") or not cmd.has("action"): + print("Invalid command received: %s" % cmd) + continue + + if cmd.identifier != "org.godotengine.sc-plugin": + continue + + if cmd.action == "run-main": + EditorInterface.play_main_scene() + elif cmd.action == "run-current": + EditorInterface.play_current_scene() + elif cmd.action == "run-scene": + EditorInterface.play_custom_scene(cmd.arguments) + elif cmd.action == "stop-run": + if EditorInterface.is_playing_scene(): + EditorInterface.stop_playing_scene() + elif cmd.action == "save-project": + EditorInterface.save_all_scenes() + elif cmd.action == "show-2d": + EditorInterface.set_main_screen_editor("2D") + elif cmd.action == "show-3d": + EditorInterface.set_main_screen_editor("3D") + elif cmd.action == "show-script": + EditorInterface.set_main_screen_editor("Script") + elif cmd.action == "show-assetlib": + EditorInterface.set_main_screen_editor("AssetLib") + elif cmd.action == "restart-editor-no-save": + EditorInterface.restart_editor(false) + elif cmd.action == "restart-editor-save": + EditorInterface.restart_editor(true) diff --git a/addons/sc_editor/plugin.gd.uid b/addons/sc_editor/plugin.gd.uid new file mode 100644 index 00000000..ad2be7f0 --- /dev/null +++ b/addons/sc_editor/plugin.gd.uid @@ -0,0 +1 @@ +uid://bp1d8ypclmecq