1 #include "stdafx.h"
2 #include "retired_games.h"
3
4
getAllGames() const5 const vector<RetiredGames::RetiredGame>& RetiredGames::getAllGames() const {
6 return games;
7 }
8
setActive(int num,bool b)9 void RetiredGames::setActive(int num, bool b) {
10 if (b)
11 active.insert(num);
12 else
13 active.erase(num);
14 }
15
isActive(int num) const16 bool RetiredGames::isActive(int num) const {
17 return active.count(num);
18 }
19
getNumActive() const20 int RetiredGames::getNumActive() const {
21 return active.size();
22 }
23
getActiveGames() const24 vector<RetiredGames::RetiredGame> RetiredGames::getActiveGames() const {
25 vector<RetiredGame> ret;
26 for (int i : active)
27 ret.push_back(games[i]);
28 return ret;
29 }
30
addLocal(const SavedGameInfo & game,const SaveFileInfo & file)31 void RetiredGames::addLocal(const SavedGameInfo& game, const SaveFileInfo& file) {
32 games.push_back({game, file, 0, 0});
33 ++numLocal;
34 }
35
addOnline(const SavedGameInfo & game,const SaveFileInfo & file,int total,int won)36 void RetiredGames::addOnline(const SavedGameInfo& game, const SaveFileInfo& file, int total, int won) {
37 for (int i : All(games))
38 if (games[i].fileInfo.filename == file.filename) {
39 games[i].numTotal = total;
40 games[i].numWon = won;
41 return;
42 }
43 games.push_back({game, file, total, won});
44 }
45
sort()46 void RetiredGames::sort() {
47 auto compare = [] (const RetiredGame& g1, const RetiredGame& g2) { return g1.numTotal > g2.numTotal; };
48 std::sort(games.begin(), games.begin() + numLocal, compare);
49 std::sort(games.begin() + numLocal, games.end(), compare);
50 }
51
getNumLocal() const52 int RetiredGames::getNumLocal() const {
53 return numLocal;
54 }
55