ScummVM API documentation
achievements.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef COMMON_ACHIEVEMENTS_H
23 #define COMMON_ACHIEVEMENTS_H
24 
25 #include "common/array.h"
26 #include "common/formats/ini-file.h"
27 #include "common/hashmap.h"
28 #include "common/singleton.h"
29 #include "common/str.h"
30 
31 namespace Common {
32 
47  STEAM_ACHIEVEMENTS,
48  GALAXY_ACHIEVEMENTS,
49  UNK_ACHIEVEMENTS = -1
50 };
51 
59 };
60 
68  bool isHidden;
69 };
70 
77 
78  AchievementsInfo() { platform = Common::UNK_ACHIEVEMENTS; }
79 };
80 
88  const char *gameId;
90  const char *appId;
91 };
92 
93 #define ACHIEVEMENT_DESC_TABLE_END_MARKER \
94  { nullptr, Common::UNK_ACHIEVEMENTS, nullptr }
95 
101 class AchievementsManager : public Singleton<AchievementsManager> {
102 public:
105 
112  bool setActiveDomain(const AchievementsInfo &info);
113  bool unsetActiveDomain();
114  bool isReady() const { return _iniFile != nullptr; }
115 
125  bool setAchievement(const String &id);
126 
132  bool isAchieved(const String &id) const;
133 
139  bool clearAchievement(const String &id);
140 
153  int getStatInt(const String &id) const;
154 
161  bool setStatInt(const String &id, int value);
162 
168  float getStatFloat(const String &id) const;
169 
176  bool setStatFloat(const String &id, float value);
177 
183  const String getStatRaw(const String &id) const;
184 
191  float getAverageRateStatFloat(const String &id) const;
192 
200  bool updateAverageRateStatFloat(const String &id, float count, float times);
201 
208  bool resetAllAchievements();
209  bool resetAllStats();
210 
225  bool setSpecialString(const String &id, const String &value);
226 
238  uint16 getAchievementCount() const;
239 
246  const AchievementDescription *getAchievementDescription(uint16 index) const;
247 
252  uint16 getStatCount() const;
253 
260  const StatDescription *getStatDescription(uint16 index) const;
261 
264 private:
265  String getCurrentLang() const;
266  bool loadAchievementsData(const char *platform, const char *appId);
267 
268  float getStatFloatEx(const String &id, const String &section) const;
269  bool setStatFloatEx(const String &id, float value, const String &section) const;
270 
271  INIFile *_iniFile;
272  String _iniFileName;
275 };
276 
278 #define AchMan Common::AchievementsManager::instance()
279 
282 } // End of namespace Common
283 
284 #endif // #ifndef COMMON_ACHIEVEMENTS_MANAGER_H
Common::String appId
Achievements application ID of the given platform.
Definition: achievements.h:76
bool isReady() const
Check whether the domain is ready.
Definition: achievements.h:114
Definition: str.h:59
Definition: achievements.h:64
String id
Achievement internal ID, such as "ACHIEVEMENT_TIMING".
Definition: achievements.h:65
String comment
Optional stat comment, such as "Items Thrown".
Definition: achievements.h:57
Definition: array.h:52
Definition: achievements.h:87
bool isHidden
Whether the achievement is hidden.
Definition: achievements.h:68
String title
Achievement displayed text, such as "Marathon Runner".
Definition: achievements.h:66
Definition: hashmap.h:85
Definition: algorithm.h:29
String id
Stat internal ID, such as "ITEMS_THROWN".
Definition: achievements.h:56
AchievementsPlatform
Definition: achievements.h:46
String comment
Optional achievement hint or comment, such as "Finish the game in less than 4 hours".
Definition: achievements.h:67
Definition: achievements.h:55
Definition: ini-file.h:58
Definition: achievements.h:101
Definition: achievements.h:74
Common::AchievementsPlatform platform
Achievements platform, such as "STEAM_ACHIEVEMENTS".
Definition: achievements.h:75
String start
Stat default value, such as "0".
Definition: achievements.h:58
Definition: singleton.h:42