Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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 
105  void SetFreeGameBuildUnlock(int freeBuild);
109  void SetFreeGameResearchUnlock(int freeResearch);
110 
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 };
void SaveApperance()
Saves PlayerApperance structure.
Definition: player_profile.cpp:432
void SaveScene(std::string dir, std::string info)
Saves current scene status.
Definition: player_profile.cpp:499
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
PlayerApperance & GetApperance()
Returns a reference to PlayerApperance structure.
Definition: player_profile.cpp:397
Definition: player_profile.h:36
std::string GetName()
Returns player name.
Definition: player_profile.cpp:161
int GetSelectedRank(LevelCategory category)
Returns selected level from save file.
Definition: player_profile.cpp:244
std::string m_playerName
Player name.
Definition: player_profile.h:142
std::string GetSaveDir()
Returns player's save directory path.
Definition: player_profile.cpp:166
int GetFreeGameResearchUnlock()
Returns unlocked DoneResearch for free game.
Definition: player_profile.cpp:339
bool GetLevelPassed(LevelCategory cat, int chap, int rank)
Chenks if the level (or chapter, if rank=0) is passed.
Definition: player_profile.cpp:203
bool DeleteScene(std::string dir)
Delete saved scene.
Definition: player_profile.cpp:557
std::map< LevelCategory, std::map< int, std::map< int, LevelInfo > > > m_levelInfo
Level completion info.
Definition: player_profile.h:147
void LoadScene(std::string dir)
Loads scene.
Definition: player_profile.cpp:509
void SetFreeGameBuildUnlock(int freeBuild)
Saves unlocked EnableBuild for free game.
Definition: player_profile.cpp:333
void SetFreeGameResearchUnlock(int freeResearch)
Saves unlocked DoneResearch for free game.
Definition: player_profile.cpp:346
void IncrementLevelTryCount(LevelCategory cat, int chap, int rank)
Increments level try count.
Definition: player_profile.cpp:178
Color structs and related functions.
void SetSelectedRank(LevelCategory category, int rank)
Sets selected level for save file.
Definition: player_profile.cpp:238
bool HasAnySavedScene()
Returns true if player has at least one saved scene.
Definition: player_profile.cpp:460
int m_freegameBuild
Buildings unlocked for free game.
Definition: player_profile.h:156
Definition: player_profile.h:30
std::string GetSaveFile(std::string filename)
Returns path to file inside player's save directory.
Definition: player_profile.cpp:171
PlayerApperance m_apperance
Player apperance.
Definition: player_profile.h:161
int GetSelectedChap(LevelCategory category)
Returns selected chapter from save file.
Definition: player_profile.cpp:230
int m_freegameResearch
Researches unlocked for free game.
Definition: player_profile.h:158
Definition: player_profile.h:48
void SetSelectedChap(LevelCategory category, int chap)
Sets selected chapter for save file.
Definition: player_profile.cpp:224
Definition: player_profile.h:58
bool m_freegameLoaded
Is freegame save file loaded already?
Definition: player_profile.h:154
void SaveFreeGameUnlock()
Saves free game unlock state.
Definition: player_profile.cpp:379
void SaveFinishedLevels(LevelCategory category)
Saves LevelInfo data for given category.
Definition: player_profile.cpp:295
void SetLevelPassed(LevelCategory cat, int chap, int rank, bool bPassed)
Changes level passed status (also updates chapter passed status)
Definition: player_profile.cpp:191
int GetLevelTryCount(LevelCategory cat, int chap, int rank)
Returns try count for given level.
Definition: player_profile.cpp:184
void LoadApperance()
Loads PlayerApperance structure.
Definition: player_profile.cpp:402
std::vector< SavedScene > GetSavedSceneList()
Returns list of all saved scenes.
Definition: player_profile.cpp:473
int GetChapPassed(LevelCategory cat)
Returns the highest chapter accessible in the given category.
Definition: player_profile.cpp:210
std::map< LevelCategory, int > m_selectChap
Selected level chapter.
Definition: player_profile.h:149
RGBA color.
Definition: color.h:39
void LoadFreeGameUnlock()
Loads free game unlock state.
Definition: player_profile.cpp:352
void LoadFinishedLevels(LevelCategory category)
Loads LevelInfo data for given category.
Definition: player_profile.cpp:252
int GetFreeGameBuildUnlock()
Returns unlocked EnableBuild for free game.
Definition: player_profile.cpp:325