forked from jaildesigner-jailgames/jaildoctors_dilemma
Primera implementación de la clase asset
This commit is contained in:
@@ -10,19 +10,19 @@ Director::Director(std::string path)
|
||||
// Inicializa la ruta
|
||||
setExecutablePath(path);
|
||||
|
||||
// Establece la lista de ficheros
|
||||
setFileList();
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
mAsset = new Asset(mExecutablePath);
|
||||
|
||||
// Si falta algún fichero no inicies el programa
|
||||
// Establece la lista de ficheros
|
||||
setFileList();
|
||||
|
||||
// Si falta algún fichero no inicia el programa
|
||||
Uint8 section = PROG_SECTION_GAME;
|
||||
if (!checkFileList())
|
||||
if (!mAsset->check())
|
||||
section = PROG_SECTION_QUIT;
|
||||
|
||||
// Inicializa el objeto de idioma
|
||||
mLang = new Lang(mFileList);
|
||||
mLang = new Lang(mAsset);
|
||||
|
||||
// Crea el puntero a la estructura y carga el fichero de configuración
|
||||
mOptions = new options_t;
|
||||
@@ -39,7 +39,7 @@ Director::Director(std::string path)
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
mInput = new Input(mFileList[11]);
|
||||
mInput = new Input(mAsset->get("gamecontrollerdb.txt"));
|
||||
|
||||
// Inicializa SDL
|
||||
initSDL();
|
||||
@@ -187,91 +187,19 @@ bool Director::initSDL()
|
||||
// Crea el indice de ficheros
|
||||
void Director::setFileList()
|
||||
{
|
||||
// Inicializa el vector
|
||||
for (int i = 0; i < MAX_FILE_LIST; i++)
|
||||
mFileList[i] = "";
|
||||
|
||||
// Fuentes
|
||||
mFileList[0] = mExecutablePath + "/" + "../media/font/8bithud.png";
|
||||
mFileList[1] = mExecutablePath + "/" + "../media/font/8bithud.txt";
|
||||
mFileList[2] = mExecutablePath + "/" + "../media/font/nokia.png";
|
||||
mFileList[3] = mExecutablePath + "/" + "../media/font/nokia.txt";
|
||||
mFileList[4] = mExecutablePath + "/" + "../media/font/nokia2.png";
|
||||
mFileList[5] = mExecutablePath + "/" + "../media/font/nokia2.txt";
|
||||
mFileList[6] = mExecutablePath + "/" + "../media/font/smb2.png";
|
||||
mFileList[7] = mExecutablePath + "/" + "../media/font/smb2.txt";
|
||||
|
||||
// Textos
|
||||
mFileList[8] = mExecutablePath + "/" + "../media/lang/es_ES.txt";
|
||||
mFileList[9] = mExecutablePath + "/" + "../media/lang/en_UK.txt";
|
||||
mFileList[10] = mExecutablePath + "/" + "../media/lang/ba_BA.txt";
|
||||
|
||||
// DATA
|
||||
mFileList[11] = mExecutablePath + "/" + "../data/gamecontrollerdb.txt";
|
||||
mFileList[12] = mExecutablePath + "/" + "../data/config.bin";
|
||||
}
|
||||
|
||||
// Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada
|
||||
bool Director::checkFolder(std::string name, std::string path)
|
||||
{
|
||||
bool success = true;
|
||||
std::string p;
|
||||
std::string filename;
|
||||
SDL_RWops *file;
|
||||
|
||||
// Comprueba los ficheros de la carpeta
|
||||
printf("\n>> %s FILES\n", name.c_str());
|
||||
for (int i = 3; i < MAX_FILE_LIST; i++)
|
||||
{
|
||||
if (mFileList[i].find(path.c_str()) != std::string::npos)
|
||||
{
|
||||
p = mFileList[i].c_str();
|
||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
if (file != NULL)
|
||||
{
|
||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Comprueba que todos los ficheros existen
|
||||
bool Director::checkFileList()
|
||||
{
|
||||
bool success = true;
|
||||
printf("Checking files...\n");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("MUSIC", "/media/music/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("SOUND", "/media/sound/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("BITMAP", "/media/gfx/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("FONT", "/media/font/");
|
||||
|
||||
if (success)
|
||||
success &= checkFolder("LANG", "/media/lang/");
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
printf("\n** All files OK.\n\n");
|
||||
else
|
||||
printf("\n** A file is missing. Exiting.\n\n");
|
||||
|
||||
return success;
|
||||
mAsset->add("/media/font/8bithud.png", font);
|
||||
mAsset->add("/media/font/8bithud.txt", font);
|
||||
mAsset->add("/media/font/nokia.png", font);
|
||||
mAsset->add("/media/font/nokia.txt", font);
|
||||
mAsset->add("/media/font/nokia2.png", font);
|
||||
mAsset->add("/media/font/nokia2.txt", font);
|
||||
mAsset->add("/media/font/smb2.png", font);
|
||||
mAsset->add("/media/font/smb2.txt", font);
|
||||
mAsset->add("/media/lang/es_ES.txt", lang);
|
||||
mAsset->add("/media/lang/en_UK.txt", lang);
|
||||
mAsset->add("/media/lang/ba_BA.txt", lang);
|
||||
mAsset->add("/data/gamecontrollerdb.txt", data);
|
||||
mAsset->add("/data/config.bin", data, false);
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
@@ -290,7 +218,7 @@ bool Director::loadConfigFile()
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
const std::string p = mFileList[12];
|
||||
const std::string p = mAsset->get("config.bin");
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
|
||||
|
||||
@@ -359,7 +287,7 @@ bool Director::loadConfigFile()
|
||||
bool Director::saveConfigFile()
|
||||
{
|
||||
bool success = true;
|
||||
const std::string p = mFileList[12];
|
||||
const std::string p = mAsset->get("config.bin");
|
||||
std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
if (file != NULL)
|
||||
@@ -424,7 +352,7 @@ void Director::runTitle()
|
||||
|
||||
void Director::runGame()
|
||||
{
|
||||
mGame = new Game(mRenderer, mFileList, mLang, mInput);
|
||||
mGame = new Game(mRenderer, mAsset, mLang, mInput);
|
||||
setSection(mGame->run());
|
||||
delete mGame;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user