using System;
using System.Collections.Generic;
using System.Text;


namespace ActionGame.GameResources.Models
{
    public class TileSetDefinition
    {
        public Int32 Key { get; set; }
        public Int32 TextureKey { get; set; }
        public Int32 X { get; set; }
        public Int32 Y { get; set; }
        public Int32 Width { get; set; }
        public Int32 Height { get; set; }
        public Boolean Passable { get; set; }
        public IList<Int32> AnimationSequence { get; set; }


        public static String GetCsvTitle()
        {
            return "Key,TextureKey,X,Y,Width,Height,Passable,AnimationSequence";
        }


        public String ToCsvString()
        {
            StringBuilder line = new StringBuilder();

            line.Append(Key);
            line.Append(',');
            line.Append(TextureKey);
            line.Append(',');
            line.Append(X);
            line.Append(',');
            line.Append(Y);
            line.Append(',');
            line.Append(Width);
            line.Append(',');
            line.Append(Height);
            line.Append(',');
            line.Append(Passable.ToString());
            line.Append(',');
            line.Append(ConvertAnimationSequenceToText());

            return line.ToString();
        }


        public void SetAnimationSequence(Int32 t1, Int32 t2, Int32 t3, Int32 t4, Int32 t5)
        {
            AnimationSequence.Clear();

            AnimationSequence.Add(t1);
            AnimationSequence.Add(t2);
            AnimationSequence.Add(t3);
            AnimationSequence.Add(t4);
            AnimationSequence.Add(t5);
        }


        private String ConvertAnimationSequenceToText()
        {
            StringBuilder result = new StringBuilder("");

            while (AnimationSequence.Contains(-1)) AnimationSequence.Remove(-1);

            if ((AnimationSequence.Count == 0) || (AnimationSequence.Count == 1)) return "";
            
            for(Int32 i = 0; i < AnimationSequence.Count; i++)
            {
                result.Append(AnimationSequence[i].ToString());
                
                if(i != (AnimationSequence.Count -1)) result.Append("|");
            }

            return result.ToString();
        }


    }
}
