holesome/src/game/input/input_mapper.h
2023-05-17 14:13:39 +02:00

44 lines
1.1 KiB
C++

#ifndef HOLESOME_INPUT_MAPPER_H
#define HOLESOME_INPUT_MAPPER_H
#include "../game.h"
#include <SFML/Window/Event.hpp>
#include "../../config.h"
#include "direction.h"
#include "input_identity.h"
/**
* Maps the inputs to actions.
*/
class InputMapper
{
public:
InputMapper();
static std::shared_ptr<InputMapper> getInstance();
void processEvents();
std::shared_ptr<InputIdentity> getInputIdentity(InputDeviceType deviceType, unsigned int gamepadId = 0);
std::vector<std::shared_ptr<InputIdentity>> getAllInputIdentities();
private:
static inline std::shared_ptr<InputMapper> singletonInstance = nullptr;
std::shared_ptr<InputIdentity> allIdentity;
std::shared_ptr<InputIdentity> keyboardIdentity;
std::map<unsigned int, std::shared_ptr<InputIdentity>> gamepadIdentities;
void handleKeyPress(sf::Event::KeyEvent event);
void handleKeyRelease(sf::Event::KeyEvent event);
void handleJoystickMovement(sf::Event::JoystickMoveEvent event);
void addGamepadIdentity(unsigned int gamepadId);
void deactivateGamepadIdentity(unsigned int gamepadId);
};
#endif //HOLESOME_INPUT_MAPPER_H