└── addons └── multirun ├── Multirun.gd └── plugin.cfg /addons/multirun/Multirun.gd: -------------------------------------------------------------------------------- 1 | tool 2 | extends EditorPlugin 3 | 4 | var panel1 5 | var panel2 6 | var pids = [] 7 | 8 | func _enter_tree(): 9 | var editor_node = get_tree().get_root().get_child(0) 10 | var gui_base = editor_node.get_gui_base() 11 | var icon_transition = gui_base.get_icon("TransitionSync", "EditorIcons") #ToolConnect 12 | var icon_transition_auto = gui_base.get_icon("TransitionSyncAuto", "EditorIcons") 13 | var icon_load = gui_base.get_icon("Load", "EditorIcons") 14 | 15 | panel2 = _add_tooblar_button("_loaddir_pressed", icon_load, icon_load) 16 | panel1 = _add_tooblar_button("_multirun_pressed", icon_transition, icon_transition_auto) 17 | 18 | _add_setting("debug/multirun/number_of_windows", TYPE_INT, 2) 19 | _add_setting("debug/multirun/window_distance", TYPE_INT, 1270) 20 | _add_setting("debug/multirun/add_custom_args", TYPE_BOOL, true) 21 | _add_setting("debug/multirun/first_window_args", TYPE_STRING, "listen") 22 | _add_setting("debug/multirun/other_window_args", TYPE_STRING, "join") 23 | 24 | func _multirun_pressed(): 25 | var window_count : int = ProjectSettings.get_setting("debug/multirun/number_of_windows") 26 | var window_dist : int = ProjectSettings.get_setting("debug/multirun/window_distance") 27 | var add_custom_args : bool = ProjectSettings.get_setting("debug/multirun/add_custom_args") 28 | var first_args : String = ProjectSettings.get_setting("debug/multirun/first_window_args") 29 | var other_args : String = ProjectSettings.get_setting("debug/multirun/other_window_args") 30 | var commands = ["--position", "50,10"] 31 | if first_args && add_custom_args: 32 | for arg in first_args.split(" "): 33 | commands.push_front(arg) 34 | 35 | var main_run_args = ProjectSettings.get_setting("editor/main_run_args") 36 | if main_run_args != first_args: 37 | ProjectSettings.set_setting("editor/main_run_args", first_args) 38 | var interface = get_editor_interface() 39 | interface.play_main_scene() 40 | if main_run_args != first_args: 41 | ProjectSettings.set_setting("editor/main_run_args", main_run_args) 42 | 43 | kill_pids() 44 | for i in range(window_count-1): 45 | commands = ["--position", str(50 + (i+1) * window_dist) + ",10"] 46 | if other_args && add_custom_args: 47 | for arg in other_args.split(" "): 48 | commands.push_front(arg) 49 | pids.append(OS.execute(OS.get_executable_path(), commands, false)) 50 | 51 | func _loaddir_pressed(): 52 | OS.shell_open(OS.get_user_data_dir()) 53 | 54 | func _exit_tree(): 55 | _remove_panels() 56 | kill_pids() 57 | 58 | func kill_pids(): 59 | for pid in pids: 60 | OS.kill(pid) 61 | pids = [] 62 | 63 | func _remove_panels(): 64 | if panel1: 65 | remove_control_from_container(CONTAINER_TOOLBAR, panel1) 66 | panel1.free() 67 | if panel2: 68 | remove_control_from_container(CONTAINER_TOOLBAR, panel2) 69 | panel2.free() 70 | 71 | func _unhandled_input(event): 72 | if event is InputEventKey: 73 | if event.pressed and event.scancode == KEY_F4: 74 | _multirun_pressed() 75 | 76 | func _add_tooblar_button(action:String, icon_normal, icon_pressed): 77 | var panel = PanelContainer.new() 78 | var b = TextureButton.new(); 79 | b.texture_normal = icon_normal 80 | b.texture_pressed = icon_pressed 81 | b.connect("pressed", self, action) 82 | panel.add_child(b) 83 | add_control_to_container(CONTAINER_TOOLBAR, panel) 84 | return panel 85 | 86 | func _add_setting(name:String, type, value): 87 | if ProjectSettings.has_setting(name): 88 | return 89 | ProjectSettings.set(name, value) 90 | var property_info = { 91 | "name": name, 92 | "type": type 93 | } 94 | ProjectSettings.add_property_info(property_info) 95 | -------------------------------------------------------------------------------- /addons/multirun/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="Multirun" 4 | description="Multirun allows to start multiple game instances at once." 5 | author="Jaanus Jaggo" 6 | version="1.1.0" 7 | script="Multirun.gd" --------------------------------------------------------------------------------