intro: clang-tidy readability-function-cognitive-complexity

This commit is contained in:
2025-07-21 13:30:40 +02:00
parent ea5cedfd26
commit 532d0f4261
3 changed files with 213 additions and 194 deletions

View File

@@ -1,10 +1,9 @@
#include "balloon_formations.h"
#include <stddef.h> // Para size_t
#include <algorithm> // Para max
#include <array> // Para array
#include <cctype> // Para isdigit
#include <cstddef> // Para size_t
#include <exception> // Para exception
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
#include <map> // Para map, operator==

View File

@@ -54,76 +54,9 @@ void Intro::checkEvents() {
#ifdef DEBUG
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 1) {
static Color color_ = param.intro.bg_color;
switch (event.key.key) {
case SDLK_A:
if (color_.r < 255) {
++color_.r;
}
break;
case SDLK_Z:
if (color_.r > 0) {
--color_.r;
}
break;
case SDLK_S:
if (color_.g < 255) {
++color_.g;
}
break;
case SDLK_X:
if (color_.g > 0) {
--color_.g;
}
break;
case SDLK_D:
if (color_.b < 255) {
++color_.b;
}
break;
case SDLK_C:
if (color_.b > 0) {
--color_.b;
}
break;
case SDLK_F:
if (color_.r < 255) {
++color_.r;
}
if (color_.g < 255) {
++color_.g;
}
if (color_.b < 255) {
++color_.b;
}
break;
case SDLK_V:
if (color_.r > 0) {
--color_.r;
}
if (color_.g > 0) {
--color_.g;
}
if (color_.b > 0) {
--color_.b;
}
break;
default:
break;
}
handleDebugColorKeys(event.key.key, color_);
tiled_bg_->setColor(color_);
std::cout << "#"
<< std::hex << std::setw(2) << std::setfill('0') << (int)color_.r
<< std::setw(2) << std::setfill('0') << (int)color_.g
<< std::setw(2) << std::setfill('0') << (int)color_.b
<< std::endl;
printColorDebugInfo(color_);
}
#endif
GlobalEvents::check(event);
@@ -139,10 +72,32 @@ void Intro::checkInput() {
// Actualiza las escenas de la intro
void Intro::updateScenes() {
switch (scene_) {
case 0: {
case 0:
updateScene0();
break;
case 1:
updateScene1();
break;
case 2:
updateScene2();
break;
case 3:
updateScene3();
break;
case 4:
updateScene4();
break;
case 5:
updateScene5();
break;
default:
break;
}
}
void Intro::updateScene0() {
// Primera imagen - UPV
card_sprites_.at(0)->enable();
shadow_sprites_.at(0)->enable();
enableCardAndShadow(0);
// Primer texto de la primera imagen
if (card_sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished()) {
@@ -151,14 +106,12 @@ void Intro::updateScenes() {
// Segundo texto de la primera imagen
if (texts_.at(0)->hasFinished() && !texts_.at(1)->hasFinished()) {
texts_.at(0)->setEnabled(false);
texts_.at(1)->setEnabled(true);
switchText(0, 1);
}
// Tercer texto de la primera imagen
if (texts_.at(1)->hasFinished() && !texts_.at(2)->hasFinished()) {
texts_.at(1)->setEnabled(false);
texts_.at(2)->setEnabled(true);
switchText(1, 2);
}
// Fin de la primera escena
@@ -166,13 +119,11 @@ void Intro::updateScenes() {
texts_.at(2)->setEnabled(false);
scene_++;
}
break;
}
}
case 1: {
void Intro::updateScene1() {
// Segunda imagen - Máquina
card_sprites_.at(1)->enable();
shadow_sprites_.at(1)->enable();
enableCardAndShadow(1);
// Primer texto de la segunda imagen
if (card_sprites_.at(1)->hasFinished() && !texts_.at(3)->hasFinished()) {
@@ -184,15 +135,12 @@ void Intro::updateScenes() {
texts_.at(3)->setEnabled(false);
scene_++;
}
break;
}
}
case 2: {
void Intro::updateScene2() {
// Tercera imagen junto con primer texto - GRITO
if (!texts_.at(4)->hasFinished()) {
card_sprites_.at(2)->enable();
shadow_sprites_.at(2)->enable();
enableCardAndShadow(2);
texts_.at(4)->setEnabled(true);
}
@@ -201,13 +149,11 @@ void Intro::updateScenes() {
texts_.at(4)->setEnabled(false);
scene_++;
}
break;
}
}
case 3: {
void Intro::updateScene3() {
// Cuarta imagen junto con primer texto - Reflexión
card_sprites_.at(3)->enable();
shadow_sprites_.at(3)->enable();
enableCardAndShadow(3);
if (!texts_.at(5)->hasFinished()) {
texts_.at(5)->setEnabled(true);
@@ -215,8 +161,7 @@ void Intro::updateScenes() {
// Segundo texto de la cuarta imagen
if (texts_.at(5)->hasFinished() && !texts_.at(6)->hasFinished()) {
texts_.at(5)->setEnabled(false);
texts_.at(6)->setEnabled(true);
switchText(5, 6);
}
// Fin de la cuarta escena
@@ -224,13 +169,11 @@ void Intro::updateScenes() {
texts_.at(6)->setEnabled(false);
scene_++;
}
break;
}
}
case 4: {
void Intro::updateScene4() {
// Quinta imagen - Patada
card_sprites_.at(4)->enable();
shadow_sprites_.at(4)->enable();
enableCardAndShadow(4);
// Primer texto de la quinta imagen
if (!texts_.at(7)->hasFinished()) {
@@ -242,13 +185,11 @@ void Intro::updateScenes() {
texts_.at(7)->setEnabled(false);
scene_++;
}
break;
}
}
case 5: {
void Intro::updateScene5() {
// Sexta imagen junto con texto - Globos de café
card_sprites_.at(5)->enable();
shadow_sprites_.at(5)->enable();
enableCardAndShadow(5);
if (!texts_.at(8)->hasFinished()) {
texts_.at(8)->setEnabled(true);
@@ -264,12 +205,17 @@ void Intro::updateScenes() {
state_ = IntroState::POST;
state_start_time_ = SDL_GetTicks();
}
break;
}
}
default:
break;
}
// Helper methods to reduce code duplication
void Intro::enableCardAndShadow(int index) {
card_sprites_.at(index)->enable();
shadow_sprites_.at(index)->enable();
}
void Intro::switchText(int fromIndex, int toIndex) {
texts_.at(fromIndex)->setEnabled(false);
texts_.at(toIndex)->setEnabled(true);
}
// Actualiza las variables del objeto
@@ -589,3 +535,59 @@ void Intro::renderTextRect() {
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), param.intro.shadow_color.r, param.intro.shadow_color.g, param.intro.shadow_color.b, param.intro.shadow_color.a);
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
}
#ifdef DEBUG
// Helper functions for color adjustment
void Intro::adjustColorComponent(uint8_t &component, bool increase) {
if (increase && component < 255) {
++component;
} else if (!increase && component > 0) {
--component;
}
}
void Intro::adjustAllColorComponents(Color &color, bool increase) {
adjustColorComponent(color.r, increase);
adjustColorComponent(color.g, increase);
adjustColorComponent(color.b, increase);
}
void Intro::handleDebugColorKeys(SDL_Keycode key, Color &color) {
switch (key) {
case SDLK_A:
adjustColorComponent(color.r, true);
break;
case SDLK_Z:
adjustColorComponent(color.r, false);
break;
case SDLK_S:
adjustColorComponent(color.g, true);
break;
case SDLK_X:
adjustColorComponent(color.g, false);
break;
case SDLK_D:
adjustColorComponent(color.b, true);
break;
case SDLK_C:
adjustColorComponent(color.b, false);
break;
case SDLK_F:
adjustAllColorComponents(color, true);
break;
case SDLK_V:
adjustAllColorComponents(color, false);
break;
default:
break;
}
}
void Intro::printColorDebugInfo(const Color &color) {
std::cout << "#"
<< std::hex << std::setw(2) << std::setfill('0') << (int)color.r
<< std::setw(2) << std::setfill('0') << (int)color.g
<< std::setw(2) << std::setfill('0') << (int)color.b
<< std::endl;
}
#endif

View File

@@ -69,4 +69,22 @@ class Intro {
void renderTexts(); // Dibuja los textos
static void renderTextRect(); // Dibuja el rectangulo de fondo del texto;
void updatePostState(); // Actualiza el estado POST
#ifdef DEBUG
void adjustColorComponent(uint8_t& component, bool increase);
void adjustAllColorComponents(Color& color, bool increase);
void handleDebugColorKeys(SDL_Keycode key, Color& color);
void printColorDebugInfo(const Color& color);
#endif
// --- Métodos para manejar cada escena individualmente ---
void updateScene0();
void updateScene1();
void updateScene2();
void updateScene3();
void updateScene4();
void updateScene5();
// --- Métodos auxiliares para reducir duplicación de código ---
void enableCardAndShadow(int index);
void switchText(int fromIndex, int toIndex);
};