This commit is contained in:
2025-10-27 18:35:53 +01:00
parent b1dca32a5b
commit 3179a08dac
63 changed files with 686 additions and 693 deletions

View File

@@ -18,7 +18,7 @@
#include "core/rendering/screen.hpp" // Para Screen
// Carga una paleta desde un archivo .gif
Palette loadPalette(const std::string& file_path) {
auto loadPalette(const std::string& file_path) -> Palette {
// Abrir el archivo en modo binario
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
if (!file.is_open()) {
@@ -51,7 +51,7 @@ Palette loadPalette(const std::string& file_path) {
}
// Carga una paleta desde un archivo .pal
Palette readPalFile(const std::string& file_path) {
auto readPalFile(const std::string& file_path) -> Palette {
Palette palette{};
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
@@ -107,11 +107,11 @@ Surface::Surface(const std::string& file_path)
}
// Carga una superficie desde un archivo
SurfaceData Surface::loadSurface(const std::string& file_path) {
auto Surface::loadSurface(const std::string& file_path) -> SurfaceData {
// Abrir el archivo usando std::ifstream para manejo automático del recurso
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
if (!file.is_open()) {
std::cerr << "Error opening file: " << file_path << std::endl;
std::cerr << "Error opening file: " << file_path << '\n';
throw std::runtime_error("Error opening file");
}
@@ -122,7 +122,7 @@ SurfaceData Surface::loadSurface(const std::string& file_path) {
// Leer el contenido del archivo en un buffer
std::vector<Uint8> buffer(size);
if (!file.read(reinterpret_cast<char*>(buffer.data()), size)) {
std::cerr << "Error reading file: " << file_path << std::endl;
std::cerr << "Error reading file: " << file_path << '\n';
throw std::runtime_error("Error reading file");
}
@@ -131,7 +131,7 @@ SurfaceData Surface::loadSurface(const std::string& file_path) {
Uint16 h = 0;
std::vector<Uint8> raw_pixels = GIF::Gif::loadGif(buffer.data(), w, h);
if (raw_pixels.empty()) {
std::cerr << "Error loading GIF from file: " << file_path << std::endl;
std::cerr << "Error loading GIF from file: " << file_path << '\n';
throw std::runtime_error("Error loading GIF");
}
@@ -143,7 +143,7 @@ SurfaceData Surface::loadSurface(const std::string& file_path) {
// Crear y devolver directamente el objeto SurfaceData
printWithDots("Surface : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
return SurfaceData(w, h, pixels);
return {static_cast<float>(w), static_cast<float>(h), pixels};
}
// Carga una paleta desde un archivo
@@ -179,7 +179,7 @@ void Surface::putPixel(int x, int y, Uint8 color) {
}
// Obtiene el color de un pixel de la surface_data
Uint8 Surface::getPixel(int x, int y) { return surface_data_->data.get()[x + (y * static_cast<int>(surface_data_->width))]; }
auto Surface::getPixel(int x, int y) -> Uint8 { return surface_data_->data.get()[x + (y * static_cast<int>(surface_data_->width))]; }
// Dibuja un rectangulo relleno
void Surface::fillRect(const SDL_FRect* rect, Uint8 color) {
@@ -527,7 +527,7 @@ void Surface::copyToTexture(SDL_Renderer* renderer, SDL_Texture* texture, SDL_FR
}
// Realiza un efecto de fundido en la paleta principal
bool Surface::fadePalette() {
auto Surface::fadePalette() -> bool {
// Verificar que el tamaño mínimo de palette_ sea adecuado
static constexpr int PALETTE_SIZE = 19;
if (sizeof(palette_) / sizeof(palette_[0]) < PALETTE_SIZE) {
@@ -547,7 +547,7 @@ bool Surface::fadePalette() {
}
// Realiza un efecto de fundido en la paleta secundaria
bool Surface::fadeSubPalette(Uint32 delay) {
auto Surface::fadeSubPalette(Uint32 delay) -> bool {
// Variable estática para almacenar el último tick
static Uint32 last_tick_ = 0;