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) 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; return f.file;
} }

View File

@@ -14,6 +14,9 @@ void Resource::loadTextures(std::vector<std::string> list)
{ {
for (auto l : list) for (auto l : list)
{ {
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
std::cout << "png: " << asset->get(l) << std::endl;
res_texture_t t; res_texture_t t;
t.name = l; t.name = l;
t.texture = new Texture(renderer, asset->get(l)); t.texture = new Texture(renderer, asset->get(l));
@@ -30,6 +33,10 @@ void Resource::loadAnimations(std::vector<std::string> list)
const size_t lastIndex = l.find_last_of("."); const size_t lastIndex = l.find_last_of(".");
const std::string pngFile = l.substr(0, lastIndex) + ".png"; 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; res_animation_t as;
as.name = l; as.name = l;
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(l))); as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(l)));
@@ -158,8 +165,12 @@ Texture *Resource::getTexture(std::string name)
{ {
for (auto texture : textures) 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; return texture.texture;
} }
} }
@@ -173,8 +184,11 @@ animatedSprite_t *Resource::getAnimation(std::string name)
{ {
for (auto animation : animations) 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; return animation.animation;
} }
} }
@@ -188,7 +202,8 @@ textFile_t *Resource::getOffset(std::string name)
{ {
for (auto offset : offsets) 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; return offset.textFile;
} }
@@ -203,7 +218,8 @@ std::vector<int> *Resource::getTileMap(std::string name)
{ {
for (auto tileMap : tileMaps) 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; return tileMap.tileMap;
} }
@@ -218,7 +234,8 @@ room_t *Resource::getRoom(std::string name)
{ {
for (auto room : rooms) 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; return room.room;
} }

View File

@@ -311,7 +311,7 @@ void Director::loadResources(section_t section)
std::vector<std::string> animationList; std::vector<std::string> animationList;
// Jugador // Jugador
animationList.push_back("player"); animationList.push_back("player.ani");
// Enemigos // Enemigos
animationList.push_back("abad.ani"); 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); // this->debug->setEnabled(true);
currentRoom = "06.room"; currentRoom = "25.room";
const int x = 30; const int x = 28;
const int y = 13; const int y = 13;
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
// **** // ****