clang-tidy readability-function-cognitive-complexity
clang-format
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#include "utils.h" // Para printWithDots
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
auto loadAnimationsFromFile(const std::string &file_path) -> AnimationsFileBuffer {
|
||||
auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffer {
|
||||
std::ifstream file(file_path);
|
||||
if (!file) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||
@@ -34,7 +34,7 @@ auto loadAnimationsFromFile(const std::string &file_path) -> AnimationsFileBuffe
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path)
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string& file_path)
|
||||
: MovingSprite(texture) {
|
||||
// Carga las animaciones
|
||||
if (!file_path.empty()) {
|
||||
@@ -44,7 +44,7 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::stri
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer &animations)
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer& animations)
|
||||
: MovingSprite(texture) {
|
||||
if (!animations.empty()) {
|
||||
loadFromAnimationsFileBuffer(animations);
|
||||
@@ -52,7 +52,7 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const Animation
|
||||
}
|
||||
|
||||
// Obtiene el índice de la animación a partir del nombre
|
||||
auto AnimatedSprite::getIndex(const std::string &name) -> int {
|
||||
auto AnimatedSprite::getIndex(const std::string& name) -> int {
|
||||
auto iterator = animation_indices_.find(name);
|
||||
if (iterator != animation_indices_.end()) {
|
||||
// Si se encuentra la animación en el mapa, devuelve su índice
|
||||
@@ -100,7 +100,7 @@ auto AnimatedSprite::animationIsCompleted() -> bool {
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string &name, bool reset) {
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string& name, bool reset) {
|
||||
const auto NEW_ANIMATION = getIndex(name);
|
||||
if (current_animation_ != NEW_ANIMATION) {
|
||||
const auto OLD_ANIMATION = current_animation_;
|
||||
@@ -149,22 +149,22 @@ void AnimatedSprite::resetAnimation() {
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector de cadenas
|
||||
void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source) {
|
||||
void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer& source) {
|
||||
AnimationConfig config;
|
||||
|
||||
|
||||
size_t index = 0;
|
||||
while (index < source.size()) {
|
||||
const std::string& line = source.at(index);
|
||||
|
||||
|
||||
if (line == "[animation]") {
|
||||
index = processAnimationBlock(source, index, config);
|
||||
} else {
|
||||
processConfigLine(line, config);
|
||||
}
|
||||
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
// Pone un valor por defecto
|
||||
setWidth(config.frame_width);
|
||||
setHeight(config.frame_height);
|
||||
@@ -176,10 +176,10 @@ void AnimatedSprite::processConfigLine(const std::string& line, AnimationConfig&
|
||||
if (pos == std::string::npos) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::string key = line.substr(0, pos);
|
||||
int value = std::stoi(line.substr(pos + 1));
|
||||
|
||||
|
||||
if (key == "frame_width") {
|
||||
config.frame_width = value;
|
||||
updateFrameCalculations(config);
|
||||
@@ -202,25 +202,25 @@ void AnimatedSprite::updateFrameCalculations(AnimationConfig& config) {
|
||||
// Procesa un bloque completo de animación
|
||||
auto AnimatedSprite::processAnimationBlock(const AnimationsFileBuffer& source, size_t start_index, const AnimationConfig& config) -> size_t {
|
||||
Animation animation;
|
||||
size_t index = start_index + 1; // Salta la línea "[animation]"
|
||||
|
||||
size_t index = start_index + 1; // Salta la línea "[animation]"
|
||||
|
||||
while (index < source.size()) {
|
||||
const std::string& line = source.at(index);
|
||||
|
||||
|
||||
if (line == "[/animation]") {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
processAnimationParameter(line, animation, config);
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
// Añade la animación al vector de animaciones
|
||||
animations_.emplace_back(animation);
|
||||
|
||||
|
||||
// Rellena el mapa con el nombre y el nuevo índice
|
||||
animation_indices_[animation.name] = animations_.size() - 1;
|
||||
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -230,10 +230,10 @@ void AnimatedSprite::processAnimationParameter(const std::string& line, Animatio
|
||||
if (pos == std::string::npos) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1);
|
||||
|
||||
|
||||
if (key == "name") {
|
||||
animation.name = value;
|
||||
} else if (key == "speed") {
|
||||
@@ -252,7 +252,7 @@ void AnimatedSprite::parseFramesParameter(const std::string& frames_str, Animati
|
||||
std::stringstream stream(frames_str);
|
||||
std::string tmp;
|
||||
SDL_FRect rect = {0, 0, config.frame_width, config.frame_height};
|
||||
|
||||
|
||||
while (getline(stream, tmp, ',')) {
|
||||
const int NUM_TILE = std::stoi(tmp);
|
||||
if (NUM_TILE <= config.max_tiles) {
|
||||
|
||||
Reference in New Issue
Block a user