2023-05-07 12:27:11 +02:00
|
|
|
#ifndef HOLESOME_INPUT_MAPPER_H
|
|
|
|
#define HOLESOME_INPUT_MAPPER_H
|
|
|
|
|
|
|
|
#include "../game.h"
|
|
|
|
#include <SFML/Window/Event.hpp>
|
|
|
|
#include "../../config.h"
|
2023-05-09 20:50:50 +02:00
|
|
|
#include "direction.h"
|
2023-05-16 21:56:55 +02:00
|
|
|
#include "input_identity.h"
|
2023-05-07 12:27:11 +02:00
|
|
|
|
|
|
|
class Game;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps the inputs to actions.
|
|
|
|
*/
|
|
|
|
class InputMapper
|
|
|
|
{
|
|
|
|
public:
|
2023-05-08 18:20:55 +02:00
|
|
|
static void setGame(Game *game);
|
2023-05-07 12:27:11 +02:00
|
|
|
|
2023-05-08 18:20:55 +02:00
|
|
|
static void processEvents();
|
2023-05-07 12:27:11 +02:00
|
|
|
|
2023-05-16 21:56:55 +02:00
|
|
|
static std::shared_ptr<InputIdentity> getInputIdentity(InputDeviceType deviceType, unsigned int gamepadId = 0);
|
2023-05-09 20:50:50 +02:00
|
|
|
|
2023-05-07 12:27:11 +02:00
|
|
|
private:
|
2023-05-08 18:20:55 +02:00
|
|
|
static inline Game *game = nullptr;
|
2023-05-07 12:27:11 +02:00
|
|
|
|
2023-05-16 21:56:55 +02:00
|
|
|
static std::shared_ptr<InputIdentity> allIdentity;
|
|
|
|
static std::shared_ptr<InputIdentity> keyboardIdentity;
|
|
|
|
static std::map<unsigned int, std::shared_ptr<InputIdentity>> gamepadIdentities;
|
|
|
|
|
2023-05-10 14:51:09 +02:00
|
|
|
static inline std::vector<HardDirection> inputDirectionBuffer = std::vector<HardDirection>();
|
2023-05-09 20:50:50 +02:00
|
|
|
|
2023-05-08 18:20:55 +02:00
|
|
|
static void handleKeyPress(sf::Event::KeyEvent event);
|
2023-05-09 20:50:50 +02:00
|
|
|
|
|
|
|
static void handleKeyRelease(sf::Event::KeyEvent event);
|
2023-05-16 21:56:55 +02:00
|
|
|
|
|
|
|
static void handleJoystickMovement(sf::Event::JoystickMoveEvent event);
|
2023-05-07 12:27:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //HOLESOME_INPUT_MAPPER_H
|