intro: clang-tidy readability-function-cognitive-complexity
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
#include "balloon_formations.h"
|
#include "balloon_formations.h"
|
||||||
|
|
||||||
#include <stddef.h> // Para size_t
|
|
||||||
|
|
||||||
#include <algorithm> // Para max
|
#include <algorithm> // Para max
|
||||||
#include <array> // Para array
|
#include <array> // Para array
|
||||||
#include <cctype> // Para isdigit
|
#include <cctype> // Para isdigit
|
||||||
|
#include <cstddef> // Para size_t
|
||||||
#include <exception> // Para exception
|
#include <exception> // Para exception
|
||||||
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
|
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
|
||||||
#include <map> // Para map, operator==
|
#include <map> // Para map, operator==
|
||||||
|
|||||||
@@ -54,76 +54,9 @@ void Intro::checkEvents() {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 1) {
|
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 1) {
|
||||||
static Color color_ = param.intro.bg_color;
|
static Color color_ = param.intro.bg_color;
|
||||||
switch (event.key.key) {
|
handleDebugColorKeys(event.key.key, color_);
|
||||||
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;
|
|
||||||
}
|
|
||||||
tiled_bg_->setColor(color_);
|
tiled_bg_->setColor(color_);
|
||||||
std::cout << "#"
|
printColorDebugInfo(color_);
|
||||||
<< 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
|
#endif
|
||||||
GlobalEvents::check(event);
|
GlobalEvents::check(event);
|
||||||
@@ -139,10 +72,32 @@ void Intro::checkInput() {
|
|||||||
// Actualiza las escenas de la intro
|
// Actualiza las escenas de la intro
|
||||||
void Intro::updateScenes() {
|
void Intro::updateScenes() {
|
||||||
switch (scene_) {
|
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
|
// Primera imagen - UPV
|
||||||
card_sprites_.at(0)->enable();
|
enableCardAndShadow(0);
|
||||||
shadow_sprites_.at(0)->enable();
|
|
||||||
|
|
||||||
// Primer texto de la primera imagen
|
// Primer texto de la primera imagen
|
||||||
if (card_sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished()) {
|
if (card_sprites_.at(0)->hasFinished() && !texts_.at(0)->hasFinished()) {
|
||||||
@@ -151,14 +106,12 @@ void Intro::updateScenes() {
|
|||||||
|
|
||||||
// Segundo texto de la primera imagen
|
// Segundo texto de la primera imagen
|
||||||
if (texts_.at(0)->hasFinished() && !texts_.at(1)->hasFinished()) {
|
if (texts_.at(0)->hasFinished() && !texts_.at(1)->hasFinished()) {
|
||||||
texts_.at(0)->setEnabled(false);
|
switchText(0, 1);
|
||||||
texts_.at(1)->setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tercer texto de la primera imagen
|
// Tercer texto de la primera imagen
|
||||||
if (texts_.at(1)->hasFinished() && !texts_.at(2)->hasFinished()) {
|
if (texts_.at(1)->hasFinished() && !texts_.at(2)->hasFinished()) {
|
||||||
texts_.at(1)->setEnabled(false);
|
switchText(1, 2);
|
||||||
texts_.at(2)->setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fin de la primera escena
|
// Fin de la primera escena
|
||||||
@@ -166,13 +119,11 @@ void Intro::updateScenes() {
|
|||||||
texts_.at(2)->setEnabled(false);
|
texts_.at(2)->setEnabled(false);
|
||||||
scene_++;
|
scene_++;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case 1: {
|
void Intro::updateScene1() {
|
||||||
// Segunda imagen - Máquina
|
// Segunda imagen - Máquina
|
||||||
card_sprites_.at(1)->enable();
|
enableCardAndShadow(1);
|
||||||
shadow_sprites_.at(1)->enable();
|
|
||||||
|
|
||||||
// Primer texto de la segunda imagen
|
// Primer texto de la segunda imagen
|
||||||
if (card_sprites_.at(1)->hasFinished() && !texts_.at(3)->hasFinished()) {
|
if (card_sprites_.at(1)->hasFinished() && !texts_.at(3)->hasFinished()) {
|
||||||
@@ -184,15 +135,12 @@ void Intro::updateScenes() {
|
|||||||
texts_.at(3)->setEnabled(false);
|
texts_.at(3)->setEnabled(false);
|
||||||
scene_++;
|
scene_++;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case 2: {
|
void Intro::updateScene2() {
|
||||||
// Tercera imagen junto con primer texto - GRITO
|
// Tercera imagen junto con primer texto - GRITO
|
||||||
if (!texts_.at(4)->hasFinished()) {
|
if (!texts_.at(4)->hasFinished()) {
|
||||||
card_sprites_.at(2)->enable();
|
enableCardAndShadow(2);
|
||||||
shadow_sprites_.at(2)->enable();
|
|
||||||
|
|
||||||
texts_.at(4)->setEnabled(true);
|
texts_.at(4)->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,13 +149,11 @@ void Intro::updateScenes() {
|
|||||||
texts_.at(4)->setEnabled(false);
|
texts_.at(4)->setEnabled(false);
|
||||||
scene_++;
|
scene_++;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case 3: {
|
void Intro::updateScene3() {
|
||||||
// Cuarta imagen junto con primer texto - Reflexión
|
// Cuarta imagen junto con primer texto - Reflexión
|
||||||
card_sprites_.at(3)->enable();
|
enableCardAndShadow(3);
|
||||||
shadow_sprites_.at(3)->enable();
|
|
||||||
|
|
||||||
if (!texts_.at(5)->hasFinished()) {
|
if (!texts_.at(5)->hasFinished()) {
|
||||||
texts_.at(5)->setEnabled(true);
|
texts_.at(5)->setEnabled(true);
|
||||||
@@ -215,8 +161,7 @@ void Intro::updateScenes() {
|
|||||||
|
|
||||||
// Segundo texto de la cuarta imagen
|
// Segundo texto de la cuarta imagen
|
||||||
if (texts_.at(5)->hasFinished() && !texts_.at(6)->hasFinished()) {
|
if (texts_.at(5)->hasFinished() && !texts_.at(6)->hasFinished()) {
|
||||||
texts_.at(5)->setEnabled(false);
|
switchText(5, 6);
|
||||||
texts_.at(6)->setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fin de la cuarta escena
|
// Fin de la cuarta escena
|
||||||
@@ -224,13 +169,11 @@ void Intro::updateScenes() {
|
|||||||
texts_.at(6)->setEnabled(false);
|
texts_.at(6)->setEnabled(false);
|
||||||
scene_++;
|
scene_++;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case 4: {
|
void Intro::updateScene4() {
|
||||||
// Quinta imagen - Patada
|
// Quinta imagen - Patada
|
||||||
card_sprites_.at(4)->enable();
|
enableCardAndShadow(4);
|
||||||
shadow_sprites_.at(4)->enable();
|
|
||||||
|
|
||||||
// Primer texto de la quinta imagen
|
// Primer texto de la quinta imagen
|
||||||
if (!texts_.at(7)->hasFinished()) {
|
if (!texts_.at(7)->hasFinished()) {
|
||||||
@@ -242,13 +185,11 @@ void Intro::updateScenes() {
|
|||||||
texts_.at(7)->setEnabled(false);
|
texts_.at(7)->setEnabled(false);
|
||||||
scene_++;
|
scene_++;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case 5: {
|
void Intro::updateScene5() {
|
||||||
// Sexta imagen junto con texto - Globos de café
|
// Sexta imagen junto con texto - Globos de café
|
||||||
card_sprites_.at(5)->enable();
|
enableCardAndShadow(5);
|
||||||
shadow_sprites_.at(5)->enable();
|
|
||||||
|
|
||||||
if (!texts_.at(8)->hasFinished()) {
|
if (!texts_.at(8)->hasFinished()) {
|
||||||
texts_.at(8)->setEnabled(true);
|
texts_.at(8)->setEnabled(true);
|
||||||
@@ -264,12 +205,17 @@ void Intro::updateScenes() {
|
|||||||
state_ = IntroState::POST;
|
state_ = IntroState::POST;
|
||||||
state_start_time_ = SDL_GetTicks();
|
state_start_time_ = SDL_GetTicks();
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
// Helper methods to reduce code duplication
|
||||||
break;
|
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
|
// 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_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_);
|
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
|
||||||
@@ -69,4 +69,22 @@ class Intro {
|
|||||||
void renderTexts(); // Dibuja los textos
|
void renderTexts(); // Dibuja los textos
|
||||||
static void renderTextRect(); // Dibuja el rectangulo de fondo del texto;
|
static void renderTextRect(); // Dibuja el rectangulo de fondo del texto;
|
||||||
void updatePostState(); // Actualiza el estado POST
|
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);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user