diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 42137ce9b..80c4e4cdd 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -60,74 +60,15 @@ UnlockManager::UnlockManager() // Read challenges from .../data/tracks/* // -------------------------------------- const std::vector *all_track_dirs = track_manager->getAllTrackDirs(); - for(std::vector::const_iterator dir=all_track_dirs->begin(); - dir!=all_track_dirs->end(); dir++) - { - std::set all_files; - file_manager->listFiles(all_files, *dir, /*is_full_path*/ true); - for(std::set::iterator file=all_files.begin(); - file!=all_files.end(); file++) - { - if(!StringUtils::hasSuffix(*file,".challenge")) continue; - std::string filename=*dir+"/"+*file; - FILE *f=fopen(filename.c_str(), "r"); - if(f) - { - fclose(f); - ChallengeData* newChallenge = NULL; - try - { - newChallenge = new ChallengeData(filename); - } - catch (std::runtime_error& ex) - { - std::cerr << "\n/!\\ An error occurred while loading challenge file '" << filename << "' : " - << ex.what() << " : challenge will be ignored.\n\n"; - continue; - } - addChallenge(newChallenge); - - } // if file - } // for file in files - } // for dir in all_track_dirs - - // Load challenges from .../data/karts (FIXME: the code below is just copied and pasted from above xD) - // ----------------------------------- - const std::vector *all_kart_dirs = - kart_properties_manager->getAllKartDirs(); - - // Find out which characters are available and load them - for(std::vector::const_iterator dir = all_kart_dirs->begin(); - dir != all_kart_dirs->end(); dir++) - { - std::set all_files; - file_manager->listFiles(all_files, *dir, /*is_full_path*/ true); - for(std::set::iterator file=all_files.begin(); - file!=all_files.end(); file++) - { - if(!StringUtils::hasSuffix(*file,".challenge")) continue; - std::string filename=*dir+"/"+*file; - FILE *f=fopen(filename.c_str(), "r"); - if(f) - { - fclose(f); - - ChallengeData* newChallenge = NULL; - try - { - newChallenge = new ChallengeData(filename); - } - catch (std::runtime_error& ex) - { - std::cerr << "\n/!\\ An error occurred while loading challenge file '" << filename << "' : " - << ex.what() << " : challenge will be ignored.\n\n"; - continue; - } - addChallenge(newChallenge); - } // if file - } // for file in files - } // for dir in all_karts_dirs - + readAllChallengesInDirs(all_track_dirs); + + + // Read challenges from .../data/karts/* + // -------------------------------------- + const std::vector *all_kart_dirs = kart_properties_manager->getAllKartDirs(); + readAllChallengesInDirs(all_kart_dirs); + + // Challenges from .../data/grandprix // ---------------------------------- file_manager->listFiles(result, "data/grandprix"); @@ -140,7 +81,6 @@ UnlockManager::UnlockManager() // Hard coded challenges can be added here. - computeActive(); //FIXME: 'load' calls 'computeActive', not sure this call here is needed load(); } // UnlockManager @@ -156,6 +96,45 @@ UnlockManager::~UnlockManager() // sfx_manager->deleteSFX(m_locked_sound); } // ~UnlockManager +//----------------------------------------------------------------------------- + +void UnlockManager::readAllChallengesInDirs(const std::vector* all_dirs) +{ + for(std::vector::const_iterator dir = all_dirs->begin(); + dir != all_dirs->end(); dir++) + { + std::set all_files; + file_manager->listFiles(all_files, *dir, /*is_full_path*/ true); + + for(std::set::iterator file = all_files.begin(); + file != all_files.end(); file++) + { + if (!StringUtils::hasSuffix(*file,".challenge")) continue; + + std::string filename = *dir + "/" + *file; + + FILE* f = fopen(filename.c_str(), "r"); + if (f) + { + fclose(f); + ChallengeData* newChallenge = NULL; + try + { + newChallenge = new ChallengeData(filename); + } + catch (std::runtime_error& ex) + { + std::cerr << "\n/!\\ An error occurred while loading challenge file '" << filename << "' : " + << ex.what() << " : challenge will be ignored.\n\n"; + continue; + } + addChallenge(newChallenge); + } // if file + + } // for file in files + } // for dir in all_track_dirs +} + //----------------------------------------------------------------------------- void UnlockManager::addChallenge(Challenge *c) { diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index 9d27029d5..eb6df3fc7 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -46,7 +46,8 @@ private: void load (); void unlockFeature (Challenge* c, bool do_save=true); - + void readAllChallengesInDirs(const std::vector* all_dirs); + public: UnlockManager (); ~UnlockManager ();