using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;


namespace ActionGame.GameResources.Models
{
    public class CharacterSet
    {
        public static readonly Int32 DRAW_WIDTH = 32;
        public static readonly Int32 DRAW_HEIGHT = 48;
        public enum Frame { Up, Up_1, Up_2, Up_3, Down, Down_1, Down_2, Down_3, Left, Left_1, Left_2, Left_3, Right, Right_1, Right_2, Right_3 };
        public Int32 Key { get; set; }
        public Dictionary<Frame, Texture2D> FrameTextures { get; private set; }

        public Frame CurrentFrame { get; set; }


        public CharacterSet()
        {
            this.CurrentFrame = Frame.Down;
            this.FrameTextures = new Dictionary<Frame, Texture2D>();
        }


        public Texture2D CurrentTexture
        {
            get
            {
                return this.FrameTextures[CurrentFrame];
            }
        }


        public CharacterSet Copy()
        {
            CharacterSet copy = new CharacterSet
            {
                Key = this.Key,
                FrameTextures = this.FrameTextures
            };

            return copy;
        }


        public void SetDirection(Vector2 direction)
        {

            if(direction.X == 1)
            {
                CurrentFrame = Frame.Right;
            }
            else if(direction.X == -1)
            {
                CurrentFrame = Frame.Left;
            }
            if (direction.Y == 1)
            {
                CurrentFrame = Frame.Down;
            }
            else if (direction.Y == -1)
            {
                CurrentFrame = Frame.Up;
            }

        }


        public Vector2 GetDirection()
        {
            float x = 0;
            float y = 0;

            if ((CurrentFrame == Frame.Up) || (CurrentFrame == Frame.Up_1) || (CurrentFrame == Frame.Up_2) || (CurrentFrame == Frame.Up_3))
            {
                x = 0;
                y = -1;
            }
            else if ((CurrentFrame == Frame.Down) || (CurrentFrame == Frame.Down_1) || (CurrentFrame == Frame.Down_2) || (CurrentFrame == Frame.Down_3))
            {
                x = 0;
                y = 1;
            }
            else if ((CurrentFrame == Frame.Left) || (CurrentFrame == Frame.Left_1) || (CurrentFrame == Frame.Left_2) || (CurrentFrame == Frame.Left_3))
            {
                x = -1;
                y = 0;
            }
            else if ((CurrentFrame == Frame.Right) || (CurrentFrame == Frame.Right_1) || (CurrentFrame == Frame.Right_2) || (CurrentFrame == Frame.Right_3))
            {
                x = 1;
                y = 0;
            }

            return new Vector2(x, y);
        }



    }
}
