forked from jaildesigner-jailgames/jaildoctors_dilemma
Afegint smart pointers
Actualitzat Resources Actualitzades les classes Sprite i derivades Afegida nova tipografia Actualitzat Asset Actualitzat Text
This commit is contained in:
@@ -1,360 +1,355 @@
|
||||
#include "resource.h"
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||
#include "animatedsprite.h" // Para animatedSprite_t, loadAnimationFromFile
|
||||
#include "asset.h" // Para Asset
|
||||
#include "enemy.h" // Para enemy_t
|
||||
#include "item.h" // Para item_t
|
||||
#include "room.h" // Para room_t, loadRoomFile, loadRoomTileFile
|
||||
#include "text.h" // Para textFile_t, LoadTextFile
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para options_t
|
||||
#include "screen.h"
|
||||
#include "options.h"
|
||||
#include <algorithm> // Para find_if
|
||||
#include <iostream> // Para basic_ostream, operator<<, endl, cout, cerr
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <utility> // Para pair
|
||||
#include "asset.h" // Para Asset, AssetType
|
||||
#include "jail_audio.h" // Para JA_LoadMusic, JA_LoadSound
|
||||
#include "lang.h" // Para getText
|
||||
#include "screen.h" // Para Screen
|
||||
#include "text.h" // Para Text, loadTextFile
|
||||
struct JA_Music_t; // lines 10-10
|
||||
struct JA_Sound_t; // lines 11-11
|
||||
|
||||
// [SINGLETON]
|
||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Resource *Resource::resource_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||
void Resource::init()
|
||||
{
|
||||
Resource::resource_ = new Resource();
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
||||
void Resource::destroy()
|
||||
{
|
||||
delete Resource::resource_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
Resource *Resource::get()
|
||||
{
|
||||
return Resource::resource_;
|
||||
}
|
||||
|
||||
// Carga las texturas de una lista
|
||||
void Resource::loadTextures(std::vector<std::string> list)
|
||||
// Constructor
|
||||
Resource::Resource()
|
||||
{
|
||||
for (auto l : list)
|
||||
{
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
|
||||
std::cout << "png: " << Asset::get()->get(l) << std::endl;
|
||||
}
|
||||
|
||||
res_texture_t t;
|
||||
t.name = l;
|
||||
t.texture = new Texture(Screen::get()->getRenderer(), Asset::get()->get(t.name), options.console);
|
||||
textures_.push_back(t);
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
// Vuelve a cargar las texturas
|
||||
void Resource::reLoadTextures()
|
||||
// Vacia todos los vectores de recursos
|
||||
void Resource::clear()
|
||||
{
|
||||
for (auto texture : textures_)
|
||||
{
|
||||
texture.texture->reLoad();
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las animaciones desde una lista
|
||||
void Resource::loadAnimations(std::vector<std::string> list)
|
||||
{
|
||||
for (auto l : list)
|
||||
{
|
||||
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
|
||||
const std::string pngFile = l.substr(0, l.find_last_of(".")) + ".png";
|
||||
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
|
||||
std::cout << "png: " << Asset::get()->get(pngFile) << std::endl;
|
||||
std::cout << "ani: " << Asset::get()->get(l) << std::endl;
|
||||
}
|
||||
|
||||
res_animation_t as;
|
||||
as.name = l;
|
||||
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), Asset::get()->get(as.name), options.console));
|
||||
animations_.push_back(as);
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelve a cargar las animaciones
|
||||
void Resource::reLoadAnimations()
|
||||
{
|
||||
// reLoadTextures();
|
||||
|
||||
for (auto &a : animations_)
|
||||
{
|
||||
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
|
||||
const std::string pngFile = a.name.substr(0, a.name.find_last_of(".")) + ".png";
|
||||
delete a.animation;
|
||||
a.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), Asset::get()->get(a.name), options.console));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los offsets desde una lista
|
||||
void Resource::loadOffsets(std::vector<std::string> list)
|
||||
{
|
||||
for (auto l : list)
|
||||
{
|
||||
res_textOffset_t to;
|
||||
to.name = l;
|
||||
to.textFile = new textFile_t(LoadTextFile(Asset::get()->get(l), options.console));
|
||||
offsets_.push_back(to);
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelve a cargar los offsets
|
||||
void Resource::reLoadOffsets()
|
||||
{
|
||||
for (auto &o : offsets_)
|
||||
{
|
||||
delete o.textFile;
|
||||
o.textFile = new textFile_t(LoadTextFile(Asset::get()->get(o.name), options.console));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los mapas de tiles desde una lista
|
||||
void Resource::loadTileMaps(std::vector<std::string> list)
|
||||
{
|
||||
for (auto l : list)
|
||||
{
|
||||
res_tileMap_t tm;
|
||||
tm.name = l;
|
||||
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(l), options.console));
|
||||
tile_maps_.push_back(tm);
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelve a cargar los mapas de tiles
|
||||
void Resource::reLoadTileMaps()
|
||||
{
|
||||
for (auto &tm : tile_maps_)
|
||||
{
|
||||
delete tm.tileMap;
|
||||
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(tm.name), options.console));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las habitaciones desde una lista
|
||||
void Resource::loadRooms(std::vector<std::string> list)
|
||||
{
|
||||
for (auto l : list)
|
||||
{
|
||||
res_room_t r;
|
||||
r.name = l;
|
||||
r.room = new room_t(loadRoomFile(Asset::get()->get(l), options.console));
|
||||
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
||||
for (auto &e : r.room->enemies)
|
||||
{
|
||||
e.animation = getAnimation(e.animationString);
|
||||
}
|
||||
for (auto &i : r.room->items)
|
||||
{
|
||||
i.texture = getTexture(i.tileSetFile);
|
||||
}
|
||||
r.room->textureA = getTexture("standard.png");
|
||||
r.room->textureB = getTexture("standard_zxarne.png");
|
||||
rooms_.push_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelve a cargar las habitaciones
|
||||
void Resource::reLoadRooms()
|
||||
{
|
||||
reLoadTileMaps();
|
||||
|
||||
for (auto &r : rooms_)
|
||||
{
|
||||
delete r.room;
|
||||
r.room = new room_t(loadRoomFile(Asset::get()->get(r.name)));
|
||||
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
||||
for (auto &e : r.room->enemies)
|
||||
{
|
||||
e.animation = getAnimation(e.animationString);
|
||||
}
|
||||
for (auto &i : r.room->items)
|
||||
{
|
||||
i.texture = getTexture(i.tileSetFile);
|
||||
}
|
||||
r.room->textureA = getTexture("standard.png");
|
||||
r.room->textureB = getTexture("standard_zxarne.png");
|
||||
}
|
||||
}
|
||||
|
||||
// Vuelve a cargar todos los recursos
|
||||
void Resource::reLoad()
|
||||
{
|
||||
reLoadAnimations();
|
||||
reLoadOffsets();
|
||||
reLoadRooms();
|
||||
}
|
||||
|
||||
// Libera las texturas
|
||||
void Resource::freeTextures()
|
||||
{
|
||||
for (auto texture : textures_)
|
||||
{
|
||||
delete texture.texture;
|
||||
}
|
||||
clearSounds();
|
||||
clearMusics();
|
||||
textures_.clear();
|
||||
}
|
||||
|
||||
// Libera las animaciones
|
||||
void Resource::freeAnimations()
|
||||
{
|
||||
for (auto a : animations_)
|
||||
{
|
||||
delete a.animation;
|
||||
}
|
||||
text_files_.clear();
|
||||
texts_.clear();
|
||||
animations_.clear();
|
||||
demos_.clear();
|
||||
}
|
||||
|
||||
// Libera los offsets
|
||||
void Resource::freeOffsets()
|
||||
// Carga todos los recursos
|
||||
void Resource::load()
|
||||
{
|
||||
for (auto o : offsets_)
|
||||
{
|
||||
delete o.textFile;
|
||||
}
|
||||
offsets_.clear();
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
loadSounds();
|
||||
loadMusics();
|
||||
loadTextures();
|
||||
loadTextFiles();
|
||||
loadAnimations();
|
||||
loadDemoData();
|
||||
addPalettes();
|
||||
createText();
|
||||
createTextures();
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
|
||||
// Libera los mapas de tiles
|
||||
void Resource::freeTileMaps()
|
||||
// Recarga todos los recursos
|
||||
void Resource::reload()
|
||||
{
|
||||
for (auto t : tile_maps_)
|
||||
clear();
|
||||
load();
|
||||
}
|
||||
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(sounds_.begin(), sounds_.end(), [&name](const auto &s)
|
||||
{ return s.name == name; });
|
||||
|
||||
if (it != sounds_.end())
|
||||
{
|
||||
delete t.tileMap;
|
||||
return it->sound;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Sonido no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Sonido no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la música a partir de un nombre
|
||||
JA_Music_t *Resource::getMusic(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(musics_.begin(), musics_.end(), [&name](const auto &m)
|
||||
{ return m.name == name; });
|
||||
|
||||
if (it != musics_.end())
|
||||
{
|
||||
return it->music;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Música no encontrada " << name << std::endl;
|
||||
throw std::runtime_error("Música no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la textura a partir de un nombre
|
||||
std::shared_ptr<Texture> Resource::getTexture(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(textures_.begin(), textures_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != textures_.end())
|
||||
{
|
||||
return it->texture;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Imagen no encontrada " << name << std::endl;
|
||||
throw std::runtime_error("Imagen no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(text_files_.begin(), text_files_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != text_files_.end())
|
||||
{
|
||||
return it->text_file;
|
||||
}
|
||||
|
||||
std::cerr << "Error: TextFile no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> Resource::getText(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(texts_.begin(), texts_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != texts_.end())
|
||||
{
|
||||
return it->text;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Text no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Text no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
AnimationsFileBuffer &Resource::getAnimation(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(animations_.begin(), animations_.end(), [&name](const auto &a)
|
||||
{ return a.name == name; });
|
||||
|
||||
if (it != animations_.end())
|
||||
{
|
||||
return it->animation;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Animación no encontrada " << name << std::endl;
|
||||
throw std::runtime_error("Animación no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el mapa de tiles a partir de un nombre
|
||||
std::vector<int> &Resource::getTileMap(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(tile_maps_.begin(), tile_maps_.end(), [&name](const auto &t)
|
||||
{ return t.name == name; });
|
||||
|
||||
if (it != tile_maps_.end())
|
||||
{
|
||||
return it->tileMap;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Mapa de tiles no encontrado " << name << std::endl;
|
||||
throw std::runtime_error("Mapa de tiles no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la habitación a partir de un nombre
|
||||
std::shared_ptr<room_t> Resource::getRoom(const std::string &name)
|
||||
{
|
||||
auto it = std::find_if(rooms_.begin(), rooms_.end(), [&name](const auto &r)
|
||||
{ return r.name == name; });
|
||||
|
||||
if (it != rooms_.end())
|
||||
{
|
||||
return it->room;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Habitación no encontrada " << name << std::endl;
|
||||
throw std::runtime_error("Habitación no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Carga los sonidos
|
||||
void Resource::loadSounds()
|
||||
{
|
||||
std::cout << "\n>> SOUND FILES" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
sounds_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
auto name = getFileName(l);
|
||||
sounds_.emplace_back(ResourceSound(name, JA_LoadSound(l.c_str())));
|
||||
printWithDots("Sound : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las musicas
|
||||
void Resource::loadMusics()
|
||||
{
|
||||
std::cout << "\n>> MUSIC FILES" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
musics_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
auto name = getFileName(l);
|
||||
musics_.emplace_back(ResourceMusic(name, JA_LoadMusic(l.c_str())));
|
||||
printWithDots("Music : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las texturas
|
||||
void Resource::loadTextures()
|
||||
{
|
||||
std::cout << "\n>> TEXTURES" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
||||
textures_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
auto name = getFileName(l);
|
||||
textures_.emplace_back(ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los ficheros de texto
|
||||
void Resource::loadTextFiles()
|
||||
{
|
||||
std::cout << "\n>> TEXT FILES" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::FONT);
|
||||
text_files_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
auto name = getFileName(l);
|
||||
text_files_.emplace_back(ResourceTextFile(name, loadTextFile(l)));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las animaciones
|
||||
void Resource::loadAnimations()
|
||||
{
|
||||
std::cout << "\n>> ANIMATIONS" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::ANIMATION);
|
||||
animations_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
auto name = getFileName(l);
|
||||
animations_.emplace_back(ResourceAnimation(name, loadAnimationsFromFile(l)));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los mapas de tiles
|
||||
void Resource::loadTileMaps()
|
||||
{
|
||||
std::cout << "\n>> TILE MAPS" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::TILEMAP);
|
||||
tile_maps_.clear();
|
||||
|
||||
for (const auto &l : list)
|
||||
{
|
||||
auto name = getFileName(l);
|
||||
tile_maps_.emplace_back(ResourceTileMap(name, std::make_shared<std::vector<int>>(loadRoomTileFile(l))));
|
||||
}
|
||||
}
|
||||
|
||||
// Libera las habitaciones
|
||||
void Resource::freeRooms()
|
||||
// Carga las habitaciones
|
||||
void Resource::loadRooms()
|
||||
{
|
||||
for (auto r : rooms_)
|
||||
{
|
||||
delete r.room;
|
||||
}
|
||||
std::cout << "\n>> ROOMS" << std::endl;
|
||||
auto list = Asset::get()->getListByType(AssetType::ROOM);
|
||||
rooms_.clear();
|
||||
}
|
||||
|
||||
// Libera todos los recursos
|
||||
void Resource::free()
|
||||
{
|
||||
freeTextures();
|
||||
freeAnimations();
|
||||
freeOffsets();
|
||||
freeTileMaps();
|
||||
freeRooms();
|
||||
}
|
||||
|
||||
// Obtiene una textura
|
||||
Texture *Resource::getTexture(std::string name)
|
||||
{
|
||||
for (auto texture : textures_)
|
||||
for (const auto &l : list)
|
||||
{
|
||||
// if (texture.name.find(name) != std::string::npos)
|
||||
if (texture.name == name)
|
||||
{
|
||||
// std::cout << "\nTEXTURE REQUESTED: " << name << std::endl;
|
||||
// std::cout << "served: " << texture.name << std::endl;
|
||||
auto name = getFileName(l);
|
||||
rooms_.emplace_back(ResourceRoom(name, std::make_shared<room_t>(loadRoomFile(l))));
|
||||
}
|
||||
}
|
||||
|
||||
return texture.texture;
|
||||
void Resource::createText()
|
||||
{
|
||||
struct ResourceInfo
|
||||
{
|
||||
std::string key; // Identificador del recurso
|
||||
std::string textureFile; // Nombre del archivo de textura
|
||||
std::string textFile; // Nombre del archivo de texto
|
||||
|
||||
// Constructor para facilitar la creación de objetos ResourceInfo
|
||||
ResourceInfo(const std::string &k, const std::string &tFile, const std::string &txtFile)
|
||||
: key(k), textureFile(tFile), textFile(txtFile) {}
|
||||
};
|
||||
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||
|
||||
std::vector<ResourceInfo> resources = {
|
||||
{"debug", "debug.png", "debug.txt"},
|
||||
{"gauntlet", "gauntlet.png", "gauntlet.txt"},
|
||||
{"smb2", "smb2.png", "smb2.txt"},
|
||||
{"subatomic", "subatomic.png", "subatomic.txt"},
|
||||
{"8bithud", "8bithud.png", "8bithud.txt"}};
|
||||
|
||||
for (const auto &resource : resources)
|
||||
{
|
||||
texts_.emplace_back(ResourceText(resource.key, std::make_shared<Text>(
|
||||
getTexture(resource.textureFile),
|
||||
getTextFile(resource.textFile))));
|
||||
printWithDots("Text : ", resource.key, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
// Vacía el vector de sonidos
|
||||
void Resource::clearSounds()
|
||||
{
|
||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Sound_t
|
||||
for (auto &sound : sounds_)
|
||||
{
|
||||
if (sound.sound)
|
||||
{
|
||||
JA_DeleteSound(sound.sound);
|
||||
sound.sound = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
sounds_.clear(); // Limpia el vector después de liberar todos los recursos
|
||||
}
|
||||
|
||||
// Obtiene una animación
|
||||
animatedSprite_t *Resource::getAnimation(std::string name)
|
||||
// Vacía el vector de musicas
|
||||
void Resource::clearMusics()
|
||||
{
|
||||
for (auto animation : animations_)
|
||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Music_t
|
||||
for (auto &music : musics_)
|
||||
{
|
||||
// if (animation.name.find(name) != std::string::npos)
|
||||
if (animation.name == name)
|
||||
if (music.music)
|
||||
{
|
||||
// std::cout << "\nANIMATION REQUESTED: " << name << std::endl;
|
||||
// std::cout << "served: " << animation.name << std::endl;
|
||||
return animation.animation;
|
||||
JA_DeleteMusic(music.music);
|
||||
music.music = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Obtiene un offset
|
||||
textFile_t *Resource::getOffset(std::string name)
|
||||
{
|
||||
for (auto offset : offsets_)
|
||||
{
|
||||
// if (offset.name.find(name) != std::string::npos)
|
||||
if (offset.name == name)
|
||||
{
|
||||
return offset.textFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Obtiene un mapa de tiles
|
||||
std::vector<int> *Resource::getTileMap(std::string name)
|
||||
{
|
||||
for (auto tileMap : tile_maps_)
|
||||
{
|
||||
// if (tileMap.name.find(name) != std::string::npos)
|
||||
if (tileMap.name == name)
|
||||
{
|
||||
return tileMap.tileMap;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Obtiene una habitacion
|
||||
room_t *Resource::getRoom(std::string name)
|
||||
{
|
||||
for (auto room : rooms_)
|
||||
{
|
||||
// if (room.name.find(name) != std::string::npos)
|
||||
if (room.name == name)
|
||||
{
|
||||
return room.room;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Obtiene todas las habitaciones
|
||||
std::vector<res_room_t> *Resource::getAllRooms()
|
||||
{
|
||||
return &rooms_;
|
||||
musics_.clear(); // Limpia el vector después de liberar todos los recursos
|
||||
}
|
||||
Reference in New Issue
Block a user