using OnlineMaps;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(OnlineMapsCategories.MARKERS)]
    [Tooltip("Gets marker rotation.")]
    public class Get2DMarkerRotation : FsmStateAction
    {
        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Instance of 2D marker.")]
        public FsmObject marker;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        [Tooltip("Rotation of marker.")]
        public FsmFloat storeRotation;

        public override void Reset()
        {
            marker = null;
            storeRotation = null;
        }

        public override void OnEnter()
        {
            DoEnter();
            Finish();
        }

        private void DoEnter()
        {
            if (!Map.instance)
            {
                Debug.LogError("Online Maps not found.");
                return;
            }

            if (marker.IsNone) return;

            if (marker.Value.GetType() != typeof(MarkerWrapper))
            {
                Debug.Log("Its not MarkerWrapper instance");
                return;
            }

            Marker2D m = (marker.Value as MarkerWrapper).marker as Marker2D;
            storeRotation.Value = m.rotation;
        }
    }
}