#include "Wumbo-KeyboardInput.h"

namespace Wumbo
{
	void KeyboardInput::initialize()
	{
		Wumbo::InputMethod::initialize();
		for(int i=0;i<256;i++)
			keystateDown[i] = keystatePressed[i] = keystateReleased[i] = false;
	}
	void KeyboardInput::deinitialized()
	{
		Wumbo::InputMethod::deinitialize();
		for(int i=0;i<256;i++)
			keystateDown[i] = keystatePressed[i] = keystateReleased[i] = false;
	}
	void KeyboardInput::update()
	{
		// lol. this method does nothing.
	}
	//
#if PLATFORM_IOS
	void KeyboardInput::onEndOfFrame()
	{
		printf("Keyboard::onEndOfFrame() -- This input method is not supported on this platform.\n");
		return;
	}
	void KeyboardInput::handleEvent(sf::Event event)
	{
		printf("Keyboard::handleEvent() -- This input method is not supported on this platform.\n");
		return;
	}
	bool KeyboardInput::isKeyPressed(sf::Keyboard::Key key)
	{
		printf("Keyboard::isKeyPressed() -- This input method is not supported on this platform.\n");
		return false;
	}
	bool KeyboardInput::isKeyReleased(sf::Keyboard::Key key)
	{
		printf("Keyboard::isKeyReleased() -- This input method is not supported on this platform.\n");
		return false;
	}
	bool KeyboardInput::isKeyDown(sf::Keyboard::Key key)
	{
		printf("Keyboard::isKeyDown() -- This input method is not supported on this platform.\n");
		return false;
	}
#else
	void KeyboardInput::onEndOfFrame()
	{
		if (!initialized)
			return;
		for(int i=0;i<256;i++)
			keystateReleased[i] = keystatePressed[i] = false;
	}
	void KeyboardInput::handleEvent(sf::Event event)
	{
		if (!initialized)
			return;
		if (event.type == sf::Event::KeyPressed)
		{
			keystateDown[(int) event.key.code] = true;
			keystatePressed[(int) event.key.code] = true;
		}
		else if (event.type == sf::Event::KeyReleased)
		{
			keystateDown[(int) event.key.code] = false;
			keystateReleased[(int) event.key.code] = true;
		}
	}
	bool KeyboardInput::isKeyPressed(sf::Keyboard::Key key)
	{
		if (!initialized)
			return false;
		if (key < 0 || key > 256 || key >= sf::Keyboard::KeyCount)
			return false;
		return keystatePressed[(int)key];
	}
	bool KeyboardInput::isKeyReleased(sf::Keyboard::Key key)
	{
		if (!initialized)
			return false;
		if (key < 0 || key > 256 || key >= sf::Keyboard::KeyCount)
			return false;
		return keystateReleased[(int)key];
	}
	bool KeyboardInput::isKeyDown(sf::Keyboard::Key key)
	{
		if (!initialized)
			return false;
		if (key < 0 || key > 256 || key >= sf::Keyboard::KeyCount)
			return false;
		return keystateDown[(int)key];
	}
#endif
};