Arreglado un bug a la hora de buscar por nombre los recursos
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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));
|
||||||
@@ -27,8 +30,12 @@ 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 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;
|
||||||
@@ -70,11 +77,11 @@ void Resource::loadRooms(std::vector<std::string> list)
|
|||||||
r.name = l;
|
r.name = l;
|
||||||
r.room = new room_t(loadRoomFile(asset->get(l)));
|
r.room = new room_t(loadRoomFile(asset->get(l)));
|
||||||
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
||||||
for (auto &e:r.room->enemies)
|
for (auto &e : r.room->enemies)
|
||||||
{
|
{
|
||||||
e.animation = getAnimation(e.animationString);
|
e.animation = getAnimation(e.animationString);
|
||||||
}
|
}
|
||||||
for (auto &i:r.room->items)
|
for (auto &i : r.room->items)
|
||||||
{
|
{
|
||||||
i.texture = getTexture(i.tileSetFile);
|
i.texture = getTexture(i.tileSetFile);
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|||||||
@@ -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};
|
||||||
// ****
|
// ****
|
||||||
|
|||||||
Reference in New Issue
Block a user