Primera implementación de la clase asset

This commit is contained in:
2021-09-08 18:26:22 +02:00
parent a0b14f5071
commit 94a06dcc2d
7 changed files with 114 additions and 123 deletions

View File

@@ -3,6 +3,7 @@
// Constructor
Asset::Asset(std::string path)
{
mExecutablePath = path;
}
// Destructor
@@ -11,10 +12,56 @@ Asset::~Asset()
}
// Añade un elemento a la lista
void Asset::add(std::string file, enum assetType type)
void Asset::add(std::string file, enum assetType type, bool required)
{
item_t temp;
temp.file = file;
temp.file = mExecutablePath + "/.." + file;
temp.type = type;
temp.required = required;
mFileList.push_back(temp);
}
// Devuelve un elemento de la lista a partir de una cadena
std::string Asset::get(std::string text)
{
for (int i = 0; i < mFileList.size(); i++)
if (mFileList[i].file.find(text) != std::string::npos)
return mFileList[i].file;
return "";
}
// Comprueba que existen todos los elementos
bool Asset::check()
{
bool success = true;
for (int i = 0; i < mFileList.size(); i++)
if (mFileList[i].required)
success &= checkFile(mFileList[i].file);
return success;
}
// Comprueba que existe un fichero
bool Asset::checkFile(std::string path)
{
bool success = true;
// Comprueba si existe el fichero
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "r+b");
if (file != NULL)
{
printf("Checking file %-20s [OK]\n", filename.c_str());
SDL_RWclose(file);
}
else
{
printf("Checking file %-20s [ERROR]\n", filename.c_str());
success = false;
}
return success;
}