Files

33 lines
1.1 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <string>
#include <unordered_map>
// Mapeig id → SDL_Scancode carregat des de data/config/input.yaml. Consumit
// per GlobalInputs i (en el futur) per menús de remapat. No té cap cost
// global: si la clau no existeix, retorna SDL_SCANCODE_UNKNOWN i GlobalInputs
// ignora l'acció. D'aquesta manera podem afegir nous bindings al YAML sense
// tocar codi mentre els handlers continuen funcionant.
class KeyConfig {
public:
static auto get() -> KeyConfig&;
KeyConfig(const KeyConfig&) = delete;
KeyConfig(KeyConfig&&) = delete;
auto operator=(const KeyConfig&) -> KeyConfig& = delete;
auto operator=(KeyConfig&&) -> KeyConfig& = delete;
void load(const std::string& file_path);
[[nodiscard]] auto scancode(const std::string& id) const -> SDL_Scancode;
[[nodiscard]] auto bindings() const -> const std::unordered_map<std::string, SDL_Scancode>& { return bindings_; }
private:
KeyConfig() = default;
~KeyConfig() = default;
std::unordered_map<std::string, SDL_Scancode> bindings_;
};