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  void DefHairColor();
46 };
47 
48 struct SavedScene
49 {
50  std::string path;
51  std::string name;
52 
53  SavedScene(std::string path = "", std::string name = "")
54  : path(path), name(name)
55  {}
56 };
57 
59 {
60 public:
61  // Creates CPlayerProfile instance and loads player save data
62  CPlayerProfile(std::string playerName);
63  ~CPlayerProfile();
64  // Returns last used player name, or "Player" if none found
65  static std::string GetLastName();
66  // Returnslist of possible player names
67  static std::vector<std::string> GetPlayerList();
68 
69  // Creates player save directory (if needed)
70  bool Create();
71  // Removes player save directory
72  bool Delete();
73 
75  std::string GetName();
76 
78  std::string GetSaveDir();
80  std::string GetSaveFile(std::string filename);
81 
83  void IncrementLevelTryCount(LevelCategory cat, int chap, int rank);
85  int GetLevelTryCount(LevelCategory cat, int chap, int rank);
87  void SetLevelPassed(LevelCategory cat, int chap, int rank, bool bPassed);
89  bool GetLevelPassed(LevelCategory cat, int chap, int rank);
91  int GetChapPassed(LevelCategory cat);
92 
94  void SetSelectedChap(LevelCategory category, int chap);
96  int GetSelectedChap(LevelCategory category);
98  void SetSelectedRank(LevelCategory category, int rank);
100  int GetSelectedRank(LevelCategory category);
101 
103  int GetFreeGameBuildUnlock();
105  void SetFreeGameBuildUnlock(int freeBuild);
107  int GetFreeGameResearchUnlock();
109  void SetFreeGameResearchUnlock(int freeResearch);
110 
112  PlayerApperance& GetApperance();
114  void LoadApperance();
116  void SaveApperance();
117 
119  bool HasAnySavedScene();
121  std::vector<SavedScene> GetSavedSceneList();
123  void SaveScene(std::string dir, std::string info);
125  void LoadScene(std::string dir);
127  bool DeleteScene(std::string dir);
128 
129 protected:
131  void LoadFinishedLevels(LevelCategory category);
133  void SaveFinishedLevels(LevelCategory category);
134 
136  void LoadFreeGameUnlock();
138  void SaveFreeGameUnlock();
139 
140 protected:
142  std::string m_playerName;
143 
145  std::map<LevelCategory, bool> m_levelInfoLoaded;
147  std::map<LevelCategory, std::map<int, std::map<int, LevelInfo>>> m_levelInfo;
149  std::map<LevelCategory, int> m_selectChap;
151  std::map<LevelCategory, int> m_selectRank;
152 
159 
162 };
std::map< LevelCategory, bool > m_levelInfoLoaded
Is finished levels file loaded already?
Definition: player_profile.h:145
std::map< LevelCategory, int > m_selectRank
Selected level rank.
Definition: player_profile.h:151
Definition: player_profile.h:36
std::string m_playerName
Player name.
Definition: player_profile.h:142
std::map< LevelCategory, std::map< int, std::map< int, LevelInfo > > > m_levelInfo
Level completion info.
Definition: player_profile.h:147
Color structs and related functions.
int m_freegameBuild
Buildings unlocked for free game.
Definition: player_profile.h:156
Definition: player_profile.h:30
PlayerApperance m_apperance
Player apperance.
Definition: player_profile.h:161
int m_freegameResearch
Researches unlocked for free game.
Definition: player_profile.h:158
Definition: player_profile.h:48
Definition: player_profile.h:58
bool m_freegameLoaded
Is freegame save file loaded already?
Definition: player_profile.h:154
std::map< LevelCategory, int > m_selectChap
Selected level chapter.
Definition: player_profile.h:149
RGBA color.
Definition: color.h:39