Arreglado un bug a la hora de buscar por nombre los recursos

This commit is contained in:
2022-10-31 20:07:41 +01:00
parent a354104c8c
commit 83977ed22c
4 changed files with 33 additions and 13 deletions

View File

@@ -26,7 +26,10 @@ std::string Asset::get(std::string text)
{
for (auto f : fileList)
{
if (f.file.find(text) != std::string::npos)
const size_t lastIndex = f.file.find_last_of("/")+1;
const std:: string file = f.file.substr(lastIndex, std::string::npos);
if (file == text)
{
return f.file;
}

View File

@@ -14,6 +14,9 @@ void Resource::loadTextures(std::vector<std::string> list)
{
for (auto l : list)
{
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
std::cout << "png: " << asset->get(l) << std::endl;
res_texture_t t;
t.name = l;
t.texture = new Texture(renderer, asset->get(l));
@@ -27,8 +30,12 @@ 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 size_t lastIndex = l.find_last_of(".");
const std:: string pngFile = l.substr(0, lastIndex)+".png";
const size_t lastIndex = l.find_last_of(".");
const std::string pngFile = l.substr(0, lastIndex) + ".png";
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
std::cout << "png: " << asset->get(pngFile) << std::endl;
std::cout << "ani: " << asset->get(l) << std::endl;
res_animation_t as;
as.name = l;
@@ -70,11 +77,11 @@ void Resource::loadRooms(std::vector<std::string> list)
r.name = l;
r.room = new room_t(loadRoomFile(asset->get(l)));
r.room->tileMap = getTileMap(r.room->tileMapFile);
for (auto &e:r.room->enemies)
for (auto &e : r.room->enemies)
{
e.animation = getAnimation(e.animationString);
}
for (auto &i:r.room->items)
for (auto &i : r.room->items)
{
i.texture = getTexture(i.tileSetFile);
}
@@ -158,8 +165,12 @@ Texture *Resource::getTexture(std::string name)
{
for (auto texture : textures)
{
if (texture.name.find(name) != std::string::npos)
// 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;
return texture.texture;
}
}
@@ -173,8 +184,11 @@ animatedSprite_t *Resource::getAnimation(std::string name)
{
for (auto animation : animations)
{
if (animation.name.find(name) != std::string::npos)
// if (animation.name.find(name) != std::string::npos)
if (animation.name == name)
{
// std::cout << "\nANIMATION REQUESTED: " << name << std::endl;
// std::cout << "served: " << animation.name << std::endl;
return animation.animation;
}
}
@@ -188,7 +202,8 @@ textFile_t *Resource::getOffset(std::string name)
{
for (auto offset : offsets)
{
if (offset.name.find(name) != std::string::npos)
// if (offset.name.find(name) != std::string::npos)
if (offset.name == name)
{
return offset.textFile;
}
@@ -203,7 +218,8 @@ std::vector<int> *Resource::getTileMap(std::string name)
{
for (auto tileMap : tileMaps)
{
if (tileMap.name.find(name) != std::string::npos)
// if (tileMap.name.find(name) != std::string::npos)
if (tileMap.name == name)
{
return tileMap.tileMap;
}
@@ -218,7 +234,8 @@ room_t *Resource::getRoom(std::string name)
{
for (auto room : rooms)
{
if (room.name.find(name) != std::string::npos)
// if (room.name.find(name) != std::string::npos)
if (room.name == name)
{
return room.room;
}

View File

@@ -311,7 +311,7 @@ void Director::loadResources(section_t section)
std::vector<std::string> animationList;
// Jugador
animationList.push_back("player");
animationList.push_back("player.ani");
// Enemigos
animationList.push_back("abad.ani");

View File

@@ -20,8 +20,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
// ****
// this->debug->setEnabled(true);
currentRoom = "06.room";
const int x = 30;
currentRoom = "25.room";
const int x = 28;
const int y = 13;
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
// ****