mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-28 16:49:58 -06:00
Added TallyScore method to AchievementManager
Added a TallyScore method to AchievementManager to calculate the player's current scores (soft and hard) against the total number of points across all achievements. Includes a PointSpread structure to hold all points and counts. The Unlock Map now includes point values for each achievement to aid in this calculation; this is populated at insert time, and Unofficial achievements are tallied as zero.
This commit is contained in:
@ -185,8 +185,11 @@ void AchievementManager::ActivateDeactivateAchievements()
|
||||
bool encore = Config::Get(Config::RA_ENCORE_ENABLED);
|
||||
for (u32 ix = 0; ix < m_game_data.num_achievements; ix++)
|
||||
{
|
||||
auto iter =
|
||||
m_unlock_map.insert({m_game_data.achievements[ix].id, UnlockStatus{.game_data_index = ix}});
|
||||
u32 points = (m_game_data.achievements[ix].category == RC_ACHIEVEMENT_CATEGORY_UNOFFICIAL) ?
|
||||
0 :
|
||||
m_game_data.achievements[ix].points;
|
||||
auto iter = m_unlock_map.insert(
|
||||
{m_game_data.achievements[ix].id, UnlockStatus{.game_data_index = ix, .points = points}});
|
||||
ActivateDeactivateAchievement(iter.first->first, enabled, unofficial, encore);
|
||||
}
|
||||
}
|
||||
@ -573,6 +576,30 @@ void AchievementManager::HandleLeaderboardTriggeredEvent(const rc_runtime_event_
|
||||
}
|
||||
}
|
||||
|
||||
AchievementManager::PointSpread AchievementManager::TallyScore() const
|
||||
{
|
||||
PointSpread spread{};
|
||||
for (const auto& entry : m_unlock_map)
|
||||
{
|
||||
u32 points = entry.second.points;
|
||||
spread.total_count++;
|
||||
spread.total_points += points;
|
||||
if (entry.second.remote_unlock_status == UnlockStatus::UnlockType::HARDCORE ||
|
||||
(hardcore_mode_enabled && entry.second.session_unlock_count > 0))
|
||||
{
|
||||
spread.hard_unlocks++;
|
||||
spread.hard_points += points;
|
||||
}
|
||||
else if (entry.second.remote_unlock_status == UnlockStatus::UnlockType::SOFTCORE ||
|
||||
entry.second.session_unlock_count > 0)
|
||||
{
|
||||
spread.soft_unlocks++;
|
||||
spread.soft_points += points;
|
||||
}
|
||||
}
|
||||
return spread;
|
||||
}
|
||||
|
||||
// Every RetroAchievements API call, with only a partial exception for fetch_image, follows
|
||||
// the same design pattern (here, X is the name of the call):
|
||||
// Create a specific rc_api_X_request_t struct and populate with the necessary values
|
||||
|
Reference in New Issue
Block a user