/**
 *  Triangles
 *  Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
 *
 *  This program 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, version 3 of the License.
 *
 *  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <vector>
#include <SFML/Graphics.hpp>
#include "Utility.hpp"

/**
 * @class Foreground
 * @author POSITIVE MENTAL ATTITUDE
 * @date 06/09/16
 * @file Foreground.hpp
 * @brief The destructible foreground.
 */
class Foreground: public sf::Drawable
{
	public:
		Foreground();
		~Foreground();
		void create(sf::Image& foreground, sf::Image& normal, sf::Image& map);
		void create(std::string foreground, std::string normal, std::string map);
		void setResolution(sf::Vector2u resolution);
		void setPosition(sf::Vector2f position);
		void reloadFromTile(int x, int y, bool neighbouring = false);
		void reloadFromPixel(int x, int y, bool neighbouring = false);
		bool destroy(unsigned x, unsigned y);
		const sf::Vector2u getSize() const;
		const unsigned getTileSize() const;
		unsigned const tileAlpha(unsigned x, unsigned y, unsigned pixelX, unsigned pixelY);
		void renderNormals(bool render);
		void move(sf::Vector2f movement);
		void rotate(float rotation);
		const Rect getBounds() const;
		const sf::Vector2f getWormholePosition() const;
		const bool getStarPosition(sf::Vector2f& starPosition);

	private:
		void draw(sf::RenderTarget& target, sf::RenderStates states) const;
		std::vector<std::pair<sf::Image, sf::Texture>> _tiles;
		std::vector<std::vector<sf::Sprite>> _sprites;
		std::vector<std::pair<sf::Image, sf::Texture>> _normalTiles;
		std::vector<std::vector<sf::Sprite>> _normalSprites;
		sf::Vector2u _renderCount;
		sf::Vector2u _tileCount;
		unsigned _tileSize;
		sf::Vector2u _position;
		bool _renderNormals;
		
		sf::Vector2u _wormholePosition;
		std::vector<sf::Vector2u> _starPosition;
};

