137 lines
2.9 KiB
C++
137 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL.h>
|
|
#include "animatedsprite.h"
|
|
#include "asset.h"
|
|
#include "../room.h"
|
|
#include "text.h"
|
|
#include "texture.h"
|
|
#include "utils.h"
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifndef RESOURCE_H
|
|
#define RESOURCE_H
|
|
|
|
struct res_texture_t
|
|
{
|
|
std::string name; // Nombre de la textura
|
|
Texture *texture; // La textura
|
|
};
|
|
|
|
struct res_animation_t
|
|
{
|
|
std::string name; // Nombre de la textura
|
|
animatedSprite_t *animation; // La animación
|
|
};
|
|
|
|
struct res_textOffset_t
|
|
{
|
|
std::string name; // Nombre del offset
|
|
textFile_t *textFile; // Los offsets de la fuente
|
|
};
|
|
|
|
struct res_tileMap_t
|
|
{
|
|
std::string name; // Nombre del mapa de tiles
|
|
std::vector<int> *tileMap; // Vector con los indices del mapa de tiles
|
|
};
|
|
|
|
struct res_room_t
|
|
{
|
|
std::string name; // Nombre de la habitación
|
|
room_t *room; // Vector con las habitaciones
|
|
};
|
|
|
|
// Clase Resource. Almacena recursos de disco en memoria
|
|
class Resource
|
|
{
|
|
private:
|
|
// Objetos y punteros
|
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
|
options_t *options; // Puntero a las opciones del juego
|
|
|
|
// Variables
|
|
std::vector<res_texture_t> textures;
|
|
std::vector<res_animation_t> animations;
|
|
std::vector<res_textOffset_t> offsets;
|
|
std::vector<res_tileMap_t> tileMaps;
|
|
std::vector<res_room_t> rooms;
|
|
|
|
public:
|
|
// Constructor
|
|
Resource(SDL_Renderer *renderer, Asset *asset, options_t *options);
|
|
|
|
// Carga las texturas de una lista
|
|
void loadTextures(std::vector<std::string> list);
|
|
|
|
// Vuelve a cargar las texturas
|
|
void reLoadTextures();
|
|
|
|
// Carga las animaciones desde una lista
|
|
void loadAnimations(std::vector<std::string> list);
|
|
|
|
// Vuelve a cargar las animaciones
|
|
void reLoadAnimations();
|
|
|
|
// Carga los offsets desde una lista
|
|
void loadOffsets(std::vector<std::string> list);
|
|
|
|
// Vuelve a cargar los offsets
|
|
void reLoadOffsets();
|
|
|
|
// Carga los mapas de tiles desde una lista
|
|
void loadTileMaps(std::vector<std::string> list);
|
|
|
|
// Vuelve a cargar los mapas de tiles
|
|
void reLoadTileMaps();
|
|
|
|
// Carga las habitaciones desde una lista
|
|
void loadRooms(std::vector<std::string> list);
|
|
|
|
// Vuelve a cargar las habitaciones
|
|
void reLoadRooms();
|
|
|
|
// Vuelve a cargar todos los recursos
|
|
void reLoad();
|
|
|
|
// Libera las texturas
|
|
void freeTextures();
|
|
|
|
// Libera las animaciones
|
|
void freeAnimations();
|
|
|
|
// Libera los offsets
|
|
void freeOffsets();
|
|
|
|
// Libera los mapas de tiles
|
|
void freeTileMaps();
|
|
|
|
// Libera las habitaciones
|
|
void freeRooms();
|
|
|
|
// Libera todos los recursos
|
|
void free();
|
|
|
|
// Obtiene una textura
|
|
Texture *getTexture(std::string name);
|
|
|
|
// Obtiene una animación
|
|
animatedSprite_t *getAnimation(std::string name);
|
|
|
|
// Obtiene un offset
|
|
textFile_t *getOffset(std::string name);
|
|
|
|
// Obtiene un mapa de tiles
|
|
std::vector<int> *getTileMap(std::string name);
|
|
|
|
// Obtiene una habitacion
|
|
room_t *getRoom(std::string name);
|
|
|
|
// Obtiene todas las habitaciones
|
|
std::vector<res_room_t> *getAllRooms();
|
|
};
|
|
|
|
#endif
|