using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

[RequireComponent(typeof(ShapeOnRing))]
[RequireComponent(typeof(ElementalSphere))]
public class AttachableShape : MonoBehaviour
{
    protected bool beingDragged = false;
    protected RingManager ring;
    protected ShapeOnRing shapeOnRing;
    protected ElementalSphere elemental;
    public float scaleFactor = 1f;

    protected void Awake()
    {
        shapeOnRing = gameObject.GetComponent<ShapeOnRing>();
        elemental = gameObject.GetComponent<ElementalSphere>();
    }

    protected void OnMouseDown()
    {
        beingDragged = true;
        transform.parent = null;
    }

    protected void OnTriggerEnter(Collider col)
    {
        if(col.CompareTag("Ring"))
        {
            ring = col.gameObject.GetComponent<RingManager>();
        }
    }

    protected void OnTriggerExit(Collider col)
    {
        if (col.CompareTag("Ring"))
        {
            ring = null;
        }
    }

    protected void OnMouseUp()
    {
        if(beingDragged && ring!=null)
        {
            Direction dir = ring.AttachObjectToNearestRing(transform);
            shapeOnRing.direction = dir;
            elemental.scaleFactor = scaleFactor;
        }
    }
}
