Ya funciona la recarga de recursos

This commit is contained in:
2022-11-07 20:14:19 +01:00
parent a36378f98c
commit a28a93e791
2 changed files with 10 additions and 12 deletions

View File

@@ -22,7 +22,7 @@ void Resource::loadTextures(std::vector<std::string> list)
res_texture_t t; res_texture_t t;
t.name = l; t.name = l;
t.texture = new Texture(renderer, asset->get(l), options->console); t.texture = new Texture(renderer, asset->get(t.name), options->console);
textures.push_back(t); textures.push_back(t);
} }
} }
@@ -42,8 +42,7 @@ void Resource::loadAnimations(std::vector<std::string> list)
for (auto l : list) for (auto l : list)
{ {
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura // Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
const size_t lastIndex = l.find_last_of("."); const std::string pngFile = l.substr(0, l.find_last_of(".")) + ".png";
const std::string pngFile = l.substr(0, lastIndex) + ".png";
if (options->console) if (options->console)
{ {
@@ -54,7 +53,7 @@ void Resource::loadAnimations(std::vector<std::string> list)
res_animation_t as; res_animation_t as;
as.name = l; as.name = l;
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(l), options->console)); as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(as.name), options->console));
animations.push_back(as); animations.push_back(as);
} }
} }
@@ -62,13 +61,12 @@ void Resource::loadAnimations(std::vector<std::string> list)
// Vuelve a cargar las animaciones // Vuelve a cargar las animaciones
void Resource::reLoadAnimations() void Resource::reLoadAnimations()
{ {
reLoadTextures(); // reLoadTextures();
for (auto a:animations) for (auto &a : animations)
{ {
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura // Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
const size_t lastIndex = a.name.find_last_of("."); const std::string pngFile = a.name.substr(0, a.name.find_last_of(".")) + ".png";
const std::string pngFile = a.name.substr(0, lastIndex) + ".png";
delete a.animation; delete a.animation;
a.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(a.name), options->console)); a.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(a.name), options->console));
} }

View File

@@ -34,13 +34,13 @@ struct res_textOffset_t
struct res_tileMap_t struct res_tileMap_t
{ {
std::string name; // Nombre del mapa de tiles std::string name; // Nombre del mapa de tiles
std::vector<int> *tileMap; // Vecor con los indices del mapa de tiles std::vector<int> *tileMap; // Vector con los indices del mapa de tiles
}; };
struct res_room_t struct res_room_t
{ {
std::string name; // Nombre de la habitación std::string name; // Nombre de la habitación
room_t *room; // Vecor con las habitaciones room_t *room; // Vector con las habitaciones
}; };
// Clase Resource. Almacena recursos de disco en memoria // Clase Resource. Almacena recursos de disco en memoria