From 523d5e478b03d0ffb8e5bb4deca9ec9a6fe3ce7c Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 1 Aug 2021 15:44:24 +0200 Subject: [PATCH] Added the multirun addon to the project. (Disabled by default) --- game/addons/.gitignore | 2 + game/addons/multirun/Multirun.gd | 94 ++++++++++++++++++++++++++++++++ game/addons/multirun/plugin.cfg | 7 +++ game/project.godot | 5 ++ 4 files changed, 108 insertions(+) create mode 100644 game/addons/multirun/Multirun.gd create mode 100644 game/addons/multirun/plugin.cfg diff --git a/game/addons/.gitignore b/game/addons/.gitignore index 230d2f1d..ecdb05b5 100644 --- a/game/addons/.gitignore +++ b/game/addons/.gitignore @@ -11,5 +11,7 @@ !mesh_data_resource_editor/** !bone_editor !bone_editor/** +!multirun +!multirun/** !addon_versions diff --git a/game/addons/multirun/Multirun.gd b/game/addons/multirun/Multirun.gd new file mode 100644 index 00000000..5d41fa01 --- /dev/null +++ b/game/addons/multirun/Multirun.gd @@ -0,0 +1,94 @@ +tool +extends EditorPlugin + +var panel1 +var panel2 +var pids = [] + +func _enter_tree(): + var editor_node = get_tree().get_root().get_child(0) + var gui_base = editor_node.get_gui_base() + var icon_transition = gui_base.get_icon("TransitionSync", "EditorIcons") #ToolConnect + var icon_transition_auto = gui_base.get_icon("TransitionSyncAuto", "EditorIcons") + var icon_load = gui_base.get_icon("Load", "EditorIcons") + + panel2 = _add_tooblar_button("_loaddir_pressed", icon_load, icon_load) + panel1 = _add_tooblar_button("_multirun_pressed", icon_transition, icon_transition_auto) + + _add_setting("debug/multirun/number_of_windows", TYPE_INT, 2) + _add_setting("debug/multirun/window_distance", TYPE_INT, 1270) + _add_setting("debug/multirun/add_custom_args", TYPE_BOOL, true) + _add_setting("debug/multirun/first_window_args", TYPE_STRING, "listen") + _add_setting("debug/multirun/other_window_args", TYPE_STRING, "join") + +func _multirun_pressed(): + var window_count : int = ProjectSettings.get_setting("debug/multirun/number_of_windows") + var window_dist : int = ProjectSettings.get_setting("debug/multirun/window_distance") + var add_custom_args : bool = ProjectSettings.get_setting("debug/multirun/add_custom_args") + var first_args : String = ProjectSettings.get_setting("debug/multirun/first_window_args") + var other_args : String = ProjectSettings.get_setting("debug/multirun/other_window_args") + var commands = ["--position", "50,10"] + if first_args && add_custom_args: + for arg in first_args.split(" "): + commands.push_front(arg) + + var main_run_args = ProjectSettings.get_setting("editor/main_run_args") + if main_run_args != first_args: + ProjectSettings.set_setting("editor/main_run_args", first_args) + var interface = get_editor_interface() + interface.play_main_scene() + if main_run_args != first_args: + ProjectSettings.set_setting("editor/main_run_args", main_run_args) + + kill_pids() + for i in range(window_count-1): + commands = ["--position", str(50 + (i+1) * window_dist) + ",10"] + if other_args && add_custom_args: + for arg in other_args.split(" "): + commands.push_front(arg) + pids.append(OS.execute(OS.get_executable_path(), commands, false)) + +func _loaddir_pressed(): + OS.shell_open(OS.get_user_data_dir()) + +func _exit_tree(): + _remove_panels() + kill_pids() + +func kill_pids(): + for pid in pids: + OS.kill(pid) + pids = [] + +func _remove_panels(): + if panel1: + remove_control_from_container(CONTAINER_TOOLBAR, panel1) + panel1.free() + if panel2: + remove_control_from_container(CONTAINER_TOOLBAR, panel2) + panel2.free() + +func _unhandled_input(event): + if event is InputEventKey: + if event.pressed and event.scancode == KEY_F4: + _multirun_pressed() + +func _add_tooblar_button(action:String, icon_normal, icon_pressed): + var panel = PanelContainer.new() + var b = TextureButton.new(); + b.texture_normal = icon_normal + b.texture_pressed = icon_pressed + b.connect("pressed", self, action) + panel.add_child(b) + add_control_to_container(CONTAINER_TOOLBAR, panel) + return panel + +func _add_setting(name:String, type, value): + if ProjectSettings.has_setting(name): + return + ProjectSettings.set(name, value) + var property_info = { + "name": name, + "type": type + } + ProjectSettings.add_property_info(property_info) diff --git a/game/addons/multirun/plugin.cfg b/game/addons/multirun/plugin.cfg new file mode 100644 index 00000000..5112dfff --- /dev/null +++ b/game/addons/multirun/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Multirun" +description="Multirun allows to start multiple game instances at once." +author="Jaanus Jaggo" +version="1.1.0" +script="Multirun.gd" \ No newline at end of file diff --git a/game/project.godot b/game/project.godot index 1d61442b..70e51d8d 100644 --- a/game/project.godot +++ b/game/project.godot @@ -273,6 +273,11 @@ gdscript/warnings/unused_argument=false gdscript/warnings/unused_signal=false gdscript/warnings/return_value_discarded=false gdscript/warnings/integer_division=false +multirun/number_of_windows=2 +multirun/window_distance=1270 +multirun/add_custom_args=true +multirun/first_window_args="listen" +multirun/other_window_args="join" [display]