linter: varios
This commit is contained in:
@@ -15,14 +15,14 @@ void AssetIntegrated::initWithResourcePack(const std::string& executable_path,
|
||||
auto& loader = ResourceLoader::getInstance();
|
||||
if (loader.initialize(resource_pack_path, 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 {
|
||||
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) {
|
||||
// Intentar cargar del pack de recursos
|
||||
auto& loader = ResourceLoader::getInstance();
|
||||
@@ -45,7 +45,7 @@ std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
|
||||
// Fallback: cargar del filesystem
|
||||
std::ifstream file(filename, std::ios::binary | std::ios::ate);
|
||||
if (!file) {
|
||||
std::cerr << "Error: Could not open file: " << filename << std::endl;
|
||||
std::cerr << "Error: Could not open file: " << filename << '\n';
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -54,25 +54,25 @@ std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
|
||||
|
||||
std::vector<uint8_t> 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 data;
|
||||
}
|
||||
|
||||
bool AssetIntegrated::fileExists(const std::string& filename) const {
|
||||
auto AssetIntegrated::fileExists(const std::string& filename) const -> bool {
|
||||
if (shouldUseResourcePack(filename) && resource_pack_enabled) {
|
||||
auto& loader = ResourceLoader::getInstance();
|
||||
|
||||
// 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/");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -81,24 +81,24 @@ bool AssetIntegrated::fileExists(const std::string& filename) const {
|
||||
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
|
||||
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:
|
||||
// - Archivos de config/ (ahora están fuera de data/)
|
||||
// - Archivos con absolute=true en assets.txt
|
||||
// - Archivos de sistema (${SYSTEM_FOLDER})
|
||||
|
||||
if (filepath.find("/config/") != std::string::npos ||
|
||||
filepath.find("config/") == 0) {
|
||||
filepath.starts_with("config/")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (filepath.find("/data/") != std::string::npos ||
|
||||
filepath.find("data/") == 0) {
|
||||
filepath.starts_with("data/")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ class AssetIntegrated : public Asset {
|
||||
auto fileExists(const std::string& filename) const -> bool;
|
||||
|
||||
// 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:
|
||||
static bool resource_pack_enabled;
|
||||
|
||||
// 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;
|
||||
};
|
||||
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm> // Para std::max
|
||||
|
||||
class Cooldown {
|
||||
public:
|
||||
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),
|
||||
remaining_s_(0.0F), held_before_(false) {}
|
||||
: first_delay_s_(first_delay_s), repeat_delay_s_(repeat_delay_s) {}
|
||||
|
||||
// Llamar cada frame con delta en segundos (float)
|
||||
void update(float delta_s) {
|
||||
@@ -13,12 +14,14 @@ public:
|
||||
return;
|
||||
}
|
||||
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.
|
||||
bool tryConsumeOnHeld() {
|
||||
if (remaining_s_ > 0.0F) return false;
|
||||
auto tryConsumeOnHeld() -> bool {
|
||||
if (remaining_s_ > 0.0F) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float delay = held_before_ ? repeat_delay_s_ : first_delay_s_;
|
||||
remaining_s_ = delay;
|
||||
@@ -32,7 +35,7 @@ public:
|
||||
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)
|
||||
void forceSet(float seconds) { remaining_s_ = seconds > 0.0F ? seconds : 0.0F; }
|
||||
@@ -40,6 +43,6 @@ public:
|
||||
private:
|
||||
float first_delay_s_;
|
||||
float repeat_delay_s_;
|
||||
float remaining_s_;
|
||||
bool held_before_;
|
||||
float remaining_s_{0.0F};
|
||||
bool held_before_{false};
|
||||
};
|
||||
|
||||
@@ -67,7 +67,7 @@ auto EnterName::getSelectedCharacter(int offset) const -> std::string {
|
||||
index += size;
|
||||
}
|
||||
|
||||
return std::string(1, character_list_[index]);
|
||||
return {1, character_list_[index]};
|
||||
}
|
||||
|
||||
// Devuelve el carrusel completo de caracteres centrado en el seleccionado
|
||||
|
||||
@@ -130,12 +130,7 @@ void Fade::updatePostState() {
|
||||
}
|
||||
|
||||
// Mantener el estado final del fade
|
||||
Uint8 post_alpha = a_;
|
||||
if (type_ == Type::RANDOM_SQUARE2 || type_ == Type::DIAGONAL) {
|
||||
post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
|
||||
} else {
|
||||
post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
|
||||
}
|
||||
Uint8 post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
|
||||
|
||||
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);
|
||||
|
||||
// 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;
|
||||
SDL_SetTextureAlphaMod(backbuffer_, a_);
|
||||
|
||||
@@ -162,10 +157,10 @@ void Fade::updateCenterFade() {
|
||||
float progress = std::min(static_cast<float>(elapsed_time) / fading_duration_, 1.0F);
|
||||
|
||||
// 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) {
|
||||
rect_height = (param.game.height / 2.0f) - rect_height;
|
||||
rect_height = (param.game.height / 2.0F) - rect_height;
|
||||
}
|
||||
|
||||
rect1_.h = rect_height;
|
||||
@@ -509,7 +504,7 @@ void Fade::activate() {
|
||||
|
||||
case Type::VENETIAN: {
|
||||
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;
|
||||
for (int i = 0; i < MAX; ++i) {
|
||||
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
|
||||
auto Fade::calculateValue(int min, int max, int current) -> int {
|
||||
if (current <= min) return 0;
|
||||
if (current >= max) return 100;
|
||||
if (current <= min) {
|
||||
return 0;
|
||||
}
|
||||
if (current >= max) {
|
||||
return 100;
|
||||
}
|
||||
return static_cast<int>(100.0 * (current - min) / (max - min));
|
||||
}
|
||||
@@ -55,62 +55,70 @@ void PathSprite::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(Path path, bool centered) {
|
||||
PathCentered path_centered = PathCentered::NONE;
|
||||
// Determina el tipo de centrado basado en el tipo de path
|
||||
auto PathSprite::determineCenteringType(const Path& path, bool centered) const -> PathCentered {
|
||||
if (!centered) {
|
||||
return PathCentered::NONE;
|
||||
}
|
||||
|
||||
if (centered) {
|
||||
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()) {
|
||||
// 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;
|
||||
}
|
||||
} 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 (path.spots.back().x == path.spots.front().x) ? PathCentered::ON_X : PathCentered::ON_Y;
|
||||
}
|
||||
return PathCentered::NONE;
|
||||
}
|
||||
|
||||
switch (path_centered) {
|
||||
case PathCentered::ON_X: {
|
||||
// Centrar en el eje X (para paths Verticales)
|
||||
const float X_OFFSET = pos_.w / 2.0F; // Asume que pos_.w está inicializado por el constructor de Sprite
|
||||
// Lógica de centrado para paths GENERADOS
|
||||
// Si el tipo es Vertical, centramos en X
|
||||
return (path.type == PathType::VERTICAL) ? PathCentered::ON_X : PathCentered::ON_Y;
|
||||
}
|
||||
|
||||
// Aplica centrado en el eje X (para paths verticales)
|
||||
void PathSprite::centerPathOnX(Path& path, float offset) {
|
||||
if (path.is_point_path) {
|
||||
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) {
|
||||
spot.x = X;
|
||||
}
|
||||
} else {
|
||||
// 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)
|
||||
const float Y_OFFSET = pos_.h / 2.0F; // Asume que pos_.h está inicializado
|
||||
|
||||
// Aplica centrado en el eje Y (para paths horizontales)
|
||||
void PathSprite::centerPathOnY(Path& path, float offset) {
|
||||
if (path.is_point_path) {
|
||||
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) {
|
||||
spot.y = Y;
|
||||
}
|
||||
} else {
|
||||
// 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;
|
||||
}
|
||||
default:
|
||||
// Sin centrado
|
||||
paths_.emplace_back(std::move(path)); // Usamos std::move
|
||||
}
|
||||
|
||||
// Añade un recorrido
|
||||
void PathSprite::addPath(Path path, bool centered) {
|
||||
PathCentered path_centered = determineCenteringType(path, centered);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
paths_.emplace_back(std::move(path));
|
||||
}
|
||||
|
||||
// Añade un recorrido generado (en segundos)
|
||||
|
||||
@@ -93,4 +93,9 @@ class PathSprite : public Sprite {
|
||||
// --- Métodos internos ---
|
||||
void moveThroughCurrentPath(float delta_time); // Coloca el sprite en los diferentes puntos del recorrido
|
||||
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
|
||||
};
|
||||
@@ -35,7 +35,7 @@ struct AudioData {
|
||||
|
||||
auto loadAudioData(const std::string& file_path) -> AudioData {
|
||||
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
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ void Scoreboard::setCarouselAnimation(Id id, int selected_index, EnterName* ente
|
||||
}
|
||||
|
||||
// ===== 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;
|
||||
}
|
||||
|
||||
@@ -755,7 +755,7 @@ void Scoreboard::renderCarousel(size_t panel_index, int center_x, int y) {
|
||||
}
|
||||
|
||||
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)
|
||||
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) ---
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
const float DISTANCE_FROM_CENTER = diff;
|
||||
|
||||
|
||||
@@ -285,6 +285,30 @@ void Text::writeCentered(int x, int y, const std::string& text, int kerning, int
|
||||
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
|
||||
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);
|
||||
@@ -297,11 +321,7 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerni
|
||||
}
|
||||
|
||||
if (SHADOWED) {
|
||||
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);
|
||||
}
|
||||
renderShadow(x, y, text, shadow_color, kerning, length, shadow_distance);
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
// Método tradicional para stroke sólido
|
||||
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, shadow_color, kerning, length);
|
||||
} else {
|
||||
writeColored(x + dx, y + dy, text, shadow_color, kerning, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
renderSolidStroke(x, y, text, shadow_color, kerning, length, shadow_distance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ class Text {
|
||||
// --- 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 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:
|
||||
// --- Objetos y punteros ---
|
||||
|
||||
Reference in New Issue
Block a user