
using System.Collections.Generic;
using System;
public class Animation
{
    private string name;
    private int frameRate;
    private bool loop;
    private Frames left;
    private Frames right;
    private bool isOver;

    protected class Frames
    {
        private List<int> frames;
        public int offsetX;
        public int offsetY;

        public Frames()
        {
            frames = new List<int>();
        }

        public int getLength()
        {
            return frames.Count;
        }

        public int getFrame(int i)
        {
            return frames[i];
        }

        public void addFrame(int i)
        {
            frames.Add(i);
        }

        public int getOffsetX()
        {
            return this.offsetX;
        }

        public int getOffsetY()
        {
            return this.offsetY;
        }
    }

    public string getAnimName()
    {
        return this.name;
    }

    public int getLength(bool direction)
    {
        if (!direction)	// left
            return this.left.getLength();
        else		// right
            return this.right.getLength();
    }

    public int getFrame(bool direction, int i)
    {
        if (!direction)	// left
            return this.left.getFrame(i);
        else		// right
            return this.right.getFrame(i);
    }

    public int getFrameRate()
    {
        return this.frameRate;
    }

    public int getOffsetX(bool direction)
    {
        if (!direction)	// left
            return this.left.getOffsetX();
        else		// right
            return this.right.getOffsetX();
    }

    public int getOffsetY(bool direction)
    {
        if (!direction)	// left
            return this.left.getOffsetY();
        else		// right
            return this.right.getOffsetY();
    }

    public bool isLooping()
    {
        return loop;
    }

    public bool IsOver
    {
        get { return isOver; }
        set { isOver = value; }
    }

    public Animation(FileIO fp, string name)
    {
        string line;
        string[] words;
        int token;

        //if(fp != null) System.out.printf("fp is not null. It is: %s\n", fp.getNext());
        // name, speed, loop
        this.name = name;
        this.frameRate = int.Parse(fp.getNext());
        this.loop = (int.Parse(fp.getNext()) != 0);

        left = new Frames();
        right = new Frames();

        fp.getNext();
        // left offsets
        this.left.offsetX = int.Parse(fp.getNext());
        this.left.offsetY = int.Parse(fp.getNext());
        // left frames
        {
            line = fp.getLine();
            words = line.Split(new char[] { ' ', '\t' });
            token = 0; // skip the first word

            while (token < words.Length - 1)
            {
                token++;
                this.left.addFrame(int.Parse(words[token]));
            }
        }
        fp.getNext();
        // right offsets
        this.right.offsetX = int.Parse(fp.getNext());
        this.right.offsetY = int.Parse(fp.getNext());
        // right frames
        {
            line = fp.getLine();
            words = line.Split(new char[] { ' ', '\t' });
            token = 0; // skip the first word

            while (token < words.Length - 1)
            {
                token++;
                this.right.addFrame(int.Parse(words[token]));
            }
        }

        Console.WriteLine("Name: {0}\nFramerate: {1}\nLEFT", this.name, this.frameRate);
        Console.WriteLine("Offx: {0}\nOffy: {1}\nLen: {2}\nRIGHT", this.left.offsetX, this.left.offsetY, this.left.getLength());
        Console.WriteLine("Offx: {0}\nOffy: {1}\nLen: {2}", this.right.offsetX, this.right.offsetY, this.right.getLength());
        Console.WriteLine("===");
    }

    public string getName()
    {
        return name;
    }
}
