linter: varios

This commit is contained in:
2025-10-24 17:12:57 +02:00
parent 9979f31b4a
commit 636e4d932a
11 changed files with 136 additions and 106 deletions

View File

@@ -15,14 +15,14 @@ void AssetIntegrated::initWithResourcePack(const std::string& executable_path,
auto& loader = ResourceLoader::getInstance(); auto& loader = ResourceLoader::getInstance();
if (loader.initialize(resource_pack_path, true)) { if (loader.initialize(resource_pack_path, true)) {
resource_pack_enabled = true; resource_pack_enabled = true;
std::cout << "Asset system initialized with resource pack: " << resource_pack_path << std::endl; std::cout << "Asset system initialized with resource pack: " << resource_pack_path << '\n';
} else { } else {
resource_pack_enabled = false; resource_pack_enabled = false;
std::cout << "Asset system initialized in fallback mode (filesystem)" << std::endl; std::cout << "Asset system initialized in fallback mode (filesystem)" << '\n';
} }
} }
std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) { auto AssetIntegrated::loadFile(const std::string& filename) -> std::vector<uint8_t> {
if (shouldUseResourcePack(filename) && resource_pack_enabled) { if (shouldUseResourcePack(filename) && resource_pack_enabled) {
// Intentar cargar del pack de recursos // Intentar cargar del pack de recursos
auto& loader = ResourceLoader::getInstance(); auto& loader = ResourceLoader::getInstance();
@@ -45,7 +45,7 @@ std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
// Fallback: cargar del filesystem // Fallback: cargar del filesystem
std::ifstream file(filename, std::ios::binary | std::ios::ate); std::ifstream file(filename, std::ios::binary | std::ios::ate);
if (!file) { if (!file) {
std::cerr << "Error: Could not open file: " << filename << std::endl; std::cerr << "Error: Could not open file: " << filename << '\n';
return {}; return {};
} }
@@ -54,25 +54,25 @@ std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
std::vector<uint8_t> data(file_size); std::vector<uint8_t> data(file_size);
if (!file.read(reinterpret_cast<char*>(data.data()), file_size)) { if (!file.read(reinterpret_cast<char*>(data.data()), file_size)) {
std::cerr << "Error: Could not read file: " << filename << std::endl; std::cerr << "Error: Could not read file: " << filename << '\n';
return {}; return {};
} }
return data; return data;
} }
bool AssetIntegrated::fileExists(const std::string& filename) const { auto AssetIntegrated::fileExists(const std::string& filename) const -> bool {
if (shouldUseResourcePack(filename) && resource_pack_enabled) { if (shouldUseResourcePack(filename) && resource_pack_enabled) {
auto& loader = ResourceLoader::getInstance(); auto& loader = ResourceLoader::getInstance();
// Convertir ruta completa a ruta relativa para el pack // Convertir ruta completa a ruta relativa para el pack
std::string relativePath = filename; std::string relative_path = filename;
size_t data_pos = filename.find("data/"); size_t data_pos = filename.find("data/");
if (data_pos != std::string::npos) { if (data_pos != std::string::npos) {
relativePath = filename.substr(data_pos + 5); relative_path = filename.substr(data_pos + 5);
} }
if (loader.resourceExists(relativePath)) { if (loader.resourceExists(relative_path)) {
return true; return true;
} }
} }
@@ -81,24 +81,24 @@ bool AssetIntegrated::fileExists(const std::string& filename) const {
return std::filesystem::exists(filename); return std::filesystem::exists(filename);
} }
std::string AssetIntegrated::getSystemPath(const std::string& filename) const { auto AssetIntegrated::getSystemPath(const std::string& filename) -> std::string {
// Los archivos de sistema/config siempre van al filesystem // Los archivos de sistema/config siempre van al filesystem
return filename; return filename;
} }
bool AssetIntegrated::shouldUseResourcePack(const std::string& filepath) const { auto AssetIntegrated::shouldUseResourcePack(const std::string& filepath) -> bool {
// Los archivos que NO van al pack: // Los archivos que NO van al pack:
// - Archivos de config/ (ahora están fuera de data/) // - Archivos de config/ (ahora están fuera de data/)
// - Archivos con absolute=true en assets.txt // - Archivos con absolute=true en assets.txt
// - Archivos de sistema (${SYSTEM_FOLDER}) // - Archivos de sistema (${SYSTEM_FOLDER})
if (filepath.find("/config/") != std::string::npos || if (filepath.find("/config/") != std::string::npos ||
filepath.find("config/") == 0) { filepath.starts_with("config/")) {
return false; return false;
} }
if (filepath.find("/data/") != std::string::npos || if (filepath.find("/data/") != std::string::npos ||
filepath.find("data/") == 0) { filepath.starts_with("data/")) {
return true; return true;
} }

View File

@@ -19,11 +19,11 @@ class AssetIntegrated : public Asset {
auto fileExists(const std::string& filename) const -> bool; auto fileExists(const std::string& filename) const -> bool;
// Obtiene la ruta completa para archivos del sistema/config // Obtiene la ruta completa para archivos del sistema/config
auto getSystemPath(const std::string& filename) const -> std::string; static auto getSystemPath(const std::string& filename) -> std::string;
private: private:
static bool resource_pack_enabled; static bool resource_pack_enabled;
// Determina si un archivo debe cargarse del pack o del filesystem // Determina si un archivo debe cargarse del pack o del filesystem
auto shouldUseResourcePack(const std::string& filepath) const -> bool; static auto shouldUseResourcePack(const std::string& filepath) -> bool;
}; };

View File

@@ -1,10 +1,11 @@
#pragma once #pragma once
#include <algorithm> // Para std::max
class Cooldown { class Cooldown {
public: public:
Cooldown(float first_delay_s = 0.0F, float repeat_delay_s = 0.0F) Cooldown(float first_delay_s = 0.0F, float repeat_delay_s = 0.0F)
: first_delay_s_(first_delay_s), repeat_delay_s_(repeat_delay_s), : first_delay_s_(first_delay_s), repeat_delay_s_(repeat_delay_s) {}
remaining_s_(0.0F), held_before_(false) {}
// Llamar cada frame con delta en segundos (float) // Llamar cada frame con delta en segundos (float)
void update(float delta_s) { void update(float delta_s) {
@@ -13,12 +14,14 @@ public:
return; return;
} }
remaining_s_ -= delta_s; remaining_s_ -= delta_s;
if (remaining_s_ < 0.0F) remaining_s_ = 0.0F; remaining_s_ = std::max(remaining_s_, 0.0F);
} }
// Llamar cuando el input está activo. Devuelve true si debe ejecutarse la acción ahora. // Llamar cuando el input está activo. Devuelve true si debe ejecutarse la acción ahora.
bool tryConsumeOnHeld() { auto tryConsumeOnHeld() -> bool {
if (remaining_s_ > 0.0F) return false; if (remaining_s_ > 0.0F) {
return false;
}
float delay = held_before_ ? repeat_delay_s_ : first_delay_s_; float delay = held_before_ ? repeat_delay_s_ : first_delay_s_;
remaining_s_ = delay; remaining_s_ = delay;
@@ -32,7 +35,7 @@ public:
remaining_s_ = 0.0F; remaining_s_ = 0.0F;
} }
bool empty() const { return remaining_s_ == 0.0F; } [[nodiscard]] auto empty() const -> bool { return remaining_s_ == 0.0F; }
// Fuerza un valor en segundos (útil para tests o resets) // Fuerza un valor en segundos (útil para tests o resets)
void forceSet(float seconds) { remaining_s_ = seconds > 0.0F ? seconds : 0.0F; } void forceSet(float seconds) { remaining_s_ = seconds > 0.0F ? seconds : 0.0F; }
@@ -40,6 +43,6 @@ public:
private: private:
float first_delay_s_; float first_delay_s_;
float repeat_delay_s_; float repeat_delay_s_;
float remaining_s_; float remaining_s_{0.0F};
bool held_before_; bool held_before_{false};
}; };

View File

@@ -67,7 +67,7 @@ auto EnterName::getSelectedCharacter(int offset) const -> std::string {
index += size; index += size;
} }
return std::string(1, character_list_[index]); return {1, character_list_[index]};
} }
// Devuelve el carrusel completo de caracteres centrado en el seleccionado // Devuelve el carrusel completo de caracteres centrado en el seleccionado

View File

@@ -130,12 +130,7 @@ void Fade::updatePostState() {
} }
// Mantener el estado final del fade // Mantener el estado final del fade
Uint8 post_alpha = a_; Uint8 post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
if (type_ == Type::RANDOM_SQUARE2 || type_ == Type::DIAGONAL) {
post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
} else {
post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
}
cleanBackbuffer(r_, g_, b_, post_alpha); cleanBackbuffer(r_, g_, b_, post_alpha);
} }
@@ -145,7 +140,7 @@ void Fade::updateFullscreenFade() {
float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F); float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F);
// Modifica la transparencia basada en el progreso // Modifica la transparencia basada en el progreso
Uint8 current_alpha = static_cast<Uint8>(progress * 255.0f); auto current_alpha = static_cast<Uint8>(progress * 255.0F);
a_ = (mode_ == Mode::OUT) ? current_alpha : 255 - current_alpha; a_ = (mode_ == Mode::OUT) ? current_alpha : 255 - current_alpha;
SDL_SetTextureAlphaMod(backbuffer_, a_); SDL_SetTextureAlphaMod(backbuffer_, a_);
@@ -162,10 +157,10 @@ void Fade::updateCenterFade() {
float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F); float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F);
// Calcula la altura de las barras // Calcula la altura de las barras
float rect_height = progress * (param.game.height / 2.0f); float rect_height = progress * (param.game.height / 2.0F);
if (mode_ == Mode::IN) { if (mode_ == Mode::IN) {
rect_height = (param.game.height / 2.0f) - rect_height; rect_height = (param.game.height / 2.0F) - rect_height;
} }
rect1_.h = rect_height; rect1_.h = rect_height;
@@ -509,7 +504,7 @@ void Fade::activate() {
case Type::VENETIAN: { case Type::VENETIAN: {
square_.clear(); square_.clear();
rect1_ = {.x = 0, .y = 0, .w = param.game.width, .h = (mode_ == Mode::OUT) ? 0.0f : static_cast<float>(param.fade.venetian_size)}; rect1_ = {.x = 0, .y = 0, .w = param.game.width, .h = (mode_ == Mode::OUT) ? 0.0F : param.fade.venetian_size};
const int MAX = param.game.height / param.fade.venetian_size; const int MAX = param.game.height / param.fade.venetian_size;
for (int i = 0; i < MAX; ++i) { for (int i = 0; i < MAX; ++i) {
rect1_.y = i * param.fade.venetian_size; rect1_.y = i * param.fade.venetian_size;
@@ -546,7 +541,11 @@ void Fade::cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
// Calcula el valor del estado del fade // Calcula el valor del estado del fade
auto Fade::calculateValue(int min, int max, int current) -> int { auto Fade::calculateValue(int min, int max, int current) -> int {
if (current <= min) return 0; if (current <= min) {
if (current >= max) return 100; return 0;
}
if (current >= max) {
return 100;
}
return static_cast<int>(100.0 * (current - min) / (max - min)); return static_cast<int>(100.0 * (current - min) / (max - min));
} }

View File

@@ -55,62 +55,70 @@ void PathSprite::render() {
} }
} }
// Añade un recorrido // Determina el tipo de centrado basado en el tipo de path
void PathSprite::addPath(Path path, bool centered) { auto PathSprite::determineCenteringType(const Path& path, bool centered) const -> PathCentered {
PathCentered path_centered = PathCentered::NONE; if (!centered) {
return PathCentered::NONE;
}
if (centered) {
if (path.is_point_path) { if (path.is_point_path) {
// Lógica de centrado para paths por PUNTOS (como antes) // Lógica de centrado para paths por PUNTOS
if (!path.spots.empty()) { if (!path.spots.empty()) {
// Si X es constante, es un path Vertical, centramos en X // Si X es constante, es un path Vertical, centramos en X
path_centered = (path.spots.back().x == path.spots.front().x) ? PathCentered::ON_X : PathCentered::ON_Y; return (path.spots.back().x == path.spots.front().x) ? PathCentered::ON_X : PathCentered::ON_Y;
}
} else {
// Lógica de centrado para paths GENERADOS (por duración)
// Si el tipo es Vertical, centramos en X
path_centered = (path.type == PathType::VERTICAL) ? PathCentered::ON_X : PathCentered::ON_Y;
} }
return PathCentered::NONE;
} }
switch (path_centered) { // Lógica de centrado para paths GENERADOS
case PathCentered::ON_X: { // Si el tipo es Vertical, centramos en X
// Centrar en el eje X (para paths Verticales) return (path.type == PathType::VERTICAL) ? PathCentered::ON_X : PathCentered::ON_Y;
const float X_OFFSET = pos_.w / 2.0F; // Asume que pos_.w está inicializado por el constructor de Sprite }
// Aplica centrado en el eje X (para paths verticales)
void PathSprite::centerPathOnX(Path& path, float offset) {
if (path.is_point_path) { if (path.is_point_path) {
const float X_BASE = !path.spots.empty() ? path.spots.front().x : 0.0F; const float X_BASE = !path.spots.empty() ? path.spots.front().x : 0.0F;
const float X = X_BASE - X_OFFSET; const float X = X_BASE - offset;
for (auto& spot : path.spots) { for (auto& spot : path.spots) {
spot.x = X; spot.x = X;
} }
} else { } else {
// Es un path generado, ajustamos la posición fija (que es X) // Es un path generado, ajustamos la posición fija (que es X)
path.fixed_pos -= X_OFFSET; path.fixed_pos -= offset;
} }
paths_.emplace_back(std::move(path)); // Usamos std::move
break;
} }
case PathCentered::ON_Y: {
// Centrar en el eje Y (para paths Horizontales) // Aplica centrado en el eje Y (para paths horizontales)
const float Y_OFFSET = pos_.h / 2.0F; // Asume que pos_.h está inicializado void PathSprite::centerPathOnY(Path& path, float offset) {
if (path.is_point_path) { if (path.is_point_path) {
const float Y_BASE = !path.spots.empty() ? path.spots.front().y : 0.0F; const float Y_BASE = !path.spots.empty() ? path.spots.front().y : 0.0F;
const float Y = Y_BASE - Y_OFFSET; const float Y = Y_BASE - offset;
for (auto& spot : path.spots) { for (auto& spot : path.spots) {
spot.y = Y; spot.y = Y;
} }
} else { } else {
// Es un path generado, ajustamos la posición fija (que es Y) // Es un path generado, ajustamos la posición fija (que es Y)
path.fixed_pos -= Y_OFFSET; path.fixed_pos -= offset;
} }
paths_.emplace_back(std::move(path)); // Usamos std::move }
break;
} // Añade un recorrido
default: void PathSprite::addPath(Path path, bool centered) {
// Sin centrado PathCentered path_centered = determineCenteringType(path, centered);
paths_.emplace_back(std::move(path)); // Usamos std::move
switch (path_centered) {
case PathCentered::ON_X:
centerPathOnX(path, pos_.w / 2.0F);
break;
case PathCentered::ON_Y:
centerPathOnY(path, pos_.h / 2.0F);
break;
case PathCentered::NONE:
break; break;
} }
paths_.emplace_back(std::move(path));
} }
// Añade un recorrido generado (en segundos) // Añade un recorrido generado (en segundos)

View File

@@ -93,4 +93,9 @@ class PathSprite : public Sprite {
// --- Métodos internos --- // --- Métodos internos ---
void moveThroughCurrentPath(float delta_time); // Coloca el sprite en los diferentes puntos del recorrido void moveThroughCurrentPath(float delta_time); // Coloca el sprite en los diferentes puntos del recorrido
void goToNextPathOrDie(); // Cambia de recorrido o finaliza void goToNextPathOrDie(); // Cambia de recorrido o finaliza
// --- Métodos auxiliares para addPath ---
[[nodiscard]] auto determineCenteringType(const Path& path, bool centered) const -> PathCentered; // Determina el tipo de centrado
void centerPathOnX(Path& path, float offset); // Aplica centrado en el eje X
void centerPathOnY(Path& path, float offset); // Aplica centrado en el eje Y
}; };

View File

@@ -35,7 +35,7 @@ struct AudioData {
auto loadAudioData(const std::string& file_path) -> AudioData { auto loadAudioData(const std::string& file_path) -> AudioData {
auto resource_data = ResourceHelper::loadFile(file_path); auto resource_data = ResourceHelper::loadFile(file_path);
return AudioData{std::move(resource_data), file_path}; return AudioData{.data = std::move(resource_data), .filepath = file_path};
} }
} // namespace } // namespace

View File

@@ -119,7 +119,7 @@ void Scoreboard::setCarouselAnimation(Id id, int selected_index, EnterName* ente
} }
// ===== Bloquear si aún animando ===== // ===== Bloquear si aún animando =====
if (std::abs(carousel_position_.at(idx) - carousel_target_.at(idx)) > 0.01f) { if (std::abs(carousel_position_.at(idx) - carousel_target_.at(idx)) > 0.01F) {
return; return;
} }
@@ -755,7 +755,7 @@ void Scoreboard::renderCarousel(size_t panel_index, int center_x, int y) {
} }
const float FRACTIONAL_OFFSET = frac; const float FRACTIONAL_OFFSET = frac;
const int PIXEL_OFFSET = static_cast<int>(FRACTIONAL_OFFSET * CHAR_STEP + 0.5f); const int PIXEL_OFFSET = static_cast<int>((FRACTIONAL_OFFSET * CHAR_STEP) + 0.5F);
// Índice base en la lista de caracteres (posición central) // Índice base en la lista de caracteres (posición central)
const int BASE_INDEX = static_cast<int>(std::floor(carousel_pos)); const int BASE_INDEX = static_cast<int>(std::floor(carousel_pos));
@@ -774,11 +774,14 @@ void Scoreboard::renderCarousel(size_t panel_index, int center_x, int y) {
// --- Calcular distancia circular correcta (corregido el bug de wrap) --- // --- Calcular distancia circular correcta (corregido el bug de wrap) ---
float normalized_pos = std::fmod(carousel_pos, static_cast<float>(CHAR_LIST_SIZE)); float normalized_pos = std::fmod(carousel_pos, static_cast<float>(CHAR_LIST_SIZE));
if (normalized_pos < 0.0F) normalized_pos += static_cast<float>(CHAR_LIST_SIZE); if (normalized_pos < 0.0F) {
normalized_pos += static_cast<float>(CHAR_LIST_SIZE);
}
float diff = std::abs(static_cast<float>(char_index) - normalized_pos); float diff = std::abs(static_cast<float>(char_index) - normalized_pos);
if (diff > static_cast<float>(CHAR_LIST_SIZE) / 2.0F) if (diff > static_cast<float>(CHAR_LIST_SIZE) / 2.0F) {
diff = static_cast<float>(CHAR_LIST_SIZE) - diff; diff = static_cast<float>(CHAR_LIST_SIZE) - diff;
}
const float DISTANCE_FROM_CENTER = diff; const float DISTANCE_FROM_CENTER = diff;

View File

@@ -285,6 +285,30 @@ void Text::writeCentered(int x, int y, const std::string& text, int kerning, int
write(x, y, text, kerning, length); write(x, y, text, kerning, length);
} }
// Renderiza sombra del texto
void Text::renderShadow(int x, int y, const std::string& text, Color shadow_color, int kerning, int length, Uint8 shadow_distance) {
if (white_sprite_) {
writeColoredWithSprite(white_sprite_.get(), x + shadow_distance, y + shadow_distance, text, shadow_color, kerning, length);
} else {
writeColored(x + shadow_distance, y + shadow_distance, text, shadow_color, kerning, length);
}
}
// Renderiza stroke sólido (método tradicional para stroke sin alpha)
void Text::renderSolidStroke(int x, int y, const std::string& text, Color stroke_color, int kerning, int length, Uint8 shadow_distance) {
for (int dist = 1; dist <= shadow_distance; ++dist) {
for (int dy = -dist; dy <= dist; ++dy) {
for (int dx = -dist; dx <= dist; ++dx) {
if (white_sprite_) {
writeColoredWithSprite(white_sprite_.get(), x + dx, y + dy, text, stroke_color, kerning, length);
} else {
writeColored(x + dx, y + dy, text, stroke_color, kerning, length);
}
}
}
}
}
// Escribe texto con extras // Escribe texto con extras
void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) { void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) {
const auto CENTERED = ((flags & Text::CENTER) == Text::CENTER); const auto CENTERED = ((flags & Text::CENTER) == Text::CENTER);
@@ -297,11 +321,7 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerni
} }
if (SHADOWED) { if (SHADOWED) {
if (white_sprite_) { renderShadow(x, y, text, shadow_color, kerning, length, shadow_distance);
writeColoredWithSprite(white_sprite_.get(), x + shadow_distance, y + shadow_distance, text, shadow_color, kerning, length);
} else {
writeColored(x + shadow_distance, y + shadow_distance, text, shadow_color, kerning, length);
}
} }
if (STROKED) { if (STROKED) {
@@ -310,17 +330,7 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerni
writeStrokeWithAlpha(x, y, text, kerning, shadow_color, shadow_distance, length); writeStrokeWithAlpha(x, y, text, kerning, shadow_color, shadow_distance, length);
} else { } else {
// Método tradicional para stroke sólido // Método tradicional para stroke sólido
for (int dist = 1; dist <= shadow_distance; ++dist) { renderSolidStroke(x, y, text, shadow_color, kerning, length, shadow_distance);
for (int dy = -dist; dy <= dist; ++dy) {
for (int dx = -dist; dx <= dist; ++dx) {
if (white_sprite_) {
writeColoredWithSprite(white_sprite_.get(), x + dx, y + dy, text, shadow_color, kerning, length);
} else {
writeColored(x + dx, y + dy, text, shadow_color, kerning, length);
}
}
}
}
} }
} }

View File

@@ -86,6 +86,8 @@ class Text {
// --- Métodos privados --- // --- Métodos privados ---
void writeColoredWithSprite(Sprite* sprite, int x, int y, const std::string& text, Color color, int kerning = 1, int length = -1); // Escribe con un sprite específico void writeColoredWithSprite(Sprite* sprite, int x, int y, const std::string& text, Color color, int kerning = 1, int length = -1); // Escribe con un sprite específico
void writeStrokeWithAlpha(int x, int y, const std::string& text, int kerning, Color stroke_color, Uint8 shadow_distance, int length = -1); // Escribe stroke con alpha correcto void writeStrokeWithAlpha(int x, int y, const std::string& text, int kerning, Color stroke_color, Uint8 shadow_distance, int length = -1); // Escribe stroke con alpha correcto
void renderShadow(int x, int y, const std::string& text, Color shadow_color, int kerning, int length, Uint8 shadow_distance); // Renderiza sombra del texto
void renderSolidStroke(int x, int y, const std::string& text, Color stroke_color, int kerning, int length, Uint8 shadow_distance); // Renderiza stroke sólido
private: private:
// --- Objetos y punteros --- // --- Objetos y punteros ---