canvi de pc

This commit is contained in:
2025-02-21 19:45:29 +01:00
parent 5f68c6256f
commit 7a0bc5c9ae
18 changed files with 918 additions and 889 deletions

View File

@@ -8,37 +8,30 @@
#include "text.h" // Para textFile_t, LoadTextFile
#include "texture.h" // Para Texture
#include "utils.h" // Para options_t
// Constructor
Resource::Resource(SDL_Renderer *renderer, Asset *asset, options_t *options)
{
this->renderer = renderer;
this->asset = asset;
this->options = options;
}
#include "screen.h"
// Carga las texturas de una lista
void Resource::loadTextures(std::vector<std::string> list)
{
for (auto l : list)
{
if (options->console)
if (options_->console)
{
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
std::cout << "png: " << asset->get(l) << std::endl;
std::cout << "png: " << Asset::get()->get(l) << std::endl;
}
res_texture_t t;
t.name = l;
t.texture = new Texture(renderer, asset->get(t.name), options->console);
textures.push_back(t);
t.texture = new Texture(Screen::get()->getRenderer(), Asset::get()->get(t.name), options_->console);
textures_.push_back(t);
}
}
// Vuelve a cargar las texturas
void Resource::reLoadTextures()
{
for (auto texture : textures)
for (auto texture : textures_)
{
texture.texture->reLoad();
}
@@ -52,17 +45,17 @@ void Resource::loadAnimations(std::vector<std::string> list)
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
const std::string pngFile = l.substr(0, l.find_last_of(".")) + ".png";
if (options->console)
if (options_->console)
{
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
std::cout << "png: " << asset->get(pngFile) << std::endl;
std::cout << "ani: " << asset->get(l) << std::endl;
std::cout << "png: " << Asset::get()->get(pngFile) << std::endl;
std::cout << "ani: " << Asset::get()->get(l) << std::endl;
}
res_animation_t as;
as.name = l;
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(as.name), options->console));
animations.push_back(as);
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), Asset::get()->get(as.name), options_->console));
animations_.push_back(as);
}
}
@@ -71,12 +64,12 @@ void Resource::reLoadAnimations()
{
// 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
const std::string pngFile = a.name.substr(0, a.name.find_last_of(".")) + ".png";
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()->get(a.name), options_->console));
}
}
@@ -87,18 +80,18 @@ void Resource::loadOffsets(std::vector<std::string> list)
{
res_textOffset_t to;
to.name = l;
to.textFile = new textFile_t(LoadTextFile(asset->get(l), options->console));
offsets.push_back(to);
to.textFile = new textFile_t(LoadTextFile(Asset::get()->get(l), options_->console));
offsets_.push_back(to);
}
}
// Vuelve a cargar los offsets
void Resource::reLoadOffsets()
{
for (auto &o : offsets)
for (auto &o : offsets_)
{
delete o.textFile;
o.textFile = new textFile_t(LoadTextFile(asset->get(o.name), options->console));
o.textFile = new textFile_t(LoadTextFile(Asset::get()->get(o.name), options_->console));
}
}
@@ -109,18 +102,18 @@ void Resource::loadTileMaps(std::vector<std::string> list)
{
res_tileMap_t tm;
tm.name = l;
tm.tileMap = new std::vector<int>(loadRoomTileFile(asset->get(l), options->console));
tileMaps.push_back(tm);
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(l), options_->console));
tile_maps_.push_back(tm);
}
}
// Vuelve a cargar los mapas de tiles
void Resource::reLoadTileMaps()
{
for (auto &tm : tileMaps)
for (auto &tm : tile_maps_)
{
delete tm.tileMap;
tm.tileMap = new std::vector<int>(loadRoomTileFile(asset->get(tm.name), options->console));
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(tm.name), options_->console));
}
}
@@ -131,7 +124,7 @@ void Resource::loadRooms(std::vector<std::string> list)
{
res_room_t r;
r.name = l;
r.room = new room_t(loadRoomFile(asset->get(l), options->console));
r.room = new room_t(loadRoomFile(Asset::get()->get(l), options_->console));
r.room->tileMap = getTileMap(r.room->tileMapFile);
for (auto &e : r.room->enemies)
{
@@ -143,7 +136,7 @@ void Resource::loadRooms(std::vector<std::string> list)
}
r.room->textureA = getTexture("standard.png");
r.room->textureB = getTexture("standard_zxarne.png");
rooms.push_back(r);
rooms_.push_back(r);
}
}
@@ -152,10 +145,10 @@ void Resource::reLoadRooms()
{
reLoadTileMaps();
for (auto &r : rooms)
for (auto &r : rooms_)
{
delete r.room;
r.room = new room_t(loadRoomFile(asset->get(r.name)));
r.room = new room_t(loadRoomFile(Asset::get()->get(r.name)));
r.room->tileMap = getTileMap(r.room->tileMapFile);
for (auto &e : r.room->enemies)
{
@@ -181,51 +174,51 @@ void Resource::reLoad()
// Libera las texturas
void Resource::freeTextures()
{
for (auto texture : textures)
for (auto texture : textures_)
{
delete texture.texture;
}
textures.clear();
textures_.clear();
}
// Libera las animaciones
void Resource::freeAnimations()
{
for (auto a : animations)
for (auto a : animations_)
{
delete a.animation;
}
animations.clear();
animations_.clear();
}
// Libera los offsets
void Resource::freeOffsets()
{
for (auto o : offsets)
for (auto o : offsets_)
{
delete o.textFile;
}
offsets.clear();
offsets_.clear();
}
// Libera los mapas de tiles
void Resource::freeTileMaps()
{
for (auto t : tileMaps)
for (auto t : tile_maps_)
{
delete t.tileMap;
}
tileMaps.clear();
tile_maps_.clear();
}
// Libera las habitaciones
void Resource::freeRooms()
{
for (auto r : rooms)
for (auto r : rooms_)
{
delete r.room;
}
rooms.clear();
rooms_.clear();
}
// Libera todos los recursos
@@ -241,7 +234,7 @@ void Resource::free()
// Obtiene una textura
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 == name)
@@ -253,7 +246,7 @@ Texture *Resource::getTexture(std::string name)
}
}
if (options->console)
if (options_->console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
@@ -263,7 +256,7 @@ Texture *Resource::getTexture(std::string name)
// Obtiene una animación
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 == name)
@@ -274,7 +267,7 @@ animatedSprite_t *Resource::getAnimation(std::string name)
}
}
if (options->console)
if (options_->console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
@@ -284,7 +277,7 @@ animatedSprite_t *Resource::getAnimation(std::string name)
// Obtiene un offset
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 == name)
@@ -293,7 +286,7 @@ textFile_t *Resource::getOffset(std::string name)
}
}
if (options->console)
if (options_->console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
@@ -303,7 +296,7 @@ textFile_t *Resource::getOffset(std::string name)
// Obtiene un mapa de tiles
std::vector<int> *Resource::getTileMap(std::string name)
{
for (auto tileMap : tileMaps)
for (auto tileMap : tile_maps_)
{
// if (tileMap.name.find(name) != std::string::npos)
if (tileMap.name == name)
@@ -312,7 +305,7 @@ std::vector<int> *Resource::getTileMap(std::string name)
}
}
if (options->console)
if (options_->console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
@@ -322,7 +315,7 @@ std::vector<int> *Resource::getTileMap(std::string name)
// Obtiene una habitacion
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 == name)
@@ -331,7 +324,7 @@ room_t *Resource::getRoom(std::string name)
}
}
if (options->console)
if (options_->console)
{
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
}
@@ -341,5 +334,5 @@ room_t *Resource::getRoom(std::string name)
// Obtiene todas las habitaciones
std::vector<res_room_t> *Resource::getAllRooms()
{
return &rooms;
return &rooms_;
}