From 83977ed22cf5504cb8167fd535bd94a5e8cf55b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Mon, 31 Oct 2022 20:07:41 +0100 Subject: [PATCH] Arreglado un bug a la hora de buscar por nombre los recursos --- source/common/asset.cpp | 5 ++++- source/common/resource.cpp | 35 ++++++++++++++++++++++++++--------- source/director.cpp | 2 +- source/game.cpp | 4 ++-- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/source/common/asset.cpp b/source/common/asset.cpp index b2718b6..dbd63fa 100644 --- a/source/common/asset.cpp +++ b/source/common/asset.cpp @@ -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; } diff --git a/source/common/resource.cpp b/source/common/resource.cpp index e9f1bfe..8ead87f 100644 --- a/source/common/resource.cpp +++ b/source/common/resource.cpp @@ -14,6 +14,9 @@ void Resource::loadTextures(std::vector 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 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 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 *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; } diff --git a/source/director.cpp b/source/director.cpp index 21140f9..1c099a0 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -311,7 +311,7 @@ void Director::loadResources(section_t section) std::vector animationList; // Jugador - animationList.push_back("player"); + animationList.push_back("player.ani"); // Enemigos animationList.push_back("abad.ani"); diff --git a/source/game.cpp b/source/game.cpp index 9b561a5..8371417 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -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}; // ****