Skip to content

Commit

Permalink
added multirun plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Cod3lta committed Nov 5, 2023
1 parent ee34f8f commit 5e9e7d8
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
94 changes: 94 additions & 0 deletions addons/multirun/Multirun.gd
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions addons/multirun/plugin.cfg
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 12 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,25 @@ Gamestate="*res://src/scripts/gamestate.gd"
ConnectionManager="*res://src/scripts/client/connectionManager.gd"
CandyPlacer="*res://src/scripts/server/trails/candyPlacer.gd"

[debug]

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]

window/size/width=1280
window/size/height=720
window/stretch/mode="2d"
window/stretch/aspect="expand"

[editor_plugins]

enabled=PoolStringArray( "res://addons/multirun/plugin.cfg" )

[global]

mask=false
Expand Down

0 comments on commit 5e9e7d8

Please sign in to comment.