using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Animator))]
public class Switch : TileAsset
{
	private static readonly int StartTrigger = Animator.StringToHash("Start");
	private static readonly int StopTrigger = Animator.StringToHash("Stop");

	public List<StateTileAsset> toActivate;

	private Animator animator;
	private bool isOpen;

	private void Start()
	{
		animator = GetComponent<Animator>();
	}

	public override bool CanEnter(Vector2Int comingFrom, Vector2Int goingInto, Orientation orientation)
	{
		return true;
	}

	public override void OnEnter(GameObject player)
	{
		animator.SetTrigger(isOpen ? StopTrigger : StartTrigger);
		AudioController.Play("Switch");
		isOpen = !isOpen;
		foreach (var tileAsset in toActivate)
		{
			tileAsset.SwitchState();
		}
	}

	public override void OnLeave(GameObject player)
	{
	}
}