Colobot
player_profile.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 #include "graphics/core/color.h"
23 
24 #include "level/level_category.h"
25 
26 #include <string>
27 #include <map>
28 #include <vector>
29 
30 struct LevelInfo
31 {
32  int numTry = 0;
33  bool bPassed = false;
34 };
35 
37 {
38  int face = 0; // face
39  int glasses = 0; // glasses
40  Gfx::Color colorHair; // hair color
41  Gfx::Color colorCombi; // spacesuit volor
42  Gfx::Color colorBand; // strips color
43 
44  void DefPerso();
45 };
46 
47 struct SavedScene
48 {
49  std::string path;
50  std::string name;
51 
52  SavedScene(std::string path = "", std::string name = "")
53  : path(path), name(name)
54  {}
55 };
56 
58 {
59 public:
60  // Creates CPlayerProfile instance and loads player save data
61  CPlayerProfile(std::string playerName);
62  ~CPlayerProfile();
63  // Returns last used player name, or "Player" if none found
64  static std::string GetLastName();
65  // Returnslist of possible player names
66  static std::vector<std::string> GetPlayerList();
67 
68  // Creates player save directory (if needed)
69  bool Create();
70  // Removes player save directory
71  bool Delete();
72 
74  std::string GetName();
75 
77  std::string GetSaveDir();
79  std::string GetSaveFile(std::string filename);
80 
82  void IncrementLevelTryCount(LevelCategory cat, int chap, int rank);
84  int GetLevelTryCount(LevelCategory cat, int chap, int rank);
86  void SetLevelPassed(LevelCategory cat, int chap, int rank, bool bPassed);
88  bool GetLevelPassed(LevelCategory cat, int chap, int rank);
90  int GetChapPassed(LevelCategory cat);
91 
93  void SetSelectedChap(LevelCategory category, int chap);
95  int GetSelectedChap(LevelCategory category);
97  void SetSelectedRank(LevelCategory category, int rank);
99  int GetSelectedRank(LevelCategory category);
100 
102  int GetFreeGameBuildUnlock();
104  void SetFreeGameBuildUnlock(int freeBuild);
106  int GetFreeGameResearchUnlock();
108  void SetFreeGameResearchUnlock(int freeResearch);
109 
111  PlayerApperance& GetApperance();
113  void LoadApperance();
115  void SaveApperance();
116 
118  bool HasAnySavedScene();
120  std::vector<SavedScene> GetSavedSceneList();
122  void SaveScene(std::string dir, std::string info);
124  void LoadScene(std::string dir);
126  bool DeleteScene(std::string dir);
127 
128 protected:
130  void LoadFinishedLevels(LevelCategory category);
132  void SaveFinishedLevels(LevelCategory category);
133 
135  void LoadFreeGameUnlock();
137  void SaveFreeGameUnlock();
138 
139 protected:
141  std::string m_playerName;
142 
144  std::map<LevelCategory, bool> m_levelInfoLoaded;
146  std::map<LevelCategory, std::map<int, std::map<int, LevelInfo>>> m_levelInfo;
148  std::map<LevelCategory, int> m_selectChap;
150  std::map<LevelCategory, int> m_selectRank;
151 
158 
161 };
std::map< LevelCategory, bool > m_levelInfoLoaded
Is finished levels file loaded already?
Definition: player_profile.h:144
std::map< LevelCategory, int > m_selectRank
Selected level rank.
Definition: player_profile.h:150
Definition: player_profile.h:36
std::string m_playerName
Player name.
Definition: player_profile.h:141
std::map< LevelCategory, std::map< int, std::map< int, LevelInfo > > > m_levelInfo
Level completion info.
Definition: player_profile.h:146
Color structs and related functions.
int m_freegameBuild
Buildings unlocked for free game.
Definition: player_profile.h:155
Definition: player_profile.h:30
PlayerApperance m_apperance
Player apperance.
Definition: player_profile.h:160
int m_freegameResearch
Researches unlocked for free game.
Definition: player_profile.h:157
Definition: player_profile.h:47
Definition: player_profile.h:57
bool m_freegameLoaded
Is freegame save file loaded already?
Definition: player_profile.h:153
std::map< LevelCategory, int > m_selectChap
Selected level chapter.
Definition: player_profile.h:148
RGBA color.
Definition: color.h:39