using ActionGame.GameResources.Repository;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;


namespace ActionGame.GameResources.Models
{
    public class TileSet
    {
        public static readonly Int32 DRAW_WIDTH = 32;
        public static readonly Int32 DRAW_HEIGHT = 32;

        public Int32 Key { get; set; }
        public Texture2D Texture { get; set; }
        public Boolean Passable { get; set; }
        public IList<Int32> AnimationSequence { get; set; }

        private IGameContentRepository<TileSet> tileSetRepository;
        private Int32 activeFrame;


        public TileSet(IGameContentRepository<TileSet> tileSetRepository)
        {
            this.activeFrame = 0;
            this.tileSetRepository = tileSetRepository;
        }


        public Texture2D GetActiveTexture()
        {
            if(AnimationSequence.Count == 0)
            {
                return this.Texture;
            }
            else
            {
                return tileSetRepository.GetContent(this.AnimationSequence[activeFrame]).Texture;
            }
        }


        public void Update()
        {
            if (AnimationSequence.Count == 0) return;
            
            activeFrame++;
            if (activeFrame >= AnimationSequence.Count) activeFrame = 0;
        }

    }
}
