namespace Marro.PacManUdon
{
    using UdonSharp;
    using UnityEngine;
    using VRC.SDKBase;
    using VRC.Udon;

    enum Direction
    {
        Any,
        Up,
        Left,
        Down,
        Right
    }
    public class Teleporter : UdonSharpBehaviour
    {
        [SerializeField] private Direction direction = Direction.Any;
        [SerializeField] private Transform target;

        void OnTriggerEnter(Collider other)
        {
            GridMover gridMover = other.gameObject.GetComponent<GridMover>();

            if (gridMover == null)
            {
                return;
            }

            switch (direction)
            {
                case Direction.Up:
                    if (gridMover.GetDirection().y < 0)
                    {
                        return;
                    }
                    break;
                case Direction.Down:
                    if (gridMover.GetDirection().y > 0)
                    {
                        return;
                    }
                    break;
                case Direction.Left:
                    if (gridMover.GetDirection().x > 0)
                    {
                        return;
                    }
                    break;
                case Direction.Right:
                    if (gridMover.GetDirection().x < 0)
                    {
                        return;
                    }
                    break;
                default:
                    break;
            }

            gridMover.SetPosition(gridMover.GetPosition() + (Vector2)(target.localPosition - transform.localPosition));
        }
    }
}