clang-tidy

This commit is contained in:
2026-04-03 09:31:41 +02:00
parent 8dcc1d282a
commit 46dc81124f
25 changed files with 320 additions and 314 deletions

View File

@@ -3,6 +3,7 @@
#include "game/editor/editor_statusbar.hpp"
#include <string> // Para to_string
#include <utility>
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/surface.hpp" // Para Surface
@@ -13,9 +14,9 @@
#include "utils/utils.hpp" // Para stringToColor, toLower
// Constructor
EditorStatusBar::EditorStatusBar(const std::string& room_number, const std::string& room_name)
: room_number_(room_number),
room_name_(room_name) {
EditorStatusBar::EditorStatusBar(std::string room_number, std::string room_name)
: room_number_(std::move(room_number)),
room_name_(std::move(room_name)) {
const float SURFACE_WIDTH = Options::game.width;
constexpr float SURFACE_HEIGHT = 6.0F * Tile::SIZE; // 48 pixels, igual que el scoreboard

View File

@@ -11,7 +11,7 @@ class Surface;
class EditorStatusBar {
public:
EditorStatusBar(const std::string& room_number, const std::string& room_name);
EditorStatusBar(std::string room_number, std::string room_name);
~EditorStatusBar() = default;
void render();

View File

@@ -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; }

View File

@@ -65,7 +65,7 @@ class MapEditor {
void openTilePicker(const std::string& tileset_name, int current_tile);
private:
static MapEditor* instance_; // [SINGLETON] Objeto privado
static MapEditor* instance_; // NOLINT(readability-identifier-naming) [SINGLETON] Objeto privado
MapEditor(); // Constructor
~MapEditor(); // Destructor
@@ -79,7 +79,7 @@ class MapEditor {
};
Settings settings_;
void loadSettings();
void saveSettings();
void saveSettings() const;
// Tipos para drag & drop y selección
enum class DragTarget { NONE,
@@ -102,9 +102,9 @@ class MapEditor {
// Métodos internos
void updateMousePosition();
void renderEnemyBoundaries();
void renderBoundaryMarker(float x, float y, Uint8 color);
static void renderBoundaryMarker(float x, float y, Uint8 color);
void renderSelectionHighlight();
void renderGrid();
void renderGrid() const;
void handleMouseDown(float game_x, float game_y);
void handleMouseUp();
void updateDrag();

View File

@@ -94,7 +94,7 @@ void MiniMap::layoutRooms() {
// Empezar por la primera room
const std::string& start = rooms[0].name;
bfs.push({start, {0, 0}});
bfs.push({start, {.x = 0, .y = 0}});
visited.insert(start);
// Grid ocupado: posición → nombre de room
@@ -120,21 +120,21 @@ void MiniMap::layoutRooms() {
int dx, dy;
};
std::array<Neighbor, 4> neighbors = {{
{data->upper_room, 0, -1},
{data->lower_room, 0, 1},
{data->left_room, -1, 0},
{data->right_room, 1, 0},
{.room = data->upper_room, .dx = 0, .dy = -1},
{.room = data->lower_room, .dx = 0, .dy = 1},
{.room = data->left_room, .dx = -1, .dy = 0},
{.room = data->right_room, .dx = 1, .dy = 0},
}};
for (const auto& [neighbor_name, dx, dy] : neighbors) {
if (neighbor_name == "0" || neighbor_name.empty()) { continue; }
if (visited.contains(neighbor_name)) { continue; }
GridPos neighbor_pos = {pos.x + dx, pos.y + dy};
GridPos neighbor_pos = {.x = pos.x + dx, .y = pos.y + dy};
auto nkey = std::make_pair(neighbor_pos.x, neighbor_pos.y);
if (!grid_occupied.contains(nkey)) {
visited.insert(neighbor_name);
bfs.push({neighbor_name, neighbor_pos});
bfs.emplace(neighbor_name, neighbor_pos);
}
}
}
@@ -181,7 +181,7 @@ auto MiniMap::getRoomMiniSurface(const std::string& room_name) -> std::shared_pt
const auto& tile_map = room_data->tile_map;
for (int y = 0; y < ROOM_H; ++y) {
for (int x = 0; x < ROOM_W; ++x) {
int index = y * ROOM_W + x;
int index = (y * ROOM_W) + x;
if (index >= static_cast<int>(tile_map.size())) { continue; }
int tile = tile_map[index];
@@ -253,14 +253,14 @@ void MiniMap::drawConnections() {
// Conexión derecha
if (room_data->right_room != "0" && !room_data->right_room.empty() && room_positions_.contains(room_data->right_room)) {
int x1 = px + CELL_W;
int y_mid = py + CELL_H / 2 - 1;
int y_mid = py + (CELL_H / 2) - 1;
SDL_FRect line = {.x = static_cast<float>(x1), .y = static_cast<float>(y_mid), .w = static_cast<float>(GAP), .h = 3.0F};
map_surface_->fillRect(&line, conn_color_);
}
// Conexión abajo
if (room_data->lower_room != "0" && !room_data->lower_room.empty() && room_positions_.contains(room_data->lower_room)) {
int x_mid = px + CELL_W / 2 - 1;
int x_mid = px + (CELL_W / 2) - 1;
int y1 = py + CELL_H;
SDL_FRect line = {.x = static_cast<float>(x_mid), .y = static_cast<float>(y1), .w = 3.0F, .h = static_cast<float>(GAP)};
map_surface_->fillRect(&line, conn_color_);
@@ -274,8 +274,8 @@ void MiniMap::centerOnRoom(const std::string& room_name) {
if (it == room_positions_.end()) { return; }
const auto& pos = it->second.pos;
float room_cx = static_cast<float>(cellPixelX(pos.x) + CELL_W / 2);
float room_cy = static_cast<float>(cellPixelY(pos.y) + CELL_H / 2);
auto room_cx = static_cast<float>(cellPixelX(pos.x) + (CELL_W / 2));
auto room_cy = static_cast<float>(cellPixelY(pos.y) + (CELL_H / 2));
view_x_ = static_cast<float>(PlayArea::WIDTH) / 2.0F - room_cx;
view_y_ = static_cast<float>(PlayArea::HEIGHT) / 2.0F - room_cy;
}
@@ -287,8 +287,8 @@ auto MiniMap::roomAtScreen(float screen_x, float screen_y) -> std::string {
float map_y = screen_y - view_y_;
for (const auto& [name, mini] : room_positions_) {
float rx = static_cast<float>(cellPixelX(mini.pos.x));
float ry = static_cast<float>(cellPixelY(mini.pos.y));
auto rx = static_cast<float>(cellPixelX(mini.pos.x));
auto ry = static_cast<float>(cellPixelY(mini.pos.y));
if (map_x >= rx && map_x < rx + CELL_W && map_y >= ry && map_y < ry + CELL_H) {
return name;
}
@@ -314,8 +314,8 @@ void MiniMap::render(const std::string& current_room) {
if (it != room_positions_.end()) {
float cur_x = vx + static_cast<float>(cellPixelX(it->second.pos.x)) - 1;
float cur_y = vy + static_cast<float>(cellPixelY(it->second.pos.y)) - 1;
float cur_w = static_cast<float>(CELL_W + 2);
float cur_h = static_cast<float>(CELL_H + 2);
auto cur_w = static_cast<float>(CELL_W + 2);
auto cur_h = static_cast<float>(CELL_H + 2);
if (cur_x >= 0 && cur_y >= 0 && cur_x + cur_w <= PlayArea::WIDTH && cur_y + cur_h <= PlayArea::HEIGHT) {
SDL_FRect highlight = {.x = cur_x, .y = cur_y, .w = cur_w, .h = cur_h};
game_surface->drawRectBorder(&highlight, stringToColor("bright_white"));

View File

@@ -54,8 +54,8 @@ class MiniMap {
auto getRoomMiniSurface(const std::string& room_name) -> std::shared_ptr<Surface>;
void drawConnections();
auto roomAtScreen(float screen_x, float screen_y) -> std::string;
auto cellPixelX(int grid_x) const -> int { return PADDING + (grid_x - min_grid_x_) * (CELL_W + GAP); }
auto cellPixelY(int grid_y) const -> int { return PADDING + (grid_y - min_grid_y_) * (CELL_H + GAP); }
auto cellPixelX(int grid_x) const -> int { return PADDING + ((grid_x - min_grid_x_) * (CELL_W + GAP)); }
auto cellPixelY(int grid_y) const -> int { return PADDING + ((grid_y - min_grid_y_) * (CELL_H + GAP)); }
// Tabla de color predominante por tile index
std::vector<Uint8> tile_colors_; // tile_index → palette color index
@@ -84,11 +84,11 @@ class MiniMap {
float view_start_y_{0.0F};
// Constantes
static constexpr int ROOM_W = 32; // Ancho de una room en pixels del minimapa
static constexpr int ROOM_H = 16; // Alto de una room en pixels del minimapa
static constexpr int BORDER = 1; // Borde alrededor de cada room
static constexpr int CELL_W = ROOM_W + BORDER * 2; // Room + borde
static constexpr int CELL_H = ROOM_H + BORDER * 2;
static constexpr int ROOM_W = 32; // Ancho de una room en pixels del minimapa
static constexpr int ROOM_H = 16; // Alto de una room en pixels del minimapa
static constexpr int BORDER = 1; // Borde alrededor de cada room
static constexpr int CELL_W = ROOM_W + (BORDER * 2); // Room + borde
static constexpr int CELL_H = ROOM_H + (BORDER * 2);
static constexpr int GAP = 4; // Separación entre celdas
static constexpr int SHADOW_OFFSET = 1; // Desplazamiento de la sombra
static constexpr int PADDING = 4; // Padding alrededor del minimapa

View File

@@ -36,7 +36,7 @@ auto RoomSaver::conveyorBeltToString(int direction) -> std::string {
}
// Genera el YAML completo como texto con formato compacto
auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string {
auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string { // NOLINT(readability-function-cognitive-complexity)
std::ostringstream out;
// --- Cabecera: nombre como comentario ---
@@ -49,9 +49,9 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
if (original_yaml.contains("room")) {
const auto& room_node = original_yaml["room"];
for (auto it = room_node.begin(); it != room_node.end(); ++it) {
const std::string key = it.key().get_value<std::string>();
if (key.substr(0, 5) == "name_") {
out << " " << key << ": \"" << it.value().get_value<std::string>() << "\"\n";
const auto KEY = it.key().get_value<std::string>();
if (KEY.substr(0, 5) == "name_") {
out << " " << KEY << ": \"" << it.value().get_value<std::string>() << "\"\n";
}
}
}
@@ -90,7 +90,7 @@ auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& r
for (int row = 0; row < MAP_HEIGHT; ++row) {
out << " - [";
for (int col = 0; col < MAP_WIDTH; ++col) {
int index = row * MAP_WIDTH + col;
int index = (row * MAP_WIDTH) + col;
if (index < static_cast<int>(room_data.tile_map.size())) {
out << room_data.tile_map[index];
} else {

View File

@@ -38,12 +38,12 @@ void TilePicker::open(const std::string& tileset_name, int current_tile, int bg_
// Dimensiones de salida (con spacing visual entre tiles)
int out_cell = Tile::SIZE + spacing_out_;
int display_w = tileset_width_ * out_cell - spacing_out_; // Sin trailing
int display_h = tileset_height_ * out_cell - spacing_out_;
int display_w = (tileset_width_ * out_cell) - spacing_out_; // Sin trailing
int display_h = (tileset_height_ * out_cell) - spacing_out_;
// Frame: display + borde
int frame_w = display_w + BORDER_PAD * 2;
int frame_h = display_h + BORDER_PAD * 2;
int frame_w = display_w + (BORDER_PAD * 2);
int frame_h = display_h + (BORDER_PAD * 2);
frame_surface_ = std::make_shared<Surface>(frame_w, frame_h);
// Componer: fondo + borde + tiles uno a uno
@@ -61,7 +61,7 @@ void TilePicker::open(const std::string& tileset_name, int current_tile, int bg_
frame_surface_->drawRectBorder(&inner, stringToColor("white"));
// Renderizar cada tile individualmente
constexpr float TS = static_cast<float>(Tile::SIZE);
constexpr auto TS = static_cast<float>(Tile::SIZE);
for (int row = 0; row < tileset_height_; ++row) {
for (int col = 0; col < tileset_width_; ++col) {
// Fuente: posición en el tileset original
@@ -72,8 +72,8 @@ void TilePicker::open(const std::string& tileset_name, int current_tile, int bg_
.h = TS};
// Destino: posición en el frame con spacing de salida
int dst_x = BORDER_PAD + col * out_cell;
int dst_y = BORDER_PAD + row * out_cell;
int dst_x = BORDER_PAD + (col * out_cell);
int dst_y = BORDER_PAD + (row * out_cell);
if (source_color >= 0 && target_color >= 0) {
tileset_->renderWithColorReplace(dst_x, dst_y, static_cast<Uint8>(source_color), static_cast<Uint8>(target_color), &src);
@@ -90,7 +90,7 @@ void TilePicker::open(const std::string& tileset_name, int current_tile, int bg_
// Centrar en el play area
offset_x_ = (PlayArea::WIDTH - frame_w) / 2;
int offset_y = (PlayArea::HEIGHT - frame_h) / 2;
if (offset_y < 0) { offset_y = 0; }
offset_y = std::max(offset_y, 0);
visible_height_ = PlayArea::HEIGHT;
@@ -143,7 +143,7 @@ void TilePicker::render() {
int out_cell = Tile::SIZE + spacing_out_;
float tileset_screen_x = frame_dst_.x + BORDER_PAD;
float tileset_screen_y = frame_dst_.y + BORDER_PAD - static_cast<float>(scroll_y_);
constexpr float TS = static_cast<float>(Tile::SIZE);
constexpr auto TS = static_cast<float>(Tile::SIZE);
// Highlight del tile bajo el cursor (blanco)
if (hover_tile_ >= 0) {
@@ -190,7 +190,7 @@ void TilePicker::handleEvent(const SDL_Event& event) {
if (event.type == SDL_EVENT_MOUSE_WHEEL) {
scroll_y_ -= static_cast<int>(event.wheel.y) * Tile::SIZE * 2;
int max_scroll = static_cast<int>(frame_dst_.h) - visible_height_;
if (max_scroll < 0) { max_scroll = 0; }
max_scroll = std::max(max_scroll, 0);
scroll_y_ = std::clamp(scroll_y_, 0, max_scroll);
updateMousePosition();
}