forked from jaildesigner-jailgames/jaildoctors_dilemma
Primera implementación de la clase asset
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user