using System;
using XGame.Framework.Quality;
using XGame.Framework.Time;

namespace XGame.Framework.Map
{
    public class MapContext : IDisposable
    {
        public IQualityModule Quality { get; private set; }
        public ITimeModule Time { get; private set; }

        public IMapModule Map { get; private set; }

        /// <summary>
        /// 资源加载模块，需要时才创建
        /// </summary>
        private IMapAssetModule _assetModule;
        public IMapAssetModule Asset => _assetModule ?? (_assetModule = new MapAssetModule(this));

        public MapContext(IQualityModule quality, ITimeModule time, IMapModule map)
        {
            Quality = quality;
            Time = time;
            Map = map;
        }

        public MapContext Clone()
        {
            return new MapContext(Quality, Time, Map);
        }

        void IDisposable.Dispose()
        {
            Quality = null;
            Time = null;
            Map = null;
            (_assetModule as IDisposable)?.Dispose();
            _assetModule = null;
        }
    }

    public interface IMapContextSetter
    {
        MapContext Context { set; }
    }
}