extends MultiplayerSpawner

@onready var player_scene: PackedScene = load("res://player/Player.tscn")


func _ready() -> void:
	spawn_function = spawn_player


func spawn_player(data: Dictionary) -> Player:
	var new_player = player_scene.instantiate() as Player
	
	var peer_id = str(data["peer_id"])
	var player_name = str(data["player_name"])
	
	new_player.set_multiplayer_authority(int(peer_id), true)
	new_player.set_player_name(peer_id, player_name)
	new_player.position = Vector3.UP
	
	GameManager.players.append(int(peer_id))
	
	return new_player
	
	
	#var steam_id_of_player = peer_to_steam_id_map.get(peer_id)
	#if steam_id_of_player == null:
		#print("!!! [%s] CRITICAL: Cannot spawn player for Peer %s, not in map." % [multiplayer.get_unique_id(), peer_id])
		#return
		#
	#if players.has(peer_id): return
#
	#var player_name = Steam.getFriendPersonaName(steam_id_of_player)
	#print("-> [%s] Spawning character for Peer %s (Name: %s)." % [multiplayer.get_unique_id(), peer_id, player_name])
	#
	#var new_player = player_scene.instantiate() as Player
	#new_player.name = str(peer_id)
	#
	#players[peer_id] = new_player
	#add_child(new_player)
	#new_player.position = Vector3.UP
	#new_player.set_player_name(player_name)
	#new_player.set_multiplayer_authority(peer_id, true)
	#new_player.setup_player()
