#include <InputMethod/KeyboardInput/KeyboardInput.hpp>
#include <Settings/Settings.hpp>

void KeyboardInput::onEvent(InputManager &manager, SDL_Event &event)
{
    if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0)
    {
        std::optional<std::string> action = settings.keyBindings.getActionForScancode(event.key.scancode);
        if (action.has_value())
        {
            manager.onActionStarts(*action);
        }
    }
    else if (event.type == SDL_EVENT_KEY_UP)
    {
        std::optional<std::string> action = settings.keyBindings.getActionForScancode(event.key.scancode);
        if (action.has_value())
        {
            manager.onActionEnds(*action);
        }
    }
}