Passant std::cout a SDL_Log
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
#include "animated_sprite.h"
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <fstream> // Para basic_ostream, basic_istream, operator<<, basic...
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <sstream> // Para basic_stringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para printWithDots
|
||||
#include <SDL3/SDL_log.h> // Para SDL_LogWarn, SDL_LogCategory, SDL_LogError
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <fstream> // Para basic_istream, basic_ifstream, basic_ios
|
||||
#include <sstream> // Para basic_stringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path)
|
||||
@@ -13,11 +12,11 @@ AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path)
|
||||
std::ifstream file(file_path);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
}
|
||||
|
||||
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Animation file loaded: %s", file_path.c_str());
|
||||
|
||||
std::vector<std::string> buffer;
|
||||
std::string line;
|
||||
@@ -52,7 +51,7 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const Animation
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
// Obtiene el índice de la animación a partir del nombre
|
||||
int AnimatedSprite::getIndex(const std::string &name)
|
||||
{
|
||||
auto index = -1;
|
||||
@@ -65,7 +64,7 @@ int AnimatedSprite::getIndex(const std::string &name)
|
||||
return index;
|
||||
}
|
||||
}
|
||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "** Warning: could not find \"%s\" animation", name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -169,7 +168,7 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
|
||||
// Parsea el fichero para buscar variables y valores
|
||||
if (line != "[animation]")
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
// Encuentra la posición del carácter '='
|
||||
size_t pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
@@ -182,7 +181,7 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
|
||||
else if (key == "frame_height")
|
||||
frame_height = value;
|
||||
else
|
||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: unknown parameter %s", key.c_str());
|
||||
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
const int w = texture_->getWidth() / frame_width;
|
||||
@@ -191,7 +190,7 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
|
||||
}
|
||||
}
|
||||
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
// Si la línea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
Animation animation;
|
||||
@@ -220,7 +219,7 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
|
||||
SDL_FRect rect = {0, 0, frame_width, frame_height};
|
||||
while (getline(ss, tmp, ','))
|
||||
{
|
||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||
// Comprueba que el tile no sea mayor que el máximo índice permitido
|
||||
const int num_tile = std::stoi(tmp);
|
||||
if (num_tile <= max_tiles)
|
||||
{
|
||||
@@ -230,9 +229,8 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
std::cout << "Warning: unknown parameter " << key << std::endl;
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: unknown parameter %s", key.c_str());
|
||||
}
|
||||
} while (line != "[/animation]");
|
||||
|
||||
@@ -240,7 +238,7 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
|
||||
animations_.emplace_back(animation);
|
||||
}
|
||||
|
||||
// Una vez procesada la linea, aumenta el indice para pasar a la siguiente
|
||||
// Una vez procesada la línea, aumenta el índice para pasar a la siguiente
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user