Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic window layouting, per-instance user directories, more convinient custom arguments and editor buttons #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Jaanus Jaggo (Perfoon)
Copyright (c) 2021 Jaanus Jaggo (Perfoon) & Dreadpon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
48 changes: 36 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,52 @@ Multirun allows starting multiple game instances at once.

The main purpose of this feature is to speed up multiplayer game development. One game instance can be configured to host the game and others to join.

![showcase](https://i.postimg.cc/PqwFqP7N/showcase.gif)

Tested on Godot v3.5

## Installation

This plugin is installed the same way as other Godot plugins.

Download the code by clicking green `Code` button and then `Download ZIP`. Unpack it anywhere you like.

Copy the folder `addons/dreadpon.spatial_gardener/` to `res://addons/` in your Godot project and enable it from `Project -> Project Settings -> Plugins`.

**NOTE:** this plugin relies on an autoload singleton `res://addons/multirun/instance_setup.gd` under the name of `MultirunInstanceSetup` to run.
If your windows aren't positioning themselves correctly, check if `MultirunInstanceSetup` is properly loaded.

![autoload-setup](screenshots/autoload-setup.jpg)

## How to use

1. Add the plugin to your project and enable it.
2. Configure the plugin in Project Settings. The settings are located under *Debug → Multirun*.
3. Run the script by clicking the multirun button on the top right corner of Godot editor, or press F4 on keyboard.
Launching game instances can be done via buttons in the top right corner of Godot editor.
- 1 - open `user://` directory
- 2 - run all instances (or *re*launch if already launched)
- 3 - run a specific instance (will honor it's window positioning and custom `user://` directory)
- 4 - stop all running instances

![launch-instances](screenshots/launch-instances.jpg)

Extra: next to the multirun button there is also a new folder button that opens the `"user://"` path when clicked.
This plugin also supports personal subfolders for each instance ran. They are meant to be used instead of a regular `user://` path.

![Screenshot](screenshots/MultirunPreview.png)
![subdirectories](screenshots/subdirectories.jpg)

A personal path can be accessed via singleton `MultirunInstanceSetup.instance_user_dir` or `MultirunInstanceSetup.get_user_path()`. When launched standalone, this path will refer to `user://` as usual and only change when you are, indeed, "multirunning" your game.

## Settings

Under the Project Settings there is a new category *Debug → Multirun* with the following parameters:
* **Window Distance** - distance in pixels between different windows. It offsets the windows so that they don't appear on top of each other.
* **Number of Windows** - the total number of windows it opens.
* **Add Custom Args** - when checked, it will add the user defined command line arguments to the opened game instances.
* **First Window Args** - custom command line arguments that will be applied to the first window. To add multiple arguments, separate them with a space.
* **Other Window Args** - custom command line arguments that will be applied to all other windows. To add multiple arguments, separate them with a space.
You can configure the following settings in the `Project -> Project Settings -> Multirun`:
- `Number Of Windows` to run
- `Distance Between Windows` if you need extra space betwenen them. **NOTE:** there's some space between them by default: Windows OS includes "active zones" (for manually changing window size) when calculating window bounds
- `Individual Instance Args` - console arguments to pass to each instance as dictionary of instace indices as keys and string of arguments as values. **NOTE:** to pass the same args to ALL instances use the key of `-1`
- Key `Shortcuts` for actions defined in paragraph 1

![Screenshot](screenshots/MultirunSettings.png)
![settings](screenshots/settings.jpg)

## Additional Information

Finding problems in the code, open a ticket on [GitHub](https://github.com/perfoon/Multirun/issues).

**NOTE:** it might take some time to merge v.2.0.0 to main, in which case Dreadpon should be tagged for their resolution.

94 changes: 0 additions & 94 deletions addons/multirun/Multirun.gd

This file was deleted.

81 changes: 81 additions & 0 deletions addons/multirun/instance_setup.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
extends Node


#-------------------------------------------------------------------------------
# A per-instance setup for multirun instances
# Transforms instance windows according to passed cmdline arguments
# And exposes an instance-specific 'user://' subfolder
# And can be used to manually write things like settings and save files
#-------------------------------------------------------------------------------


# When running multiple game instances you might want to have separate 'user://' folders for each
# So you can store settings and data unique to these instances
# When launched with an argument '--user_subfolder=path' 'path' will be appended to the current 'user://' dir
# Otherwise will refer to 'user://' dir
# Settings that are to be separate for each instance should use THIS path instead of 'user://'
var instance_user_dir: String = ''




func _ready():
setup_instance(parse_cmdline_args())


# Parse cmdline arguments into a Dictionaey
# Stripping all special symbols
func parse_cmdline_args() -> Dictionary:
var arguments = {}
for argument in OS.get_cmdline_args():
if argument.find("=") > -1:
var key_value = argument.split("=")
arguments[key_value[0].lstrip("--")] = key_value[1]
else:
# Options without an argument might be present in the dictionary,
# With the value set to an empty string.
arguments[argument.lstrip("--")] = ""
return arguments


# Set this instance up according to passed arguments
# Mostly related to window transform
func setup_instance(arguments: Dictionary):
instance_user_dir = 'user://'
var decorations_size = OS.get_real_window_size() - OS.window_size

for arg_name in arguments:
var arg_val = arguments[arg_name]
match arg_name:

'window_pos_x':
OS.window_position = Vector2(int(arg_val), OS.window_position.y)

'window_pos_y':
OS.window_position = Vector2(OS.window_position.x, int(arg_val))

'window_size_x':
OS.window_size = Vector2(int(arg_val), OS.window_size.y)

'window_size_y':
OS.window_size = Vector2(OS.window_size.x, int(arg_val))

'window_title':
OS.set_window_title(arguments.window_title)

'user_subfolder':
instance_user_dir += arg_val
instance_user_dir.replace('\\', '/')
if !instance_user_dir.ends_with('/'):
instance_user_dir += '/'
Directory.new().make_dir_recursive(instance_user_dir)

OS.window_size -= decorations_size


# Get full path to dir/file with the instance dir path
# If we were to replicate 'user://dir/file.cfg'
# We would pass just 'dir/file.cfg'
# And receive 'user://instance_user_dir/dir/file.cfg'
func get_user_path(relative_path: String) -> String:
return instance_user_dir + relative_path
8 changes: 4 additions & 4 deletions addons/multirun/plugin.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +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"
description="Plugin to run multiple game instances at once, layed out in a neat grid."
author="Jaanus Jaggo & Dreadpon"
version="2.0.0"
script="plugin.gd"
Loading