clang-tidy
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath> // Para std::round
|
||||
#include <cstdio> // Para std::remove (borrar fichero)
|
||||
#include <fstream> // Para ifstream, ofstream
|
||||
@@ -88,7 +89,7 @@ void MapEditor::loadSettings() {
|
||||
}
|
||||
|
||||
// Guarda las opciones del editor a editor.yaml
|
||||
void MapEditor::saveSettings() {
|
||||
void MapEditor::saveSettings() const {
|
||||
std::string path = Resource::List::get()->get("editor.yaml");
|
||||
if (path.empty()) { return; }
|
||||
|
||||
@@ -332,7 +333,7 @@ void MapEditor::update(float delta_time) {
|
||||
|
||||
// Si estamos pintando tiles, pintar en la posición actual del ratón
|
||||
if (painting_ && brush_tile_ != NO_BRUSH) {
|
||||
int tile_index = mouse_tile_y_ * 32 + mouse_tile_x_;
|
||||
int tile_index = (mouse_tile_y_ * 32) + mouse_tile_x_;
|
||||
if (tile_index >= 0 && tile_index < static_cast<int>(room_data_.tile_map.size())) {
|
||||
if (room_data_.tile_map[tile_index] != brush_tile_) {
|
||||
room_data_.tile_map[tile_index] = brush_tile_;
|
||||
@@ -382,7 +383,7 @@ void MapEditor::render() {
|
||||
}
|
||||
|
||||
// Maneja eventos del editor
|
||||
void MapEditor::handleEvent(const SDL_Event& event) {
|
||||
void MapEditor::handleEvent(const SDL_Event& event) { // NOLINT(readability-function-cognitive-complexity)
|
||||
// Si el tile picker está abierto, los eventos van a él
|
||||
if (tile_picker_.isOpen()) {
|
||||
tile_picker_.handleEvent(event);
|
||||
@@ -426,7 +427,7 @@ void MapEditor::handleEvent(const SDL_Event& event) {
|
||||
selected_item_ = -1;
|
||||
|
||||
// Tile bajo el cursor como tile actual del picker
|
||||
int tile_index = mouse_tile_y_ * 32 + mouse_tile_x_;
|
||||
int tile_index = (mouse_tile_y_ * 32) + mouse_tile_x_;
|
||||
int current = (tile_index >= 0 && tile_index < static_cast<int>(room_data_.tile_map.size()))
|
||||
? room_data_.tile_map[tile_index]
|
||||
: -1;
|
||||
@@ -463,7 +464,7 @@ void MapEditor::handleEvent(const SDL_Event& event) {
|
||||
if (!hit_entity) {
|
||||
// Pintar tile y entrar en modo painting
|
||||
painting_ = true;
|
||||
int tile_index = mouse_tile_y_ * 32 + mouse_tile_x_;
|
||||
int tile_index = (mouse_tile_y_ * 32) + mouse_tile_x_;
|
||||
if (tile_index >= 0 && tile_index < static_cast<int>(room_data_.tile_map.size())) {
|
||||
room_data_.tile_map[tile_index] = brush_tile_;
|
||||
room_->setTile(tile_index, brush_tile_);
|
||||
@@ -487,7 +488,7 @@ void MapEditor::handleMouseDown(float game_x, float game_y) {
|
||||
// Prioridad de hit test: jugador → enemigos (initial) → enemigos (boundaries) → items
|
||||
|
||||
// Helper para iniciar drag
|
||||
auto startDrag = [&](DragTarget target, int index, float entity_x, float entity_y) {
|
||||
auto start_drag = [&](DragTarget target, int index, float entity_x, float entity_y) {
|
||||
drag_.target = target;
|
||||
drag_.index = index;
|
||||
drag_.offset_x = game_x - entity_x;
|
||||
@@ -500,7 +501,7 @@ void MapEditor::handleMouseDown(float game_x, float game_y) {
|
||||
// 1. Hit test sobre el jugador (8x16)
|
||||
SDL_FRect player_rect = player_->getRect();
|
||||
if (pointInRect(game_x, game_y, player_rect)) {
|
||||
startDrag(DragTarget::PLAYER, -1, player_rect.x, player_rect.y);
|
||||
start_drag(DragTarget::PLAYER, -1, player_rect.x, player_rect.y);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -509,7 +510,7 @@ void MapEditor::handleMouseDown(float game_x, float game_y) {
|
||||
for (int i = 0; i < enemy_mgr->getCount(); ++i) {
|
||||
SDL_FRect enemy_rect = enemy_mgr->getEnemy(i)->getRect();
|
||||
if (pointInRect(game_x, game_y, enemy_rect)) {
|
||||
startDrag(DragTarget::ENEMY_INITIAL, i, enemy_rect.x, enemy_rect.y);
|
||||
start_drag(DragTarget::ENEMY_INITIAL, i, enemy_rect.x, enemy_rect.y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -517,17 +518,17 @@ void MapEditor::handleMouseDown(float game_x, float game_y) {
|
||||
// 3. Hit test sobre boundaries de enemigos (rectángulos 8x8 en las posiciones de room_data_)
|
||||
for (int i = 0; i < static_cast<int>(room_data_.enemies.size()); ++i) {
|
||||
const auto& ed = room_data_.enemies[i];
|
||||
constexpr float SZ = static_cast<float>(Tile::SIZE);
|
||||
constexpr auto SZ = static_cast<float>(Tile::SIZE);
|
||||
|
||||
SDL_FRect b1_rect = {.x = static_cast<float>(ed.x1), .y = static_cast<float>(ed.y1), .w = SZ, .h = SZ};
|
||||
if (pointInRect(game_x, game_y, b1_rect)) {
|
||||
startDrag(DragTarget::ENEMY_BOUND1, i, b1_rect.x, b1_rect.y);
|
||||
start_drag(DragTarget::ENEMY_BOUND1, i, b1_rect.x, b1_rect.y);
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_FRect b2_rect = {.x = static_cast<float>(ed.x2), .y = static_cast<float>(ed.y2), .w = SZ, .h = SZ};
|
||||
if (pointInRect(game_x, game_y, b2_rect)) {
|
||||
startDrag(DragTarget::ENEMY_BOUND2, i, b2_rect.x, b2_rect.y);
|
||||
start_drag(DragTarget::ENEMY_BOUND2, i, b2_rect.x, b2_rect.y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -537,7 +538,7 @@ void MapEditor::handleMouseDown(float game_x, float game_y) {
|
||||
for (int i = 0; i < item_mgr->getCount(); ++i) {
|
||||
SDL_FRect item_rect = item_mgr->getItem(i)->getCollider();
|
||||
if (pointInRect(game_x, game_y, item_rect)) {
|
||||
startDrag(DragTarget::ITEM, i, item_rect.x, item_rect.y);
|
||||
start_drag(DragTarget::ITEM, i, item_rect.x, item_rect.y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -548,7 +549,7 @@ void MapEditor::handleMouseDown(float game_x, float game_y) {
|
||||
}
|
||||
|
||||
// Procesa soltar el ratón: commit del drag
|
||||
void MapEditor::handleMouseUp() {
|
||||
void MapEditor::handleMouseUp() { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (drag_.target == DragTarget::NONE) { return; }
|
||||
|
||||
const int IDX = drag_.index;
|
||||
@@ -681,7 +682,7 @@ void MapEditor::renderSelectionHighlight() {
|
||||
auto game_surface = Screen::get()->getRendererSurface();
|
||||
if (!game_surface) { return; }
|
||||
|
||||
constexpr float SZ = static_cast<float>(Tile::SIZE);
|
||||
constexpr auto SZ = static_cast<float>(Tile::SIZE);
|
||||
|
||||
// Highlight del enemigo seleccionado (persistente, color bright_green)
|
||||
if (selected_enemy_ >= 0 && selected_enemy_ < room_->getEnemyManager()->getCount()) {
|
||||
@@ -767,10 +768,10 @@ void MapEditor::renderEnemyBoundaries() {
|
||||
// Posiciones base (pueden estar siendo arrastradas)
|
||||
float init_x = enemy.x;
|
||||
float init_y = enemy.y;
|
||||
float b1_x = static_cast<float>(enemy.x1);
|
||||
float b1_y = static_cast<float>(enemy.y1);
|
||||
float b2_x = static_cast<float>(enemy.x2);
|
||||
float b2_y = static_cast<float>(enemy.y2);
|
||||
auto b1_x = static_cast<float>(enemy.x1);
|
||||
auto b1_y = static_cast<float>(enemy.y1);
|
||||
auto b2_x = static_cast<float>(enemy.x2);
|
||||
auto b2_y = static_cast<float>(enemy.y2);
|
||||
|
||||
// Si estamos arrastrando una boundary de este enemigo, usar la posición snapped
|
||||
if (drag_.index == i) {
|
||||
@@ -824,14 +825,14 @@ void MapEditor::updateMousePosition() {
|
||||
mouse_tile_y_ = static_cast<int>(mouse_game_y_) / Tile::SIZE;
|
||||
|
||||
// Clampear a los límites del mapa
|
||||
if (mouse_tile_x_ < 0) { mouse_tile_x_ = 0; }
|
||||
mouse_tile_x_ = std::max(mouse_tile_x_, 0);
|
||||
if (mouse_tile_x_ >= PlayArea::WIDTH / Tile::SIZE) { mouse_tile_x_ = PlayArea::WIDTH / Tile::SIZE - 1; }
|
||||
if (mouse_tile_y_ < 0) { mouse_tile_y_ = 0; }
|
||||
mouse_tile_y_ = std::max(mouse_tile_y_, 0);
|
||||
if (mouse_tile_y_ >= PlayArea::HEIGHT / Tile::SIZE) { mouse_tile_y_ = PlayArea::HEIGHT / Tile::SIZE - 1; }
|
||||
}
|
||||
|
||||
// Actualiza la información de la barra de estado
|
||||
void MapEditor::updateStatusBarInfo() {
|
||||
void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (!statusbar_) { return; }
|
||||
|
||||
statusbar_->setMouseTile(mouse_tile_x_, mouse_tile_y_);
|
||||
@@ -944,7 +945,7 @@ auto MapEditor::getSetCompletions() const -> std::vector<std::string> {
|
||||
}
|
||||
|
||||
// Modifica una propiedad del enemigo seleccionado
|
||||
auto MapEditor::setEnemyProperty(const std::string& property, const std::string& value) -> std::string {
|
||||
auto MapEditor::setEnemyProperty(const std::string& property, const std::string& value) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (!active_) { return "Editor not active"; }
|
||||
if (!hasSelectedEnemy()) { return "No enemy selected"; }
|
||||
|
||||
@@ -1124,7 +1125,7 @@ auto MapEditor::duplicateEnemy() -> std::string {
|
||||
}
|
||||
|
||||
// Modifica una propiedad de la habitación
|
||||
auto MapEditor::setRoomProperty(const std::string& property, const std::string& value) -> std::string {
|
||||
auto MapEditor::setRoomProperty(const std::string& property, const std::string& value) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (!active_) { return "Editor not active"; }
|
||||
|
||||
std::string val = toLower(value);
|
||||
@@ -1267,7 +1268,7 @@ auto MapEditor::setRoomProperty(const std::string& property, const std::string&
|
||||
}
|
||||
|
||||
// Crea una nueva habitación
|
||||
auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
auto MapEditor::createNewRoom(const std::string& direction) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (!active_) { return "Editor not active"; }
|
||||
|
||||
// Validar dirección si se proporcionó
|
||||
@@ -1340,7 +1341,7 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
}
|
||||
|
||||
// Conexiones del YAML
|
||||
auto connStr = [](const std::string& c) -> std::string { return (c == "0") ? "null" : c; };
|
||||
auto conn_str = [](const std::string& c) -> std::string { return (c == "0") ? "null" : c; };
|
||||
|
||||
// Crear el YAML
|
||||
std::ofstream file(new_path);
|
||||
@@ -1355,10 +1356,10 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
file << " tileSetFile: standard.gif\n";
|
||||
file << "\n";
|
||||
file << " connections:\n";
|
||||
file << " up: " << connStr(new_room.upper_room) << "\n";
|
||||
file << " down: " << connStr(new_room.lower_room) << "\n";
|
||||
file << " left: " << connStr(new_room.left_room) << "\n";
|
||||
file << " right: " << connStr(new_room.right_room) << "\n";
|
||||
file << " up: " << conn_str(new_room.upper_room) << "\n";
|
||||
file << " down: " << conn_str(new_room.lower_room) << "\n";
|
||||
file << " left: " << conn_str(new_room.left_room) << "\n";
|
||||
file << " right: " << conn_str(new_room.right_room) << "\n";
|
||||
file << "\n";
|
||||
file << " itemColor1: bright_cyan\n";
|
||||
file << " itemColor2: yellow\n";
|
||||
@@ -1405,7 +1406,7 @@ auto MapEditor::createNewRoom(const std::string& direction) -> std::string {
|
||||
}
|
||||
|
||||
// Elimina la habitación actual
|
||||
auto MapEditor::deleteRoom() -> std::string {
|
||||
auto MapEditor::deleteRoom() -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (!active_) { return "Editor not active"; }
|
||||
|
||||
std::string deleted_name = room_path_;
|
||||
@@ -1434,7 +1435,7 @@ auto MapEditor::deleteRoom() -> std::string {
|
||||
if (target == "0") { return "Cannot delete: no other room to navigate to"; }
|
||||
|
||||
// Desenlazar todas las conexiones recíprocas
|
||||
auto unlinkReciprocal = [&](const std::string& neighbor, const std::string& field_name) {
|
||||
auto unlink_reciprocal = [&](const std::string& neighbor, const std::string& field_name) {
|
||||
if (neighbor == "0" || neighbor.empty()) { return; }
|
||||
auto other = Resource::Cache::get()->getRoom(neighbor);
|
||||
if (!other) { return; }
|
||||
@@ -1455,10 +1456,10 @@ auto MapEditor::deleteRoom() -> std::string {
|
||||
}
|
||||
};
|
||||
|
||||
unlinkReciprocal(room_data_.upper_room, "lower_room"); // Si nosotros somos su lower
|
||||
unlinkReciprocal(room_data_.lower_room, "upper_room"); // Si nosotros somos su upper
|
||||
unlinkReciprocal(room_data_.left_room, "right_room"); // Si nosotros somos su right
|
||||
unlinkReciprocal(room_data_.right_room, "left_room"); // Si nosotros somos su left
|
||||
unlink_reciprocal(room_data_.upper_room, "lower_room"); // Si nosotros somos su lower
|
||||
unlink_reciprocal(room_data_.lower_room, "upper_room"); // Si nosotros somos su upper
|
||||
unlink_reciprocal(room_data_.left_room, "right_room"); // Si nosotros somos su right
|
||||
unlink_reciprocal(room_data_.right_room, "left_room"); // Si nosotros somos su left
|
||||
|
||||
// Navegar a la room destino antes de borrar
|
||||
reenter_ = true;
|
||||
@@ -1473,9 +1474,7 @@ auto MapEditor::deleteRoom() -> std::string {
|
||||
|
||||
// Quitar del cache
|
||||
auto& cache_rooms = Resource::Cache::get()->getRooms();
|
||||
cache_rooms.erase(
|
||||
std::remove_if(cache_rooms.begin(), cache_rooms.end(), [&](const RoomResource& r) { return r.name == deleted_name; }),
|
||||
cache_rooms.end());
|
||||
std::erase_if(cache_rooms, [&](const RoomResource& r) { return r.name == deleted_name; });
|
||||
|
||||
// Quitar de Resource::List (mapa + assets.yaml)
|
||||
Resource::List::get()->removeAsset(deleted_name);
|
||||
@@ -1598,7 +1597,7 @@ auto MapEditor::duplicateItem() -> std::string {
|
||||
// Elige un color de grid que contraste con el fondo
|
||||
// Empieza con bright_black (1), si coincide con el bg en la paleta activa, sube índices
|
||||
static auto pickGridColor(Uint8 bg, const std::shared_ptr<Surface>& surface) -> Uint8 {
|
||||
Uint8 grid = static_cast<Uint8>(PaletteColor::BRIGHT_BLACK);
|
||||
auto grid = static_cast<Uint8>(PaletteColor::BRIGHT_BLACK);
|
||||
Uint32 bg_argb = surface->getPaletteColor(bg);
|
||||
|
||||
// Si bright_black es igual al bg, buscar el siguiente color distinto
|
||||
@@ -1610,7 +1609,7 @@ static auto pickGridColor(Uint8 bg, const std::shared_ptr<Surface>& surface) ->
|
||||
}
|
||||
|
||||
// Dibuja la cuadrícula de tiles (líneas de puntos, 1 pixel sí / 1 no)
|
||||
void MapEditor::renderGrid() {
|
||||
void MapEditor::renderGrid() const {
|
||||
auto game_surface = Screen::get()->getRendererSurface();
|
||||
if (!game_surface) { return; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user