extends Node

var players: Array[int] = []

var player_spawner: MultiplayerSpawner

@onready var debug_ui: PackedScene = preload("res://ui/multiplayer-debug-ui/multiplayer-debug-ui.tscn")
var debug_ui_instance


func _ready() -> void:
	player_spawner = get_tree().root.get_node("Lobby/PlayerSpawner") as MultiplayerSpawner
	
	debug_ui_instance = debug_ui.instantiate()
	get_tree().root.add_child.call_deferred(debug_ui_instance)
	debug_ui_instance.hide()


func _input(event: InputEvent) -> void:
	if event.is_action_pressed("toggle_watch"):
		debug_ui_instance.visible = !debug_ui_instance.visible


@rpc("any_peer", "call_local", "reliable")
func request_server_to_spawn_player(peer_id: int, player_name: String) -> void:
	var data: Dictionary = {}
	
	data["peer_id"] = peer_id
	data["player_name"] = player_name
	
	player_spawner.spawn(data)
