revisió de capçaleres

This commit is contained in:
2025-05-29 09:58:23 +02:00
parent 677e4d465d
commit 0fc8224ef8
45 changed files with 1870 additions and 2684 deletions

View File

@@ -4,173 +4,126 @@
#include <string> // Para string
#include <vector> // Para vector
#include "animated_sprite.h" // Para AnimationsFileBuffer
#include "text.h" // Para TextFile
#include "text.h" // Para TextFile, Text
#include "texture.h" // Para Texture
#include "utils.h" // Para DemoData
struct JA_Music_t;
struct JA_Sound_t;
// Estructura para almacenar ficheros de sonido y su nombre
// --- Estructuras para recursos individuales ---
// Sonido
struct ResourceSound
{
std::string name; // Nombre del sonido
JA_Sound_t *sound; // Objeto con el sonido
// Constructor
ResourceSound(const std::string &name, JA_Sound_t *sound)
: name(name), sound(sound) {}
};
// Estructura para almacenar ficheros musicales y su nombre
// Música
struct ResourceMusic
{
std::string name; // Nombre de la musica
std::string name; // Nombre de la música
JA_Music_t *music; // Objeto con la música
// Constructor
ResourceMusic(const std::string &name, JA_Music_t *music)
: name(name), music(music) {}
};
// Estructura para almacenar objetos Texture y su nombre
// Textura
struct ResourceTexture
{
std::string name; // Nombre de la textura
std::shared_ptr<Texture> texture; // Objeto con la textura
// Constructor
ResourceTexture(const std::string &name, std::shared_ptr<Texture> texture)
: name(name), texture(texture) {}
};
// Estructura para almacenar ficheros TextFile y su nombre
// Fichero de texto (fuente)
struct ResourceTextFile
{
std::string name; // Nombre del fichero
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
// Constructor
ResourceTextFile(const std::string &name, std::shared_ptr<TextFile> text_file)
: name(name), text_file(text_file) {}
};
// Estructura para almacenar objetos Text y su nombre
// Objeto de texto
struct ResourceText
{
std::string name; // Nombre del objeto
std::shared_ptr<Text> text; // Objeto
// Constructor
ResourceText(const std::string &name, std::shared_ptr<Text> text)
: name(name), text(text) {}
};
// Estructura para almacenar ficheros animaciones y su nombre
// Animación
struct ResourceAnimation
{
std::string name; // Nombre del fichero
AnimationsFileBuffer animation; // Objeto con las animaciones
// Constructor
ResourceAnimation(const std::string &name, const AnimationsFileBuffer &animation)
: name(name), animation(animation) {}
};
// --- Clase Resource: gestiona todos los recursos del juego (singleton) ---
class Resource
{
public:
// --- Métodos de singleton ---
static void init(); // Inicializa el objeto Resource
static void destroy(); // Libera el objeto Resource
static Resource *get(); // Obtiene el puntero al objeto Resource
// --- Métodos de acceso a recursos ---
JA_Sound_t *getSound(const std::string &name); // Obtiene el sonido por nombre
JA_Music_t *getMusic(const std::string &name); // Obtiene la música por nombre
std::shared_ptr<Texture> getTexture(const std::string &name); // Obtiene la textura por nombre
std::shared_ptr<TextFile> getTextFile(const std::string &name); // Obtiene el fichero de texto por nombre
std::shared_ptr<Text> getText(const std::string &name); // Obtiene el objeto de texto por nombre
AnimationsFileBuffer &getAnimation(const std::string &name); // Obtiene la animación por nombre
DemoData &getDemoData(int index); // Obtiene los datos de demo por índice
// --- Recarga de recursos ---
void reload(); // Recarga todos los recursos
void reloadTextures(); // Recarga solo las texturas
private:
// [SINGLETON] Objeto resource privado
// --- Singleton ---
static Resource *resource_;
// --- Vectores de recursos ---
std::vector<ResourceSound> sounds_; // Vector con los sonidos
std::vector<ResourceMusic> musics_; // Vector con las musicas
std::vector<ResourceTexture> textures_; // Vector con las musicas
std::vector<ResourceMusic> musics_; // Vector con las músicas
std::vector<ResourceTexture> textures_; // Vector con las texturas
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
std::vector<ResourceText> texts_; // Vector con los objetos de texto
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
std::vector<DemoData> demos_; // Vector con los ficheros de datos para el modo demostración
// Carga los sonidos
void loadSounds();
// --- Métodos internos de carga y gestión ---
void loadSounds(); // Carga los sonidos
void loadMusics(); // Carga las músicas
void loadTextures(); // Carga las texturas
void loadTextFiles(); // Carga los ficheros de texto
void loadAnimations(); // Carga las animaciones
void loadDemoData(); // Carga los datos para el modo demostración
void addPalettes(); // Añade paletas a las texturas
void createTextures(); // Crea las texturas a partir de los datos cargados
void createText(); // Crea los objetos de texto
void clear(); // Vacía todos los vectores de recursos
void load(); // Carga todos los recursos
void clearSounds(); // Vacía el vector de sonidos
void clearMusics(); // Vacía el vector de músicas
// Carga las musicas
void loadMusics();
// Carga las texturas
void loadTextures();
// Carga los ficheros de texto
void loadTextFiles();
// Carga las animaciones
void loadAnimations();
// Carga los datos para el modo demostración
void loadDemoData();
// Añade paletas a las texturas
void addPalettes();
// Crea texturas
void createTextures();
// Crea los objetos de texto
void createText();
// Vacia todos los vectores de recursos
void clear();
// Carga todos los recursos
void load();
// Vacía el vector de sonidos
void clearSounds();
// Vacía el vector de musicas
void clearMusics();
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
// Constructor
Resource();
// Destructor
~Resource() = default;
public:
// [SINGLETON] Crearemos el objeto resource con esta función estática
static void init();
// [SINGLETON] Destruiremos el objeto resource con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
static Resource *get();
// Obtiene el sonido a partir de un nombre
JA_Sound_t *getSound(const std::string &name);
// Obtiene la música a partir de un nombre
JA_Music_t *getMusic(const std::string &name);
// Obtiene la textura a partir de un nombre
std::shared_ptr<Texture> getTexture(const std::string &name);
// Obtiene el fichero de texto a partir de un nombre
std::shared_ptr<TextFile> getTextFile(const std::string &name);
// Obtiene el objeto de texto a partir de un nombre
std::shared_ptr<Text> getText(const std::string &name);
// Obtiene la animación a partir de un nombre
AnimationsFileBuffer &getAnimation(const std::string &name);
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
DemoData &getDemoData(int index);
// Recarga todos los recursos
void reload();
// Recarga las texturas
void reloadTextures();
// --- Constructores y destructor privados (singleton) ---
Resource(); // Constructor privado
~Resource() = default; // Destructor privado
};