key_config.cpp i keys.yaml per a centralitzar i no hardcodejar tecles

This commit is contained in:
2026-04-12 15:21:43 +02:00
parent 999cf53821
commit 848b658611
19 changed files with 521 additions and 115 deletions

View File

@@ -13,6 +13,7 @@
#include <set> // Para set
#include <system_error> // Para std::error_code
#include "core/input/key_config.hpp" // Para KeyConfig
#include "core/input/mouse.hpp" // Para Mouse
#include "core/rendering/render_info.hpp" // Para RenderInfo
#include "core/rendering/screen.hpp" // Para Screen
@@ -434,8 +435,10 @@ void MapEditor::render() {
void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-function-cognitive-complexity)
// Si el tile picker está abierto, los eventos van a él.
// Excepción: la T lo cierra como toggle (sin tocar el brush).
const auto* kc = KeyConfig::get();
if (tile_picker_.isOpen()) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_T && static_cast<int>(event.key.repeat) == 0) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "tile_picker") && static_cast<int>(event.key.repeat) == 0) {
tile_picker_.close();
return;
}
@@ -446,7 +449,7 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
// Si el mini mapa está visible, delegar eventos (ESC o M para cerrar)
if (mini_map_visible_ && mini_map_) {
if (event.type == SDL_EVENT_KEY_DOWN &&
(event.key.key == SDLK_ESCAPE || event.key.key == SDLK_M) &&
(event.key.key == kc->key("EDITOR", "cancel") || event.key.key == kc->key("EDITOR", "minimap")) &&
static_cast<int>(event.key.repeat) == 0) {
mini_map_visible_ = false;
return;
@@ -456,19 +459,19 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
}
// ESC: cancelar eyedropper en progreso (sin tocar el brush previo)
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_ESCAPE && eyedropper_.active) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "cancel") && eyedropper_.active) {
eyedropper_.active = false;
return;
}
// ESC: desactivar brush
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_ESCAPE && !brush_.isEmpty()) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "cancel") && !brush_.isEmpty()) {
brush_.clear();
return;
}
// E: toggle borrador (alterna entre brush vacío y brush 1x1 ERASE)
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_E && static_cast<int>(event.key.repeat) == 0) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "eraser") && static_cast<int>(event.key.repeat) == 0) {
if (brush_.width == 1 && brush_.height == 1 && !brush_.tiles.empty() && brush_.tiles[0] == BrushPattern::ERASE) {
brush_.clear();
} else {
@@ -478,13 +481,13 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
}
// M: toggle mini mapa
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_M && static_cast<int>(event.key.repeat) == 0) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "minimap") && static_cast<int>(event.key.repeat) == 0) {
toggleMiniMap();
return;
}
// 8: alternar entre draw y collision
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_8 && static_cast<int>(event.key.repeat) == 0) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "collision") && static_cast<int>(event.key.repeat) == 0) {
setEditingCollision(!editing_collision_);
return;
}
@@ -492,21 +495,15 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
// Cursores: navegar a habitación adyacente
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
std::string direction;
switch (event.key.key) {
case SDLK_UP:
direction = "UP";
break;
case SDLK_DOWN:
direction = "DOWN";
break;
case SDLK_LEFT:
direction = "LEFT";
break;
case SDLK_RIGHT:
direction = "RIGHT";
break;
default:
break;
const auto NAV_KEY = event.key.key;
if (NAV_KEY == kc->key("EDITOR", "nav_up")) {
direction = "UP";
} else if (NAV_KEY == kc->key("EDITOR", "nav_down")) {
direction = "DOWN";
} else if (NAV_KEY == kc->key("EDITOR", "nav_left")) {
direction = "LEFT";
} else if (NAV_KEY == kc->key("EDITOR", "nav_right")) {
direction = "RIGHT";
}
if (!direction.empty() && GameControl::get_adjacent_room) {
std::string adjacent = GameControl::get_adjacent_room(direction);
@@ -523,7 +520,7 @@ void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-fun
}
// T: abrir TilePicker (el cierre con T también se gestiona arriba, antes de delegar al picker)
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_T && static_cast<int>(event.key.repeat) == 0) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == kc->key("EDITOR", "tile_picker") && static_cast<int>(event.key.repeat) == 0) {
// Deseleccionar entidades
selection_.clear();