#include "Highscore.h" #include #include "core/CoreIncludes.h" #include "core/config/ConfigValueIncludes.h" #include "core/singleton/ScopedSingletonIncludes.h" namespace orxonox { ManageScopedSingleton(Highscore, ScopeID::ROOT, false); RegisterClassNoArgs(Highscore); Highscore::Highscore() { RegisterObject(Highscore); this->setConfigValues(); } /** * @brief set the config values in the orxonox.ini file */ void Highscore::setConfigValues() { SetConfigValue(highscores_, std::vector()).description("Highscores saved as vector"); SetConfigValue(playerName_, "Player").description("Name of the player"); } /** * @brief Returns highest score of given game, if exists. * Else returns -1. */ int Highscore::getHighestScoreOfGame(std::string game){ std::string delimiter = "./."; //score save as "Playername./.game./.score" int best = -1; //check for the highest Score of given game for (std::string score : this->highscores_) { //filter the game string from given highscore score.erase(0, score.find(delimiter) + delimiter.length()); if(game.compare(score.substr(0,score.find(delimiter))) == 0){ score.erase(0, score.find(delimiter) + delimiter.length()); int possibleBest = std::stoi(score); if(possibleBest > best) best = possibleBest; } } return best; } /** * @brief stores a new highscore in the orxonox.ini file */ void Highscore::storeHighscore(std::string level, int points){ ModifyConfigValue(highscores_, add, playerName_+"./."+level+"./."+std::to_string(points)); } }