forked from jaildesigner-jailgames/jaildoctors_dilemma
migrat Assets a la ultima versió (fitxers no hardcoded)
This commit is contained in:
@@ -1,79 +1,205 @@
|
||||
#include "core/resources/asset.hpp"
|
||||
|
||||
#include <algorithm> // Para find_if, max
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream, endl
|
||||
#include <iostream> // Para cout
|
||||
#include <string> // Para allocator, char_traits, string, operator+, oper...
|
||||
#include <SDL3/SDL.h> // Para SDL_LogWarn, SDL_LogCategory, SDL_LogError
|
||||
|
||||
#include <algorithm> // Para sort
|
||||
#include <cstddef> // Para size_t
|
||||
#include <exception> // Para exception
|
||||
#include <filesystem> // Para exists, path
|
||||
#include <fstream> // Para ifstream, istringstream
|
||||
#include <iostream> // Para cout
|
||||
#include <sstream> // Para istringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
|
||||
#include "utils/utils.hpp" // Para getFileName, printWithDots
|
||||
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Asset* Asset::asset = nullptr;
|
||||
// Singleton
|
||||
Asset* Asset::instance = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto asset con esta función estática
|
||||
void Asset::init(const std::string& executable_path) {
|
||||
Asset::asset = new Asset(executable_path);
|
||||
Asset::instance = new Asset(executable_path);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto asset con esta función estática
|
||||
void Asset::destroy() {
|
||||
delete Asset::asset;
|
||||
delete Asset::instance;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto asset y podemos trabajar con él
|
||||
auto Asset::get() -> Asset* {
|
||||
return Asset::asset;
|
||||
return Asset::instance;
|
||||
}
|
||||
|
||||
// Añade un elemento al mapa (función auxiliar)
|
||||
void Asset::addToMap(const std::string& file_path, Type type, bool required, bool absolute) {
|
||||
std::string full_path = absolute ? file_path : executable_path_ + file_path;
|
||||
std::string filename = getFileName(full_path);
|
||||
|
||||
// Verificar si ya existe el archivo
|
||||
if (file_list_.find(filename) != file_list_.end()) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Warning: Asset '%s' already exists, overwriting",
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
file_list_.emplace(filename, Item{std::move(full_path), type, required});
|
||||
}
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void Asset::add(const std::string& file, AssetType type, bool required, bool absolute) {
|
||||
file_list_.emplace_back(absolute ? file : executable_path_ + file, type, required);
|
||||
longest_name_ = std::max(longest_name_, static_cast<int>(file_list_.back().file.size()));
|
||||
void Asset::add(const std::string& file_path, Type type, bool required, bool absolute) {
|
||||
addToMap(file_path, type, required, absolute);
|
||||
}
|
||||
|
||||
// Devuelve la ruta completa a un fichero a partir de una cadena
|
||||
auto Asset::get(const std::string& text) const -> std::string {
|
||||
auto it = std::ranges::find_if(file_list_, [&text](const auto& f) {
|
||||
return getFileName(f.file) == text;
|
||||
});
|
||||
|
||||
if (it != file_list_.end()) {
|
||||
return it->file;
|
||||
// Carga recursos desde un archivo de configuración con soporte para variables
|
||||
void Asset::loadFromFile(const std::string& config_file_path, const std::string& prefix, const std::string& system_folder) {
|
||||
std::ifstream file(config_file_path);
|
||||
if (!file.is_open()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Error: Cannot open config file: %s",
|
||||
config_file_path.c_str());
|
||||
return;
|
||||
}
|
||||
std::cout << "Warning: file " << text << " not found" << '\n';
|
||||
|
||||
std::string line;
|
||||
int line_number = 0;
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
++line_number;
|
||||
|
||||
// Limpiar espacios en blanco al principio y final
|
||||
line.erase(0, line.find_first_not_of(" \t\r"));
|
||||
line.erase(line.find_last_not_of(" \t\r") + 1);
|
||||
|
||||
// Ignorar líneas vacías y comentarios
|
||||
if (line.empty() || line[0] == '#' || line[0] == ';') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Dividir la línea por el separador '|'
|
||||
std::vector<std::string> parts;
|
||||
std::istringstream iss(line);
|
||||
std::string part;
|
||||
|
||||
while (std::getline(iss, part, '|')) {
|
||||
parts.push_back(part);
|
||||
}
|
||||
|
||||
// Verificar que tenemos al menos tipo y ruta
|
||||
if (parts.size() < 2) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Warning: Malformed line %d in config file (insufficient fields)",
|
||||
line_number);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const std::string& type_str = parts[0];
|
||||
std::string path = parts[1];
|
||||
|
||||
// Valores por defecto
|
||||
bool required = true;
|
||||
bool absolute = false;
|
||||
|
||||
// Si hay opciones en el tercer campo, parsearlas
|
||||
if (parts.size() >= 3) {
|
||||
parseOptions(parts[2], required, absolute);
|
||||
}
|
||||
|
||||
// Reemplazar variables en la ruta
|
||||
path = replaceVariables(path, prefix, system_folder);
|
||||
|
||||
// Parsear el tipo de asset
|
||||
Type type = parseAssetType(type_str);
|
||||
|
||||
// Añadir al mapa
|
||||
addToMap(path, type, required, absolute);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Error parsing line %d in config file: %s",
|
||||
line_number,
|
||||
e.what());
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Loaded " << file_list_.size() << " assets from config file" << '\n';
|
||||
file.close();
|
||||
}
|
||||
|
||||
// Devuelve la ruta completa a un fichero (búsqueda O(1))
|
||||
auto Asset::get(const std::string& filename) const -> std::string {
|
||||
auto it = file_list_.find(filename);
|
||||
if (it != file_list_.end()) {
|
||||
return it->second.file;
|
||||
}
|
||||
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: file %s not found", filename.c_str());
|
||||
return "";
|
||||
}
|
||||
|
||||
// Carga datos del archivo
|
||||
auto Asset::loadData(const std::string& filename) const -> std::vector<uint8_t> {
|
||||
auto it = file_list_.find(filename);
|
||||
if (it != file_list_.end()) {
|
||||
std::ifstream file(it->second.file, std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Warning: Could not open file %s for data loading",
|
||||
filename.c_str());
|
||||
return {};
|
||||
}
|
||||
|
||||
// Obtener tamaño del archivo
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
// Leer datos
|
||||
std::vector<uint8_t> data(size);
|
||||
file.read(reinterpret_cast<char*>(data.data()), size);
|
||||
file.close();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: file %s not found for data loading", filename.c_str());
|
||||
return {};
|
||||
}
|
||||
|
||||
// Verifica si un recurso existe
|
||||
auto Asset::exists(const std::string& filename) const -> bool {
|
||||
return file_list_.find(filename) != file_list_.end();
|
||||
}
|
||||
|
||||
// Comprueba que existen todos los elementos
|
||||
auto Asset::check() const -> bool {
|
||||
bool success = true;
|
||||
|
||||
std::cout << "\n** CHECKING FILES" << '\n';
|
||||
|
||||
// std::cout << "Executable path is: " << executable_path_ << std::endl;
|
||||
// std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
|
||||
// Agrupar por tipo para mostrar organizado
|
||||
std::unordered_map<Type, std::vector<const Item*>> by_type;
|
||||
|
||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type) {
|
||||
// Comprueba si hay ficheros de ese tipo
|
||||
bool any = false;
|
||||
|
||||
for (const auto& f : file_list_) {
|
||||
if (f.required && f.type == static_cast<AssetType>(type)) {
|
||||
any = true;
|
||||
}
|
||||
for (const auto& [filename, item] : file_list_) {
|
||||
if (item.required) {
|
||||
by_type[item.type].push_back(&item);
|
||||
}
|
||||
}
|
||||
|
||||
// Si hay ficheros de ese tipo, comprueba si existen
|
||||
if (any) {
|
||||
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << '\n';
|
||||
// Verificar por tipo
|
||||
for (int type = 0; type < static_cast<int>(Type::SIZE); ++type) {
|
||||
Type asset_type = static_cast<Type>(type);
|
||||
|
||||
for (const auto& f : file_list_) {
|
||||
if (f.required && f.type == static_cast<AssetType>(type)) {
|
||||
success &= checkFile(f.file);
|
||||
if (by_type.find(asset_type) != by_type.end()) {
|
||||
std::cout << "\n>> " << getTypeName(asset_type) << " FILES" << '\n';
|
||||
|
||||
bool type_success = true;
|
||||
for (const auto* item : by_type[asset_type]) {
|
||||
if (!checkFile(item->file)) {
|
||||
success = false;
|
||||
type_success = false;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
|
||||
if (type_success) {
|
||||
std::cout << " All files are OK." << '\n';
|
||||
}
|
||||
}
|
||||
@@ -86,7 +212,7 @@ auto Asset::check() const -> bool {
|
||||
}
|
||||
|
||||
// Comprueba que existe un fichero
|
||||
auto Asset::checkFile(const std::string& path) -> bool {
|
||||
auto Asset::checkFile(const std::string& path) const -> bool {
|
||||
std::ifstream file(path);
|
||||
bool success = file.good();
|
||||
file.close();
|
||||
@@ -98,60 +224,120 @@ auto Asset::checkFile(const std::string& path) -> bool {
|
||||
return success;
|
||||
}
|
||||
|
||||
// Parsea string a Type
|
||||
auto Asset::parseAssetType(const std::string& type_str) -> Type {
|
||||
if (type_str == "DATA") {
|
||||
return Type::DATA;
|
||||
}
|
||||
if (type_str == "BITMAP") {
|
||||
return Type::BITMAP;
|
||||
}
|
||||
if (type_str == "ANIMATION") {
|
||||
return Type::ANIMATION;
|
||||
}
|
||||
if (type_str == "MUSIC") {
|
||||
return Type::MUSIC;
|
||||
}
|
||||
if (type_str == "SOUND") {
|
||||
return Type::SOUND;
|
||||
}
|
||||
if (type_str == "FONT") {
|
||||
return Type::FONT;
|
||||
}
|
||||
if (type_str == "ROOM") {
|
||||
return Type::ROOM;
|
||||
}
|
||||
if (type_str == "TILEMAP") {
|
||||
return Type::TILEMAP;
|
||||
}
|
||||
if (type_str == "PALETTE") {
|
||||
return Type::PALETTE;
|
||||
}
|
||||
|
||||
throw std::runtime_error("Unknown asset type: " + type_str);
|
||||
}
|
||||
|
||||
// Devuelve el nombre del tipo de recurso
|
||||
auto Asset::getTypeName(AssetType type) -> std::string {
|
||||
auto Asset::getTypeName(Type type) -> std::string {
|
||||
switch (type) {
|
||||
case AssetType::DATA:
|
||||
case Type::DATA:
|
||||
return "DATA";
|
||||
break;
|
||||
|
||||
case AssetType::BITMAP:
|
||||
case Type::BITMAP:
|
||||
return "BITMAP";
|
||||
break;
|
||||
|
||||
case AssetType::ANIMATION:
|
||||
case Type::ANIMATION:
|
||||
return "ANIMATION";
|
||||
break;
|
||||
|
||||
case AssetType::MUSIC:
|
||||
case Type::MUSIC:
|
||||
return "MUSIC";
|
||||
break;
|
||||
|
||||
case AssetType::SOUND:
|
||||
case Type::SOUND:
|
||||
return "SOUND";
|
||||
break;
|
||||
|
||||
case AssetType::FONT:
|
||||
case Type::FONT:
|
||||
return "FONT";
|
||||
break;
|
||||
|
||||
case AssetType::ROOM:
|
||||
case Type::ROOM:
|
||||
return "ROOM";
|
||||
break;
|
||||
|
||||
case AssetType::TILEMAP:
|
||||
case Type::TILEMAP:
|
||||
return "TILEMAP";
|
||||
break;
|
||||
|
||||
case AssetType::PALETTE:
|
||||
case Type::PALETTE:
|
||||
return "PALETTE";
|
||||
break;
|
||||
|
||||
default:
|
||||
return "ERROR";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve la lista de recursos de un tipo
|
||||
auto Asset::getListByType(AssetType type) const -> std::vector<std::string> {
|
||||
auto Asset::getListByType(Type type) const -> std::vector<std::string> {
|
||||
std::vector<std::string> list;
|
||||
|
||||
for (const auto& f : file_list_) {
|
||||
if (f.type == type) {
|
||||
list.push_back(f.file);
|
||||
for (const auto& [filename, item] : file_list_) {
|
||||
if (item.type == type) {
|
||||
list.push_back(item.file);
|
||||
}
|
||||
}
|
||||
|
||||
// Ordenar alfabéticamente para garantizar orden consistente
|
||||
std::ranges::sort(list);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
// Reemplaza variables en las rutas
|
||||
auto Asset::replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string {
|
||||
std::string result = path;
|
||||
|
||||
// Reemplazar ${PREFIX}
|
||||
size_t pos = 0;
|
||||
while ((pos = result.find("${PREFIX}", pos)) != std::string::npos) {
|
||||
result.replace(pos, 9, prefix); // 9 = longitud de "${PREFIX}"
|
||||
pos += prefix.length();
|
||||
}
|
||||
|
||||
// Reemplazar ${SYSTEM_FOLDER}
|
||||
pos = 0;
|
||||
while ((pos = result.find("${SYSTEM_FOLDER}", pos)) != std::string::npos) {
|
||||
result.replace(pos, 16, system_folder); // 16 = longitud de "${SYSTEM_FOLDER}"
|
||||
pos += system_folder.length();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Parsea las opciones de una línea de configuración
|
||||
auto Asset::parseOptions(const std::string& options, bool& required, bool& absolute) -> void {
|
||||
if (options.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::istringstream iss(options);
|
||||
std::string option;
|
||||
|
||||
while (std::getline(iss, option, ',')) {
|
||||
// Eliminar espacios
|
||||
option.erase(0, option.find_first_not_of(" \t"));
|
||||
option.erase(option.find_last_not_of(" \t") + 1);
|
||||
|
||||
if (option == "optional") {
|
||||
required = false;
|
||||
} else if (option == "absolute") {
|
||||
absolute = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // para string, basic_string
|
||||
#include <utility>
|
||||
#include <vector> // para vector
|
||||
#include <cstdint> // Para uint8_t
|
||||
#include <string> // Para string
|
||||
#include <unordered_map> // Para unordered_map
|
||||
#include <utility> // Para move
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
enum class AssetType : int {
|
||||
DATA,
|
||||
BITMAP,
|
||||
ANIMATION,
|
||||
MUSIC,
|
||||
SOUND,
|
||||
FONT,
|
||||
ROOM,
|
||||
TILEMAP,
|
||||
PALETTE,
|
||||
MAX_ASSET_TYPE
|
||||
};
|
||||
|
||||
// Clase Asset
|
||||
// --- Clase Asset: gestor optimizado de recursos (singleton) ---
|
||||
class Asset {
|
||||
public:
|
||||
// --- Enums ---
|
||||
enum class Type : int {
|
||||
DATA, // Datos
|
||||
BITMAP, // Imágenes
|
||||
ANIMATION, // Animaciones
|
||||
MUSIC, // Música
|
||||
SOUND, // Sonidos
|
||||
FONT, // Fuentes
|
||||
ROOM, // Datos de habitación (.room)
|
||||
TILEMAP, // Tilemaps (.tmx)
|
||||
PALETTE, // Paletas
|
||||
SIZE, // Tamaño (para iteración)
|
||||
};
|
||||
|
||||
// --- Métodos de singleton ---
|
||||
static void init(const std::string& executable_path);
|
||||
static void destroy();
|
||||
static auto get() -> Asset*;
|
||||
Asset(const Asset&) = delete;
|
||||
auto operator=(const Asset&) -> Asset& = delete;
|
||||
|
||||
// --- Métodos para la gestión de recursos ---
|
||||
void add(const std::string& file_path, Type type, bool required = true, bool absolute = false);
|
||||
void loadFromFile(const std::string& config_file_path, const std::string& prefix = "", const std::string& system_folder = ""); // Con soporte para variables
|
||||
[[nodiscard]] auto get(const std::string& filename) const -> std::string; // Obtiene la ruta completa
|
||||
[[nodiscard]] auto loadData(const std::string& filename) const -> std::vector<uint8_t>; // Carga datos del archivo
|
||||
[[nodiscard]] auto check() const -> bool;
|
||||
[[nodiscard]] auto getListByType(Type type) const -> std::vector<std::string>;
|
||||
[[nodiscard]] auto exists(const std::string& filename) const -> bool; // Verifica si un asset existe
|
||||
|
||||
private:
|
||||
// [SINGLETON] Objeto asset privado para Don Melitón
|
||||
static Asset* asset;
|
||||
// --- Estructuras privadas ---
|
||||
struct Item {
|
||||
std::string file; // Ruta completa del archivo
|
||||
Type type; // Tipo de recurso
|
||||
bool required; // Indica si el archivo es obligatorio
|
||||
|
||||
// Estructura para definir un item
|
||||
struct AssetItem {
|
||||
std::string file; // Ruta del fichero desde la raíz del directorio
|
||||
AssetType type; // Indica el tipo de recurso
|
||||
bool required; // Indica si es un fichero que debe de existir
|
||||
|
||||
// Constructor
|
||||
AssetItem(std::string file_path, AssetType asset_type, bool is_required)
|
||||
: file(std::move(file_path)),
|
||||
Item(std::string path, Type asset_type, bool is_required)
|
||||
: file(std::move(path)),
|
||||
type(asset_type),
|
||||
required(is_required) {}
|
||||
};
|
||||
|
||||
// Variables
|
||||
int longest_name_ = 0; // Contiene la longitud del nombre de fichero mas largo
|
||||
std::vector<AssetItem> file_list_; // Listado con todas las rutas a los ficheros
|
||||
std::string executable_path_; // Ruta al ejecutable
|
||||
// --- Variables internas ---
|
||||
std::unordered_map<std::string, Item> file_list_; // Mapa para búsqueda O(1)
|
||||
std::string executable_path_; // Ruta del ejecutable
|
||||
|
||||
// Comprueba que existe un fichero
|
||||
static auto checkFile(const std::string& path) -> bool;
|
||||
// --- Métodos internos ---
|
||||
[[nodiscard]] auto checkFile(const std::string& path) const -> bool; // Verifica si un archivo existe
|
||||
[[nodiscard]] static auto getTypeName(Type type) -> std::string; // Obtiene el nombre del tipo
|
||||
[[nodiscard]] static auto parseAssetType(const std::string& type_str) -> Type; // Convierte string a tipo
|
||||
void addToMap(const std::string& file_path, Type type, bool required, bool absolute); // Añade archivo al mapa
|
||||
[[nodiscard]] static auto replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string; // Reemplaza variables en la ruta
|
||||
static auto parseOptions(const std::string& options, bool& required, bool& absolute) -> void; // Parsea opciones
|
||||
|
||||
// Devuelve el nombre del tipo de recurso
|
||||
static auto getTypeName(AssetType type) -> std::string;
|
||||
// --- Constructores y destructor privados (singleton) ---
|
||||
explicit Asset(std::string executable_path) // Constructor privado
|
||||
: executable_path_(std::move(executable_path)) {}
|
||||
~Asset() = default; // Destructor privado
|
||||
|
||||
// Constructor
|
||||
explicit Asset(const std::string& executable_path)
|
||||
: executable_path_(getPath(executable_path)) {}
|
||||
|
||||
// Destructor
|
||||
~Asset() = default;
|
||||
|
||||
public:
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void init(const std::string& executable_path);
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static auto get() -> Asset*;
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void add(const std::string& file, AssetType type, bool required = true, bool absolute = false);
|
||||
|
||||
// Devuelve la ruta completa a un fichero a partir de una cadena
|
||||
[[nodiscard]] auto get(const std::string& text) const -> std::string;
|
||||
|
||||
// Comprueba que existen todos los elementos
|
||||
[[nodiscard]] auto check() const -> bool;
|
||||
|
||||
// Devuelve la lista de recursos de un tipo
|
||||
[[nodiscard]] auto getListByType(AssetType type) const -> std::vector<std::string>;
|
||||
};
|
||||
// --- Instancia singleton ---
|
||||
static Asset* instance; // Instancia única de Asset
|
||||
};
|
||||
|
||||
@@ -183,7 +183,7 @@ auto Resource::getRooms() -> std::vector<ResourceRoom>& {
|
||||
// Carga los sonidos
|
||||
void Resource::loadSounds() {
|
||||
std::cout << "\n>> SOUND FILES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::SOUND);
|
||||
sounds_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -197,7 +197,7 @@ void Resource::loadSounds() {
|
||||
// Carga las musicas
|
||||
void Resource::loadMusics() {
|
||||
std::cout << "\n>> MUSIC FILES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::MUSIC);
|
||||
musics_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -211,7 +211,7 @@ void Resource::loadMusics() {
|
||||
// Carga las texturas
|
||||
void Resource::loadSurfaces() {
|
||||
std::cout << "\n>> SURFACES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::BITMAP);
|
||||
surfaces_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -234,7 +234,7 @@ void Resource::loadSurfaces() {
|
||||
// Carga las paletas
|
||||
void Resource::loadPalettes() {
|
||||
std::cout << "\n>> PALETTES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::PALETTE);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::PALETTE);
|
||||
palettes_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -247,7 +247,7 @@ void Resource::loadPalettes() {
|
||||
// Carga los ficheros de texto
|
||||
void Resource::loadTextFiles() {
|
||||
std::cout << "\n>> TEXT FILES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::FONT);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::FONT);
|
||||
text_files_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -260,7 +260,7 @@ void Resource::loadTextFiles() {
|
||||
// Carga las animaciones
|
||||
void Resource::loadAnimations() {
|
||||
std::cout << "\n>> ANIMATIONS" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::ANIMATION);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::ANIMATION);
|
||||
animations_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -273,7 +273,7 @@ void Resource::loadAnimations() {
|
||||
// Carga los mapas de tiles
|
||||
void Resource::loadTileMaps() {
|
||||
std::cout << "\n>> TILE MAPS" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::TILEMAP);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::TILEMAP);
|
||||
tile_maps_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -287,7 +287,7 @@ void Resource::loadTileMaps() {
|
||||
// Carga las habitaciones
|
||||
void Resource::loadRooms() {
|
||||
std::cout << "\n>> ROOMS" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::ROOM);
|
||||
auto list = Asset::get()->getListByType(Asset::Type::ROOM);
|
||||
rooms_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -352,15 +352,15 @@ void Resource::clearMusics() {
|
||||
|
||||
// Calcula el numero de recursos para cargar
|
||||
void Resource::calculateTotal() {
|
||||
std::vector<AssetType> asset_types = {
|
||||
AssetType::SOUND,
|
||||
AssetType::MUSIC,
|
||||
AssetType::BITMAP,
|
||||
AssetType::PALETTE,
|
||||
AssetType::FONT,
|
||||
AssetType::ANIMATION,
|
||||
AssetType::TILEMAP,
|
||||
AssetType::ROOM};
|
||||
std::vector<Asset::Type> asset_types = {
|
||||
Asset::Type::SOUND,
|
||||
Asset::Type::MUSIC,
|
||||
Asset::Type::BITMAP,
|
||||
Asset::Type::PALETTE,
|
||||
Asset::Type::FONT,
|
||||
Asset::Type::ANIMATION,
|
||||
Asset::Type::TILEMAP,
|
||||
Asset::Type::ROOM};
|
||||
|
||||
size_t total = 0;
|
||||
for (const auto& asset_type : asset_types) {
|
||||
|
||||
Reference in New Issue
Block a user