mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
ACHIEVEMENTS: Add API methods that are easy to use
This commit is contained in:
parent
57e13c641e
commit
6ed025dd89
@ -40,6 +40,17 @@ AchievementsManager::AchievementsManager() {
|
||||
AchievementsManager::~AchievementsManager() {
|
||||
}
|
||||
|
||||
bool AchievementsManager::setActiveDomain(const AchievementsInfo &info) {
|
||||
if (info.appId.empty()) {
|
||||
unsetActiveDomain();
|
||||
return false;
|
||||
}
|
||||
|
||||
_descriptions = info.descriptions;
|
||||
|
||||
return setActiveDomain(info.platform, info.appId);
|
||||
}
|
||||
|
||||
bool AchievementsManager::setActiveDomain(AchievementsPlatform platform, const String &appId) {
|
||||
String prefix = platform == STEAM_ACHIEVEMENTS ? "steam-" + appId :
|
||||
platform == GALAXY_ACHIEVEMENTS ? "galaxy-" + appId :
|
||||
@ -70,10 +81,31 @@ bool AchievementsManager::unsetActiveDomain() {
|
||||
delete _iniFile;
|
||||
_iniFile = nullptr;
|
||||
|
||||
_descriptions.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AchievementsManager::setAchievement(const String &id) {
|
||||
if (!isReady()) {
|
||||
return false;
|
||||
}
|
||||
if (isAchieved(id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String displayedMessage = id;
|
||||
for (uint32 i = 0; i < _descriptions.size(); i++) {
|
||||
if (strcmp(_descriptions[i].id, id.c_str()) == 0) {
|
||||
displayedMessage = _descriptions[i].title;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return setAchievement(id, displayedMessage);
|
||||
}
|
||||
|
||||
bool AchievementsManager::setAchievement(const String &id, const String &displayedMessage) {
|
||||
if (!isReady()) {
|
||||
return false;
|
||||
|
@ -81,12 +81,19 @@ public:
|
||||
~AchievementsManager();
|
||||
|
||||
/**
|
||||
* Set a platform and application ID as active domain.
|
||||
* (DEPRECATED) Set a platform and application ID as active domain.
|
||||
*
|
||||
* @param[in] platform Achievements platform.
|
||||
* @param[in] appId Achievements application ID of the given platform.
|
||||
*/
|
||||
bool setActiveDomain(AchievementsPlatform platform, const String &appId);
|
||||
|
||||
/**
|
||||
* Set a platform and application ID as active domain, store messages texts.
|
||||
*
|
||||
* @param[in] info Achievements platform, application ID and messages information.
|
||||
*/
|
||||
bool setActiveDomain(const AchievementsInfo &info);
|
||||
bool unsetActiveDomain(); //!< Unset the current active domain.
|
||||
bool isReady() const { return _iniFile != nullptr; } //!< Check whether the domain is ready.
|
||||
|
||||
@ -95,13 +102,19 @@ public:
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Set an achievement.
|
||||
/** (DEPRECATED) Set an achievement.
|
||||
*
|
||||
* @param[in] id Internal ID of the achievement.
|
||||
* @param[in] displayedMessage Message displayed when the achievement is achieved.
|
||||
*/
|
||||
bool setAchievement(const String &id, const String &displayedMessage);
|
||||
|
||||
/** Set an achievement. Message is automatically displayed with text from active domain.
|
||||
*
|
||||
* @param[in] id Internal ID of the achievement.
|
||||
*/
|
||||
bool setAchievement(const String &id);
|
||||
|
||||
/**
|
||||
* Set an achievement as achieved.
|
||||
*
|
||||
@ -167,6 +180,7 @@ public:
|
||||
private:
|
||||
INIFile *_iniFile;
|
||||
String _iniFileName;
|
||||
Common::Array<AchievementDescription> _descriptions;
|
||||
};
|
||||
|
||||
/** Shortcut for accessing the Achievements Manager. */
|
||||
|
Loading…
Reference in New Issue
Block a user