#pragma once

#include "vector2d.h"
#include "halleystring.h"

namespace Halley {
	namespace Animation {
		struct Frame {
			Frame(int id, Vector2f p) : texId(id), pivot(p) {}

			int texId;
			Vector2f pivot;
		};

		struct MultiFrame {
			float length;
			std::vector<Frame> frames;
		};

		typedef std::vector<MultiFrame> Sequence;
		typedef std::map<String, Sequence> Group;

		class Player {
		public:
			Player(String group);

			void step(float t);
			int getTextureId() const;
			Vector2f getPivot() const;

			void setGroup(String name);
			void setSequence(String name);
			void setDirection(int dir);

			int getFrame() const { return frameN; }
			int getDirection() const { return direction; }
			String getSequence() const { return sequenceName; }
			String getGroup() const { return groupName; }

		private:
			float time;
			int frameN;
			int direction;
			String sequenceName;
			String groupName;

			shared_ptr<Group> group;
			Sequence* sequence;
			Frame* frame;
		};


		shared_ptr<Group> parse(StringArray data);
		shared_ptr<Group> parseFile(String name);
	}
}
