#include "player_logic.h"
#include <SDL2/SDL_log.h>

namespace rogue {
PlayerCharacterLogic::PlayerCharacterLogic()
: up{{SDL_SCANCODE_K, SDL_SCANCODE_UP}, std::bind(&PlayerCharacterLogic::on_up, this, std::placeholders::_1)}
, down{{SDL_SCANCODE_J, SDL_SCANCODE_DOWN}, std::bind(&PlayerCharacterLogic::on_down, this, std::placeholders::_1)}
, right{{SDL_SCANCODE_L, SDL_SCANCODE_RIGHT}, std::bind(&PlayerCharacterLogic::on_right, this, std::placeholders::_1)}
, left{{SDL_SCANCODE_H, SDL_SCANCODE_LEFT}, std::bind(&PlayerCharacterLogic::on_left, this, std::placeholders::_1)}
{}

Tile PlayerCharacterLogic::move() {
	return {
		this->character->location.x + input_x,
		this->character->location.y + input_y
	};
}

void PlayerCharacterLogic::on_up(bool pressed) {
	if(pressed) {
		input_x = 0;
		input_y = -1;
	}
}

void PlayerCharacterLogic::on_down(bool pressed) {
	if(pressed) {
		input_x = 0;
		input_y = 1;
	}
}

void PlayerCharacterLogic::on_left(bool pressed) {
	if(pressed) {
		input_x = -1;
		input_y = 0;
	}
}

void PlayerCharacterLogic::on_right(bool pressed) {
	if(pressed) {
		input_x = 1;
		input_y = 0;
	}
}
};
