forked from jaildesigner-jailgames/jaildoctors_dilemma
89 lines
2.1 KiB
C++
89 lines
2.1 KiB
C++
#include "resource.h"
|
|
#include <iostream>
|
|
|
|
// Constructor
|
|
Resource::Resource(SDL_Renderer *renderer, Asset *asset, options_t *options)
|
|
{
|
|
this->renderer = renderer;
|
|
this->asset = asset;
|
|
this->options = options;
|
|
}
|
|
|
|
// Carga las texturas de una lista
|
|
void Resource::loadTextures(std::vector<std::string> list)
|
|
{
|
|
std::cout << "** LOAD TEXTURES" << std::endl;
|
|
for (auto l : list)
|
|
{
|
|
texture_t t;
|
|
t.name = l;
|
|
t.texture = new Texture(renderer, asset->get(t.name));
|
|
textures.push_back(t);
|
|
}
|
|
std::cout << "** TEXTURES LOADED" << std::endl;
|
|
}
|
|
|
|
// Carga las animaciones desde una lista
|
|
void Resource::loadAnimations(std::vector<std::string> list)
|
|
{
|
|
std::cout << "** LOAD ANIMATIONS" << std::endl;
|
|
for (auto l : list)
|
|
{
|
|
animation_t as;
|
|
as.name = l+".ani";
|
|
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(l+".png"), asset->get(l+".ani")));
|
|
animations.push_back(as);
|
|
}
|
|
std::cout << "** ANIMATIONS LOADED" << std::endl;
|
|
}
|
|
|
|
// Recarga las texturas
|
|
void Resource::reLoadTextures()
|
|
{
|
|
for (auto texture : textures)
|
|
{
|
|
texture.texture->reLoad();
|
|
}
|
|
}
|
|
|
|
// Libera las texturas
|
|
void Resource::freeTextures()
|
|
{
|
|
for (auto texture : textures)
|
|
{
|
|
delete texture.texture;
|
|
}
|
|
textures.clear();
|
|
}
|
|
|
|
// Obtiene una textura
|
|
Texture *Resource::getTexture(std::string name)
|
|
{
|
|
for (auto texture : textures)
|
|
{
|
|
if (texture.name.find(name) != std::string::npos)
|
|
{
|
|
std::cout << "CACHE: " << name << std::endl;
|
|
return texture.texture;
|
|
}
|
|
}
|
|
|
|
std::cout << "NOT FOUND: " << name << std::endl;
|
|
return nullptr;
|
|
}
|
|
|
|
// Obtiene una animación
|
|
animatedSprite_t *Resource::getAnimation(std::string name)
|
|
{
|
|
for (auto animation : animations)
|
|
{
|
|
if (animation.name.find(name) != std::string::npos)
|
|
{
|
|
std::cout << "CACHE: " << name << std::endl;
|
|
return animation.animation;
|
|
}
|
|
}
|
|
|
|
std::cout << "NOT FOUND: " << name << std::endl;
|
|
return nullptr;
|
|
} |