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

namespace GatherAndDefend.LevelEditor
{
    public class Level : ScriptableObject, IEnumerable<TilemapData>
    {
        private Rect _bounds;
        public Rect Bounds => _bounds;
        [SerializeField]
        private List<TilemapData> _data = new List<TilemapData>();
        public void SaveFromTilemap(Tilemap tilemap)
        {
            var data = new TilemapData();
            data.SaveFromTilemap(tilemap);
            _data.Add(data);
        }
        public void LoadToTilemap(Tilemap tilemap)
        {
            var data = _data.Find(x => x.Key == tilemap.name);
            if (data == null) return;

            data.LoadToTilemap(tilemap);
        }

        public IEnumerator<TilemapData> GetEnumerator()
        {
            return _data.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _data.GetEnumerator();
        }
    }
}