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

// Delegate function prototype for when the collider is colliding with the patch
public delegate void OnPatchEvent(Vector2 patchCenter, int patchId);

// Delegate function prototype for when the collider exit the patch
public delegate void OnPatchExitEvent();

public delegate void OnPatchTrigger(GameObject obj);

[RequireComponent(typeof(BoxCollider2D))]
public class PatchBehaviour : MonoBehaviour
{
    // The event handler for the on patch function
    public static event OnPatchEvent onPatchHandler;

    // The event handler for the on patch exit function
    public static event OnPatchExitEvent onPatchExitHandler;

    public static event OnPatchTrigger onPatchTriggered;
    
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (onPatchHandler != null)
        {
            onPatchHandler(new Vector2(transform.position.x, transform.position.y), GetInstanceID());
        }

        if (onPatchTriggered != null)
        {
            
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (onPatchExitHandler != null)
        {
            onPatchExitHandler();
        }
    }

    public static void Cleanup()
    {
        onPatchHandler = null;
        onPatchExitHandler = null;

    }
}
