1 | #include "Highscore.h" |
---|
2 | |
---|
3 | #include <vector> |
---|
4 | #include "core/CoreIncludes.h" |
---|
5 | #include "core/config/ConfigValueIncludes.h" |
---|
6 | #include "core/singleton/ScopedSingletonIncludes.h" |
---|
7 | |
---|
8 | namespace orxonox |
---|
9 | { |
---|
10 | |
---|
11 | ManageScopedSingleton(Highscore, ScopeID::ROOT, false); |
---|
12 | RegisterClassNoArgs(Highscore); |
---|
13 | |
---|
14 | Highscore::Highscore() |
---|
15 | { |
---|
16 | RegisterObject(Highscore); |
---|
17 | this->setConfigValues(); |
---|
18 | } |
---|
19 | |
---|
20 | void Highscore::setConfigValues() |
---|
21 | { |
---|
22 | SetConfigValue(highscores_, std::vector<std::string>()).description("HighscoreVektor"); |
---|
23 | } |
---|
24 | |
---|
25 | int Highscore::getHighestScoreOfGame(std::string game){ |
---|
26 | std::string delimiter = "./."; |
---|
27 | int best = -1; |
---|
28 | for (std::string score : this->highscores_) |
---|
29 | { |
---|
30 | |
---|
31 | score.erase(0, score.find(delimiter) + delimiter.length()); |
---|
32 | if(game.compare(score.substr(0,score.find(delimiter))) == 0){ |
---|
33 | score.erase(0, score.find(delimiter) + delimiter.length()); |
---|
34 | int possibleBest = std::stoi(score); |
---|
35 | if(possibleBest > best) best = possibleBest; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | } |
---|
40 | |
---|
41 | return best; |
---|
42 | |
---|
43 | } |
---|
44 | |
---|
45 | void Highscore::storeHighscore(std::string player, std::string level, int points){ |
---|
46 | ModifyConfigValue(highscores_, add, player+"./."+level+"./."+std::to_string(points)); |
---|
47 | } |
---|
48 | /* static std::string Highscore::getName(){ |
---|
49 | std::string result; |
---|
50 | result = Highscore::name_; |
---|
51 | return result; |
---|
52 | }*/ |
---|
53 | } |
---|