using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PortraitPanel : MonoBehaviour
{
	[SerializeField] private Sprite[] portraitsOn;
	[SerializeField] private Sprite[] portraitsOff;
	[SerializeField] private Image[] portraitsPlace;


	public void Init ()
	{
		GameStart.Instance.OnPlayerKill += OnPlayerKill;
		GameStart.Instance.OnRestart += Reset;

		Reset(GameManager.Instance.ControllerCount);
	}
	void OnDisable ()
	{
		GameStart.Instance.OnPlayerKill -= OnPlayerKill;
		GameStart.Instance.OnRestart -= Reset;
	}

	private void Reset(int count)
	{
		for (int i = 0; i < 4; i++)
		{
			if (i < count)
			{
				portraitsPlace[i].sprite = portraitsOn[i];
			}
			else
			{
				portraitsPlace[i].sprite = portraitsOff[i];
			}
		}
	}

	private void OnPlayerKill(int id)
	{
		portraitsPlace[id].sprite = portraitsOff[id];
	}
}
