holesome/src/game/input/input_mapper.h
2023-06-22 23:25:15 +02:00

49 lines
1.2 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"
#include "input_device_group.h"
/**
* Maps the inputs to actions.
*/
class InputMapper
{
public:
InputMapper();
static std::shared_ptr<InputMapper> getInstance();
void processEvents();
void updateIdentities();
std::shared_ptr<InputIdentity> getInputIdentity(InputDeviceGroup deviceGroup, unsigned int gamepadId = 0);
std::set<std::shared_ptr<InputIdentity>> getInputIdentities();
bool allowNewInputIdentities = true;
public:
std::set<std::shared_ptr<InputIdentity>> newInputIdentities;
std::set<std::shared_ptr<InputIdentity>> deprecatedInputIdentities;
private:
static inline std::shared_ptr<InputMapper> singletonInstance = nullptr;
std::set<std::shared_ptr<InputIdentity>> inputIdentities;
void handleKeyPress(sf::Event::KeyEvent event);
void handleKeyRelease(sf::Event::KeyEvent event);
void handleJoystickMovement(sf::Event::JoystickMoveEvent event);
void deactivateIdentity(const std::shared_ptr<InputIdentity>& identity);
};
#endif //HOLESOME_INPUT_MAPPER_H