using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class PlayerList : MonoBehaviour {
	HashSet<int> playerIds = new();
	TMP_Text text;

	void Awake() {
		text = GetComponent<TMP_Text>();
		text.text = "";
	}

	public void SetPlayerList(IEnumerable<int> ids) {
		playerIds.Clear();
		foreach (int id in ids)
			playerIds.Add(id);
	}

	public void Connected(int id) {
		playerIds.Add(id);
		UpdateList();
	}

	public void Disconnected(int id) {
		playerIds.Remove(id);
		UpdateList();
	}

	void UpdateList() {
		text.text = "";
		foreach (int playerId in playerIds)
			text.text += $"Player #{playerId}\n";
	}
}