1 | #include "Highscore.h" |
---|
2 | |
---|
3 | #include "core/CoreIncludes.h" |
---|
4 | #include "core/config/ConfigValueIncludes.h" |
---|
5 | #include "core/singleton/ScopedSingletonIncludes.h" |
---|
6 | #include "infos/PlayerInfo.h" |
---|
7 | #include "util/Convert.h" |
---|
8 | |
---|
9 | namespace orxonox |
---|
10 | { |
---|
11 | ManageScopedSingleton(Highscore, ScopeID::ROOT, false); |
---|
12 | RegisterClassNoArgs(Highscore); |
---|
13 | |
---|
14 | Highscore::Highscore() |
---|
15 | { |
---|
16 | RegisterObject(Highscore); |
---|
17 | this->setConfigValues(); |
---|
18 | } |
---|
19 | |
---|
20 | /** |
---|
21 | * @brief set the config values in the orxonox.ini file |
---|
22 | */ |
---|
23 | void Highscore::setConfigValues() |
---|
24 | { |
---|
25 | SetConfigValue(highscores_, std::vector<std::string>()).description("Highscores saved as vector"); |
---|
26 | } |
---|
27 | |
---|
28 | /** |
---|
29 | * @brief Returns highest score of given game, if exists. |
---|
30 | * Else returns -1. |
---|
31 | */ |
---|
32 | int Highscore::getHighestScoreOfGame(const std::string& game){ |
---|
33 | const std::string delimiter = "./."; //score save as "Playername./.game./.score" |
---|
34 | int best = -1; |
---|
35 | //check for the highest Score of given game |
---|
36 | for (std::string score : this->highscores_) |
---|
37 | { |
---|
38 | //filter the game string from given highscore |
---|
39 | score.erase(0, score.find(delimiter) + delimiter.length()); |
---|
40 | if(game.compare(score.substr(0,score.find(delimiter))) == 0){ |
---|
41 | score.erase(0, score.find(delimiter) + delimiter.length()); |
---|
42 | int possibleBest = multi_cast<int>(score); |
---|
43 | if(possibleBest > best) best = possibleBest; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | return best; |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * @brief stores a new highscore in the orxonox.ini file |
---|
53 | */ |
---|
54 | void Highscore::storeHighscore(const std::string& level, int points, PlayerInfo* player){ |
---|
55 | ModifyConfigValue(highscores_, add, player->getName() + "./." + level + "./." + multi_cast<std::string>(points)); |
---|
56 | } |
---|
57 | } |
---|