1 #ifdef PARSE_GAME
2 #include "stdafx.h"
3 #include "text_serialization.h"
4 #include "gzstream.h"
5 
6 #include "debug.h"
7 #include "util.h"
8 #include "parse_game.h"
9 #include "highscores.h"
10 #include "campaign_type.h"
11 #include "player_role.h"
12 #define ProgramOptions_no_colors
13 #include "extern/ProgramOptions.h"
14 
15 
16 const char delim = ',';
17 
getString(Highscores::Score score)18 static string getString(Highscores::Score score) {
19   return score.gameId + delim +
20       score.playerName + delim +
21       score.worldName + delim +
22       score.gameResult + delim +
23       ::toString<int>(score.gameWon) + delim +
24       ::toString(score.points) + delim +
25       ::toString(score.turns) + delim +
26       EnumInfo<CampaignType>::getString(score.campaignType) + delim +
27       EnumInfo<PlayerRole>::getString(score.playerRole) + delim +
28       ::toString(score.version);
29 }
30 
main(int argc,char * argv[])31 int main(int argc, char* argv[]) {
32   po::parser flags;
33   flags["help"].description("Print help");
34   flags["input"].type(po::string).description("Path a KeeperRL save file");
35   flags["display_name"].description("Print display name of the save file");
36   flags["serial_info"].description("Print serialized game info of the save file");
37   flags["info"].description("Print game info of the save file");
38   flags["highscores"].description("Print out highscores from file");
39   flags["version"].description("Print version the save file");
40   if (!flags.parseArgs(argc, argv))
41     return -1;
42   if (flags["help"].was_set() || !flags["input"].was_set()) {
43     std::cout << flags << endl;
44     return 0;
45   }
46   FilePath inputPath = FilePath::fromFullPath(flags["input"].get().string);
47   if (flags["highscores"].was_set()) {
48     vector<Highscores::Score> scores;
49     std::cerr << "Loading highscores from " << inputPath << std::endl;
50     CompressedInput in(inputPath.getPath());
51     in.getArchive() >> scores;
52     for (auto& score : scores)
53       std::cout << getString(score) << std::endl;
54   } else {
55     auto info = getNameAndVersion(inputPath);
56     if (flags["display_name"].was_set())
57       std::cout << info->first << endl;
58     if (flags["version"].was_set())
59       std::cout << info->second << endl;
60     if (flags["serial_info"].was_set()) {
61       auto savedInfo = getSavedGameInfo(inputPath);
62       TextOutput output;
63       output.getArchive() << *savedInfo;
64       std::cout << output.getStream().str() << endl;
65     }
66     if (flags["info"].was_set()) {
67       auto savedInfo = getSavedGameInfo(inputPath);
68       std::cout << savedInfo->getName() << endl;
69       for (auto& minion : savedInfo->getMinions())
70         std::cout << EnumInfo<ViewId>::getString(minion.viewId) << " level " << minion.level << endl;
71     }
72   }
73 }
74 
75 #endif
76