Mania++
 All Classes Functions Variables Pages
Map.h
1 #ifndef MAP_H_
2 #define MAP_H_
3 
4 #include "../GbxRemote/Response/GbxResponse.h"
5 
6 //* Map
10 struct Map
11 {
12  // === Mania++ information ===
13  int Id = 0;
15  // === Basic information ===
16  std::string UId;
17  std::string Name;
18  std::string FileName;
19  std::string Environment;
20  std::string Author;
22  int GoldTime;
25  std::string MapType;
26  std::string MapStyle;
28  // === Detailed information ===
29  std::string Mood;
30  int BronzeTime;
31  int SilverTime;
32  int AuthorTime;
34  bool LapRace;
35  int NbLaps;
41  Map()
42  {
43 
44  }
45 
51  Map(std::map<std::string, GbxResponseParameter> serverStruct)
52  {
53  if(serverStruct.find("UId") != serverStruct.end())
54  {
55  setBasicInfo(serverStruct);
56  }
57  }
58 
64  void MapDetailed(std::map<std::string, GbxResponseParameter> serverStruct)
65  {
66  if(serverStruct.find("Mood") != serverStruct.end())
67  {
68  setDetailedInfo(serverStruct);
69  }
70  }
71 
77  void CopyDetailedMap(Map map)
78  {
79  if(!map.Mood.empty())
80  {
81  Mood = map.Mood;
82  BronzeTime = map.BronzeTime;
83  SilverTime = map.SilverTime;
84  AuthorTime = map.AuthorTime;
85 
86  LapRace = map.LapRace;
87  NbLaps = map.NbLaps;
89  }
90  }
91 
97  void SetId(int id)
98  {
99  Id = id;
100  }
101 
102 private:
108  void setBasicInfo(std::map<std::string, GbxResponseParameter> serverStruct)
109  {
110  UId = serverStruct.find("UId")->second.GetString();
111  Name = serverStruct.find("Name")->second.GetString();
112  FileName = serverStruct.find("FileName")->second.GetString();
113  Environment = serverStruct.find("Environnement")->second.GetString();
114  Author = serverStruct.find("Author")->second.GetString();
115 
116  GoldTime = atoi(serverStruct.find("GoldTime")->second.GetString().c_str());
117  CopperPrice = atoi(serverStruct.find("CopperPrice")->second.GetString().c_str());
118 
119  MapType = serverStruct.find("MapType")->second.GetString();
120  MapStyle = serverStruct.find("MapStyle")->second.GetString();
121  }
122 
128  void setDetailedInfo(std::map<std::string, GbxResponseParameter> serverStruct)
129  {
130  setBasicInfo(serverStruct);
131 
132  Mood = serverStruct.find("Mood")->second.GetString();
133  BronzeTime = atoi(serverStruct.find("BronzeTime")->second.GetString().c_str());
134  SilverTime = atoi(serverStruct.find("SilverTime")->second.GetString().c_str());
135  AuthorTime = atoi(serverStruct.find("AuthorTime")->second.GetString().c_str());
136 
137  std::istringstream(serverStruct.find("LapRace")->second.GetString()) >> LapRace;
138  NbLaps = atoi(serverStruct.find("NbLaps")->second.GetString().c_str());
139  NbCheckpoints = atoi(serverStruct.find("NbCheckpoints")->second.GetString().c_str());
140  }
141 };
142 
143 #endif // MAP_H_
void setBasicInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the basic map information from the struct.
Definition: Map.h:108
Map()
Constructs a Map object without input.
Definition: Map.h:41
std::string Mood
Map mood (setting).
Definition: Map.h:29
bool LapRace
Map is multi-lap.
Definition: Map.h:34
std::string FileName
File name.
Definition: Map.h:18
int NbCheckpoints
Number of checkpoints.
Definition: Map.h:36
int NbLaps
Number of laps.
Definition: Map.h:35
std::string MapStyle
Map style (self-entered).
Definition: Map.h:26
int CopperPrice
Copper price.
Definition: Map.h:23
Map(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Map.h:51
Contains all information about a map in easy-to-use format.
Definition: Map.h:10
void CopyDetailedMap(Map map)
Copies information from map object.
Definition: Map.h:77
int GoldTime
Time of the gold medal.
Definition: Map.h:22
std::string Author
Login of the author.
Definition: Map.h:20
std::string MapType
Type of the map.
Definition: Map.h:25
std::string UId
Unique map identifier.
Definition: Map.h:16
int BronzeTime
Time of the bronze medal.
Definition: Map.h:30
void MapDetailed(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Map.h:64
int SilverTime
Time of the silver medal.
Definition: Map.h:31
std::string Name
Map name.
Definition: Map.h:17
void SetId(int id)
Set database identifier value.
Definition: Map.h:97
std::string Environment
Game environment.
Definition: Map.h:19
int AuthorTime
Time set by the author.
Definition: Map.h:32
void setDetailedInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the detailed map information from the struct.
Definition: Map.h:128
int Id
Map identifier (on database).
Definition: Map.h:13