diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index 8dbbebd..9140911 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -56,12 +56,6 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr texture) : MovingSprite(texture), current_animation_(0) {} -// Destructor -AnimatedSprite::~AnimatedSprite() -{ - animations_.clear(); -} - // Obtiene el indice de la animación a partir del nombre int AnimatedSprite::getIndex(const std::string &name) { @@ -260,8 +254,8 @@ std::vector AnimatedSprite::loadFromFile(const std::string &file_path { // Inicializa variables std::vector animations; - auto frame_width = 0; - auto frame_height = 0; + auto frame_width = 1; + auto frame_height = 1; std::ifstream file(file_path); std::string line; @@ -273,8 +267,8 @@ std::vector AnimatedSprite::loadFromFile(const std::string &file_path std::cout << "Animation loaded: " << getFileName(file_path) << std::endl; while (std::getline(file, line)) { - auto max_tiles = 0; - auto frames_per_row = 0; + auto max_tiles = 1; + auto frames_per_row = 1; // Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación if (line == "[animation]") { @@ -333,20 +327,15 @@ std::vector AnimatedSprite::loadFromFile(const std::string &file_path } // En caso contrario se parsea el fichero para buscar las variables y los valores - else + if (line != "[animation]") { // Encuentra la posición del caracter '=' - int pos = line.find("="); + size_t pos = line.find("="); // Procesa las dos subcadenas - if (pos != (int)line.npos) + if (pos != line.npos) { - if (line.substr(0, pos) == "frames_per_row") - { - frames_per_row = std::stoi(line.substr(pos + 1, line.length())); - } - - else if (line.substr(0, pos) == "frame_width") + if (line.substr(0, pos) == "frame_width") { frame_width = std::stoi(line.substr(pos + 1, line.length())); } @@ -358,21 +347,14 @@ std::vector AnimatedSprite::loadFromFile(const std::string &file_path else { - std::cout << "Warning: file " << getFileName(file_path).c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; + std::cout << "Warning: file " << getFileName(file_path) << "\n, unknown parameter \"" << line.substr(0, pos) << "\"" << std::endl; } - // Normaliza valores - if (frames_per_row == 0 && frame_width > 0) - { - frames_per_row = texture_->getWidth() / frame_width; - } + frames_per_row = texture_->getWidth() / frame_width; - if (max_tiles == 0 && frame_width > 0 && frame_height > 0) - { - const auto w = texture_->getWidth() / frame_width; - const auto h = texture_->getHeight() / frame_height; - max_tiles = w * h; - } + const auto w = texture_->getWidth() / frame_width; + const auto h = texture_->getHeight() / frame_height; + max_tiles = w * h; } } } diff --git a/source/animated_sprite.h b/source/animated_sprite.h index 855177e..3b55a51 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -49,7 +49,7 @@ public: explicit AnimatedSprite(std::shared_ptr texture); // Destructor - virtual ~AnimatedSprite(); + virtual ~AnimatedSprite() = default; // Actualiza las variables del objeto void update() override;