using Sirenix.OdinInspector;
using UnityEngine;

namespace mGame
{
    [CreateAssetMenu(fileName = "ShareMap",menuName = "Level/ShareMap")]
    public class MapSO : SerializedScriptableObject
    {
        #region ×é¼þ
        [FoldoutGroup("Block Prefabs")] public GameObject grass;
        [FoldoutGroup("Block Prefabs")] public GameObject sand;
        [FoldoutGroup("Block Prefabs")] public GameObject mountain;
        [FoldoutGroup("Block Prefabs")] public GameObject water;
        [FoldoutGroup("Block Prefabs")] public GameObject dirt;
        [FoldoutGroup("Block Prefabs")] public GameObject tree;
        [FoldoutGroup("Block Prefabs")] public GameObject dryTown;
        [FoldoutGroup("Block Prefabs")] public GameObject greenTown;


        public GameObject GetBlockPrefab(Block block)
        {
            return block switch
            {
                Block.Grass => grass,
                Block.Desert => sand,
                Block.Mountain => mountain,
                Block.Water=>water,
                Block.Dirt =>dirt,
                Block.Tree => tree,
                Block.DryTown => dryTown,
                Block.GreenTown => greenTown,
                _=>null
            };
        }
        #endregion
        public Vector2Int mapSize;
        public Block[,] mapData;

        public Block GetBlock(Vector3 pos)
        {
            return GetBlock(new Vector2(pos.x, -pos.z));
        }
        public Block GetBlock(Vector2 pos)
        {
            Vector2Int idx = new(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y));
            //Debug.Log(idx);
            idx.x = Mathf.Clamp(idx.x, 0, mapSize.x - 1);
            idx.y = Mathf.Clamp(idx.y, 0, mapSize.y - 1);
            return mapData[idx.x, idx.y];
        }
    }
}
