/*Copyright (C) 2010 Deveaux Duncan

This file is part of Hikou no mizu.

Hikou no mizu is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Hikou no mizu is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Hikou no mizu.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DEF_ANIMATION_MANAGER
#define DEF_ANIMATION_MANAGER

#include <SFML/Graphics.hpp>
#include <vector>
#include <string>
#include "Animation.hpp"

#include "extlibs/TinyXML/tinyxml.h" //static loadFromXML method

//Class managing a list of animations. It can :
// -Start animations (blocking or not)
// -Edit animations parameters (direction, position...)
class AnimationManager
{
    public:
        AnimationManager();
        void render(sf::RenderWindow &renderWindow);
        
        void addAnimation(const Animation &animation, int animationIx = -1);
        void removeAnimation(int animationIx);
        
        void startAnimation(int animationIx, bool blocking=false, int ixBackAnimation=0);
        void update();
        
        //Get and set methods
        Animation *getCurrentAnimation();
        bool isAnimationBlocking() const;
        
        const sf::Vector2f &getAnimationOrigin() const;
        
        void setDirection(int direction);
        int getDirection() const;
        
        float getWidth() const;
        float getHeight() const;
        
        void setXPosition(float position);
        float getXPosition() const;
        void setYPosition(float position);
        float getYPosition() const;
        
        //Static methods
        static AnimationManager loadFromXML(const std::string &xmlPath, const std::string &animationsPath);
    
    private:
        void setOrigin(const sf::Vector2f &localPosition);
        void setFlipX(bool flipX);
        
        void updateOrigin();
        
        std::vector<Animation> m_animationsList;
        
        int m_ixAnimation;
        int m_ixBackAnimation;
        
        bool m_blockingAnimation;
        bool m_animationLaunched;
        
        int m_direction;
};

#endif