diff --git a/source/director.cpp b/source/director.cpp index 9a39fae..4c69480 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -114,7 +114,7 @@ void Director::init(Uint8 name) mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W); mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E); #endif - mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE + mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE mInput->bindGameController(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP); @@ -271,135 +271,59 @@ void Director::setFileList() mFileList[51] = mExecutablePath + "/" + "../media/lang/ba_BA.txt"; } -// Comprueba que todos los ficheros existen -bool Director::checkFileList() +// 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; - printf("Checking files...\n\n"); - - // Comprueba los ficheros de musica - printf(">> MUSIC FILES\n"); - if (success) - for (int i = 3; i < MAX_FILE_LIST; i++) + // 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) { - if (mFileList[i].find("/media/music/") != 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) { - 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); + 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 los ficheros de sonidos - printf("\n>> SOUND FILES\n"); - if (success) - for (int i = 3; i < MAX_FILE_LIST; i++) - { - if (mFileList[i].find("/media/sound/") != 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); - } - } +// Comprueba que todos los ficheros existen +bool Director::checkFileList() +{ + bool success = true; + printf("Checking files...\n"); - // Comprueba los ficheros con graficos - printf("\n>> BITMAP FILES\n"); if (success) - for (int i = 3; i < MAX_FILE_LIST; i++) - { - if (mFileList[i].find("/media/gfx/") != 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); - } - } + success &= checkFolder("MUSIC", "/media/music/"); - // Comprueba los ficheros con fuentes de texto - printf("\n>> FONT FILES\n"); if (success) - for (int i = 3; i < MAX_FILE_LIST; i++) - { - if (mFileList[i].find("/media/font/") != 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); - } - } + success &= checkFolder("SOUND", "/media/sound/"); - // Comprueba los ficheros con textos en diferentes idiomas - printf("\n>> LANG FILES\n"); if (success) - for (int i = 3; i < 100; i++) - { - if (mFileList[i].find("/media/lang/") != 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); - } - } + success &= checkFolder("GFX", "/media/gfx/"); + + if (success) + success &= checkFolder("FONT", "/media/font/"); + + if (success) + success &= checkFolder("LANG", "/media/lang/"); // Resultado if (success) diff --git a/source/director.h b/source/director.h index 85ad58c..53de0a9 100644 --- a/source/director.h +++ b/source/director.h @@ -89,6 +89,9 @@ private: // Ejecuta la seccion de juego donde se juega void runGame(); + // Comprueba los ficheros del vector de ficheros que coinciden con una ruta dada + bool checkFolder(std::string name, std::string path); + public: // Constructor Director(std::string path);