ACHIEVEMENTS: Add an API to store platform-specific special strings like ClientSecret

This commit is contained in:
lb_ii 2021-05-30 04:12:09 +03:00 committed by lolbot-iichan
parent 772a38588c
commit 6513bab7af
2 changed files with 32 additions and 2 deletions

View File

@ -46,11 +46,11 @@ bool AchievementsManager::setActiveDomain(const AchievementsInfo &info) {
return false;
}
const char* prefix = info.platform == STEAM_ACHIEVEMENTS ? "steam" :
const char* platform = info.platform == STEAM_ACHIEVEMENTS ? "steam" :
info.platform == GALAXY_ACHIEVEMENTS ? "galaxy" :
"achman";
String iniFileName = String::format("%s-%s.dat", prefix, info.appId.c_str());
String iniFileName = String::format("%s-%s.dat", platform, info.appId.c_str());
if (_iniFileName == iniFileName) {
return true;
@ -67,6 +67,9 @@ bool AchievementsManager::setActiveDomain(const AchievementsInfo &info) {
_descriptions = info.descriptions;
setSpecialString("platform", platform);
setSpecialString("gameId", info.appId);
return true;
}
@ -220,6 +223,17 @@ int AchievementsManager::getStatInt(String const &id) {
}
bool AchievementsManager::setSpecialString(String const &id, String const &value) {
if (!isReady()) {
return false;
}
_iniFile->setKey(id, "special", value);
_iniFile->saveToSaveFile(_iniFileName);
return 0;
}
bool AchievementsManager::resetAllAchievements() {
if (!isReady()) {
return false;

View File

@ -179,6 +179,22 @@ public:
/** @} */
/**
* @name Methods for storing platform-specific data
* @{
*/
/**
* Store provided key and value pair in additional section.
* May be useful for posting achievements to original platform.
*
* @param[in] id Internal ID of the achievement.
* @param[in] value Value to which the statistic is set.
*/
bool setSpecialString(const String &id, const String &value);
/** @} */
private:
float getStatFloatEx(const String &id, const String &section);
bool setStatFloatEx(const String &id, float value, const String &section);