#pragma once
#include "sre/Sprite.hpp"
#include "sre/SpriteBatch.hpp"
#include "Component.hpp"
#include "Event.hpp"
// Component to render a sprite at the location / rotation / scale of the
// GameObject.
class SpriteRenderer : public Component {
public:
	SpriteRenderer(GameObject*);
	// Change the sprite which gets rendered.
	void SetSprite(const sre::Sprite&);
	// Provides selective 'friend' access for LevelBuilder
	// (Attorney-Client idiom)
	class Mutator final {
	private:
		inline static void SetDrawEvent(SpriteRenderer& target, Event<void(sre::SpriteBatch::SpriteBatchBuilder&)>* event) {
			target.drawEvent = event;
		}
		friend class LevelBuilder;
	};
private:
	sre::Sprite sprite;
	Event<void(sre::SpriteBatch::SpriteBatchBuilder&)>* drawEvent;
	void renderSprite(sre::SpriteBatch::SpriteBatchBuilder&);
	void registerToDrawEvent();
	void deregisterFromDrawEvent();
	friend class Mutator;
};