forked from jaildesigner-jailgames/jaildoctors_dilemma
Actualizada la clase asset
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
Asset::Asset(std::string path)
|
||||
{
|
||||
mExecutablePath = path;
|
||||
longest_name = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -19,6 +20,9 @@ void Asset::add(std::string file, enum assetType type, bool required)
|
||||
temp.type = type;
|
||||
temp.required = required;
|
||||
mFileList.push_back(temp);
|
||||
|
||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||
longest_name = SDL_max(longest_name, filename.size());
|
||||
}
|
||||
|
||||
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
||||
@@ -37,8 +41,20 @@ bool Asset::check()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
printf("\n** Checking files.\n");
|
||||
|
||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||
for (int type = 0; type < maxAssetType; type++)
|
||||
{
|
||||
// Comprueba si hay ficheros de ese tipo
|
||||
bool any = false;
|
||||
|
||||
for (int i = 0; i < mFileList.size(); i++)
|
||||
if ((mFileList[i].required) && (mFileList[i].type == type))
|
||||
any = true;
|
||||
|
||||
// Si hay ficheros de ese tipo, comprueba si existen
|
||||
if (any)
|
||||
{
|
||||
printf("\n>> %s FILES\n", getTypeName(type).c_str());
|
||||
|
||||
@@ -46,6 +62,7 @@ bool Asset::check()
|
||||
if ((mFileList[i].required) && (mFileList[i].type == type))
|
||||
success &= checkFile(mFileList[i].file);
|
||||
}
|
||||
}
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
@@ -59,7 +76,8 @@ bool Asset::check()
|
||||
// Comprueba que existe un fichero
|
||||
bool Asset::checkFile(std::string path)
|
||||
{
|
||||
bool success = true;
|
||||
bool success = false;
|
||||
std::string result = "ERROR";
|
||||
|
||||
// Comprueba si existe el fichero
|
||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||
@@ -67,14 +85,13 @@ bool Asset::checkFile(std::string path)
|
||||
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
||||
result = "OK";
|
||||
success = true;
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
||||
success = false;
|
||||
}
|
||||
|
||||
const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
|
||||
printf(s.c_str(), filename.c_str());
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -32,6 +33,8 @@ private:
|
||||
bool required; // Indica si es un fichero que debe de existir
|
||||
};
|
||||
|
||||
int longest_name; // Contiene la longitud del nombre de fichero mas largo
|
||||
|
||||
std::vector<item_t> mFileList;
|
||||
std::string mExecutablePath;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user