From 5fd987c6a1022576fc30f1fd316e11a472c5e86d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 29 May 2025 12:25:19 +0200 Subject: [PATCH] commit de merda pa llevar la branch --- source/animated_sprite.h | 37 +++++++++++++++---------------- source/asset.h | 48 ++++++++++++++++++++++------------------ source/audio.h | 26 +++++++++++----------- source/background.h | 2 ++ 4 files changed, 60 insertions(+), 53 deletions(-) diff --git a/source/animated_sprite.h b/source/animated_sprite.h index 1837074..4b4d89e 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -7,10 +7,10 @@ #include "moving_sprite.h" -// Declaraciones adelantadas +// Declaración adelantada class Texture; -// === Estructura de Animación === +// Estructura de Animación struct Animation { std::string name; // Nombre de la animación @@ -24,41 +24,40 @@ struct Animation Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {} }; -// === Alias de Tipos === +// Alias de tipo para buffer de animaciones using AnimationsFileBuffer = std::vector; -// === Funciones Globales === -// Carga las animaciones desde un fichero en un vector +// Carga las animaciones desde un fichero en un vector de strings AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path); +// Clase AnimatedSprite: Sprite animado que hereda de MovingSprite class AnimatedSprite : public MovingSprite { public: - // Constructores + // --- Constructores y destructor --- AnimatedSprite(std::shared_ptr texture, const std::string &file_path); AnimatedSprite(std::shared_ptr texture, const AnimationsFileBuffer &animations); explicit AnimatedSprite(std::shared_ptr texture) : MovingSprite(texture) {} - virtual ~AnimatedSprite() override = default; - // === Actualización === + // --- Métodos principales --- void update() override; // Actualiza la animación - // === Control de Animaciones === - void setCurrentAnimation(const std::string &name = "default"); // Establecer por nombre - void setCurrentAnimation(int index = 0); // Establecer por índice - void resetAnimation(); // Reiniciar la animación + // --- Control de animaciones --- + void setCurrentAnimation(const std::string &name = "default"); // Establece la animación por nombre + void setCurrentAnimation(int index = 0); // Establece la animación por índice + void resetAnimation(); // Reinicia la animación actual - // === Consultas === - bool animationIsCompleted(); // Comprobar si ha terminado - int getIndex(const std::string &name); // Obtener índice por nombre + // --- Consultas --- + bool animationIsCompleted(); // Comprueba si la animación ha terminado + int getIndex(const std::string &name); // Obtiene el índice de una animación por nombre protected: - // === Datos de Animación === + // --- Datos de animación --- std::vector animations_; // Vector de animaciones disponibles int current_animation_ = 0; // Índice de la animación activa - // === Métodos Internos === - void animate(); // Calcular el frame actual de la animación - void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Cargar desde buffer + // --- Métodos internos --- + void animate(); // Calcula el frame actual de la animación + void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Carga animaciones desde un buffer }; \ No newline at end of file diff --git a/source/asset.h b/source/asset.h index 82aa810..ce09253 100644 --- a/source/asset.h +++ b/source/asset.h @@ -2,10 +2,9 @@ #include #include - #include "utils.h" -// === Enumeraciones === +// Tipos de recursos gestionados por Asset enum class AssetType : int { BITMAP, @@ -20,30 +19,37 @@ enum class AssetType : int MAX_ASSET_TYPE, }; +// Clase Asset: gestor de recursos (singleton) class Asset { public: - // === Singleton === - static Asset &get() // Obtención de la instancia única (Meyers Singleton) + // Obtención de la instancia única (Meyers Singleton) + static Asset &get() { static Asset instance; return instance; } - // === Inicialización === + // Inicializa el gestor de recursos con la ruta del ejecutable void init(const std::string &executable_path) { executable_path_ = getPath(executable_path); } - // === Gestión de Recursos === - void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); // Añadir recurso - std::string get(const std::string &text) const; // Obtener ruta completa - bool check() const; // Verificar existencia - std::vector getListByType(AssetType type) const; // Lista por tipo + // Añade un recurso a la lista + void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); + + // Obtiene la ruta completa de un recurso a partir de su nombre + std::string get(const std::string &text) const; + + // Verifica la existencia de todos los recursos requeridos + bool check() const; + + // Devuelve una lista de archivos de un tipo concreto + std::vector getListByType(AssetType type) const; private: - // === Estructura Interna === + // Estructura interna para almacenar información de cada recurso struct AssetItem { std::string file; // Ruta del fichero desde la raíz del directorio @@ -54,18 +60,18 @@ private: : file(filePath), type(assetType), required(isRequired) {} }; - // === Variables Internas === + // Variables internas int longest_name_ = 0; // Longitud del nombre más largo - std::vector file_list_; // Lista con todas las rutas + std::vector file_list_; // Lista con todas las rutas de recursos std::string executable_path_; // Ruta del ejecutable - // === Métodos Internos === - bool checkFile(const std::string &path) const; // Verificar si archivo existe - std::string getTypeName(AssetType type) const; // Obtener nombre textual del tipo + // Métodos internos + bool checkFile(const std::string &path) const; // Verifica si un archivo existe + std::string getTypeName(AssetType type) const; // Devuelve el nombre textual del tipo de recurso - // === Patrón Singleton === - Asset() = default; // Constructor privado - ~Asset() = default; // Destructor privado - Asset(const Asset &) = delete; // Evitar copia - Asset &operator=(const Asset &) = delete; // Evitar asignación + // Patrón Singleton: constructor y destructor privados, sin copia ni asignación + Asset() = default; + ~Asset() = default; + Asset(const Asset &) = delete; + Asset &operator=(const Asset &) = delete; }; \ No newline at end of file diff --git a/source/audio.h b/source/audio.h index ab7a209..c9b9675 100644 --- a/source/audio.h +++ b/source/audio.h @@ -2,23 +2,23 @@ #include -#include "audio.h" - +// Clase Audio: gestor de audio (singleton) class Audio { public: // === Singleton === - static Audio &get() // Obtención de la instancia única (Meyers Singleton) + // Obtención de la instancia única (Meyers Singleton) + static Audio &get() { static Audio instance; return instance; } // === Control de Música === - void playMusic(const std::string &name, int loop = -1); // Reproducir en bucle - void pauseMusic(); // Pausar reproducción - void stopMusic(); // Detener completamente - void fadeOutMusic(int milliseconds); // Fundido de salida + void playMusic(const std::string &name, int loop = -1); // Reproducir música en bucle + void pauseMusic(); // Pausar reproducción de música + void stopMusic(); // Detener completamente la música + void fadeOutMusic(int milliseconds); // Fundido de salida de la música // === Control de Sonidos === void playSound(const std::string &name); // Reproducir sonido puntual @@ -27,20 +27,20 @@ public: // === Configuración General === void enable() { enabled_ = true; } // Habilitar audio void disable() { enabled_ = false; } // Deshabilitar audio - void enable(bool value) { enabled_ = value; } // Establecer estado - void toggleEnabled() { enabled_ = !enabled_; } // Alternar estado + void enable(bool value) { enabled_ = value; } // Establecer estado general + void toggleEnabled() { enabled_ = !enabled_; } // Alternar estado general // === Configuración de Sonidos === void enableSound() { sound_enabled_ = true; } // Habilitar sonidos void disableSound() { sound_enabled_ = false; } // Deshabilitar sonidos - void enableSound(bool value) { sound_enabled_ = value; } // Establecer estado - void toggleSound() { sound_enabled_ = !sound_enabled_; } // Alternar estado + void enableSound(bool value) { sound_enabled_ = value; } // Establecer estado de sonidos + void toggleSound() { sound_enabled_ = !sound_enabled_; } // Alternar estado de sonidos // === Configuración de Música === void enableMusic() { music_enabled_ = true; } // Habilitar música void disableMusic() { music_enabled_ = false; } // Deshabilitar música - void enableMusic(bool value) { music_enabled_ = value; } // Establecer estado - void toggleMusic() { music_enabled_ = !music_enabled_; } // Alternar estado + void enableMusic(bool value) { music_enabled_ = value; } // Establecer estado de música + void toggleMusic() { music_enabled_ = !music_enabled_; } // Alternar estado de música // === Control de Volumen === void setSoundVolume(int volume); // Ajustar volumen de efectos diff --git a/source/background.h b/source/background.h index 9248763..a229499 100644 --- a/source/background.h +++ b/source/background.h @@ -6,6 +6,7 @@ #include // Para unique_ptr, shared_ptr #include // Para vector #include "utils.h" // Para Color + class MovingSprite; class Sprite; class Texture; @@ -23,6 +24,7 @@ class Texture; - setColor(Color color) -> Aplica un color de atenuación - setAlpha(int alpha) -> Ajusta la transparencia de la capa de atenuación */ + class Background { public: