using OnlineMaps;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(OnlineMapsCategories.GENERAL)]
    [Tooltip("Gets coordinates of the center point of the map and zoom.")]
    public class GetMapCoordinatesAndZoom : FsmStateAction
    {
        [UIHint(UIHint.Variable)]
        [Tooltip("Coordinates of center point of map.")]
        public FsmVector2 storeCoordinates;

        [Tooltip("Map zoom.")]
        [UIHint(UIHint.Variable)]
        public FsmInt storeZoom;

        [Tooltip("Map float zoom.")]
        [UIHint(UIHint.Variable)]
        public FsmFloat storeFloatZoom;

        public override void Reset()
        {
            storeCoordinates = null;
            storeZoom = null;
            storeFloatZoom = null;
        }

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

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

            if (!storeCoordinates.IsNone) storeCoordinates.Value = Map.instance.location;
            if (!storeZoom.IsNone) storeZoom.Value = Map.instance.view.intZoom;
            if (!storeFloatZoom.IsNone) storeFloatZoom.Value = Map.instance.view.zoom;
        }
    }
}