extends Node3D

@export var PlayerScene : PackedScene

# Called when the node enters the scene tree for the first time.
func _ready():
	var me = multiplayer.get_unique_id()
	var spawn_points = get_tree().get_nodes_in_group("PlayerSpawnPoint")
	var sp_len = len(spawn_points)
	var p_len = len(GameManager.players)
	if !(sp_len > 0):
		print("Warning: sp_len =", sp_len)
		#assert(false)
	if sp_len < p_len:
		print("Warning: More players (", p_len, ") than spawn points")
	print("Players:")
	for p in GameManager.players:
		print("   ", p)
		#var player_scn = PlayerScene.instantiate()
		
	var index = 0
	for i in GameManager.players:
		var currentPlayer = PlayerScene.instantiate()
		currentPlayer.name = str(GameManager.players[i].id)
		add_child(currentPlayer)
		print(me, " Spawning:")
		#TODO fix this dumb shit
		for spawn in get_tree().get_nodes_in_group("PlayerSpawnPoint"):
			if spawn.name == str(index):
				print("    ", spawn)
				currentPlayer.global_position = spawn.global_position
				break
		index += 1
