Skip to content

Instantly share code, notes, and snippets.

@mrcdk
Created August 16, 2023 13:28
Show Gist options
  • Save mrcdk/3c22d91a3b4fb784d5df60667a33cf1e to your computer and use it in GitHub Desktop.
Save mrcdk/3c22d91a3b4fb784d5df60667a33cf1e to your computer and use it in GitHub Desktop.
Godot 4.x example of how to launch multiple instances and tile them by using an editor debugger plugin to communicate with each instance
# res://globals.gd added as an autoload
extends Node
func _ready() -> void:
EngineDebugger.register_message_capture("tile-instances", _on_tile_instances)
EngineDebugger.send_message.call_deferred("tile-instances:get_id", [])
func _on_tile_instances(message:String, data:Array) -> bool:
match message:
"session_id":
var info:Dictionary = data[0]
var id = info.get("id", -1)
var all = info.get("all", [])
print(info)
if all.size() > 1:
for i in all.size():
var other = all[i]
if other == id:
tile_window(i, all.size())
return true
return false
func tile_window(i:int, total:int) -> void:
var window = get_window()
var screen = window.current_screen
var screen_rect = DisplayServer.screen_get_usable_rect(screen)
var window_rect = window.get_visible_rect()
printt(window_rect, screen_rect)
match total:
2:
window.position.x = (screen_rect.size.x / 2 - window_rect.size.x / 2)
window.position.y = (screen_rect.size.y / 2 - window_rect.size.y / 2)
if i == 0:
window.position.x -= window_rect.size.x / 2 + 16
else:
window.position.x += window_rect.size.x / 2 + 16
3:
pass
4:
pass
# res://addons/tile-instances/plugin.cfg
[plugin]
name="tile-instances"
description=""
author="mrcdk"
version="1.0"
script="plugin.gd"
# res://addons/tile-instances/plugin.gd
@tool
extends EditorPlugin
var tile_instances = preload("res://addons/tile-instances/tile_instances.gd").new()
func _enter_tree():
add_debugger_plugin(tile_instances)
func _exit_tree():
remove_debugger_plugin(tile_instances)
# res://addons/tile-instances/tile_instances.gd
@tool
extends EditorDebuggerPlugin
const PREFIX = 'tile-instances'
func _has_capture(prefix:String) -> bool:
return prefix == PREFIX
func _capture(message:String, data:Array, session_id:int) -> bool:
match message:
"%s:get_id" % PREFIX:
var all = []
var sessions = get_sessions()
for i in sessions.size():
var session = sessions[i]
if session.is_active():
all.push_back(i)
get_session(session_id).send_message("%s:session_id" % PREFIX, [{"id": session_id, "all": all}])
return true
return false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment