Skip to content

Commit

Permalink
Achievements: Fix Leaderboard submission UI when multiple leaderboard…
Browse files Browse the repository at this point in the history
…s update at once
  • Loading branch information
CookiePLMonster committed Jul 29, 2023
1 parent 2e8b637 commit bbf0346
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/frontend-common/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void SendPingCallback(s32 status_code, std::string content_type, Common::
static void UnlockAchievementCallback(s32 status_code, std::string content_type,
Common::HTTPDownloader::Request::Data data);
static void SubmitLeaderboardCallback(s32 status_code, std::string content_type,
Common::HTTPDownloader::Request::Data data);
Common::HTTPDownloader::Request::Data data, u32 lboard_id);

static bool s_active = false;
static bool s_logged_in = false;
Expand Down Expand Up @@ -137,7 +137,6 @@ static std::string s_rich_presence_string;
static Common::Timer s_last_ping_time;

static u32 s_last_queried_lboard = 0;
static u32 s_submitting_lboard_id = 0;
static std::optional<std::vector<Achievements::LeaderboardEntry>> s_lboard_entries;

template<typename T>
Expand Down Expand Up @@ -356,7 +355,6 @@ void Achievements::ClearGameInfo(bool clear_achievements, bool clear_leaderboard
}

s_last_queried_lboard = 0;
s_submitting_lboard_id = 0;
s_lboard_entries.reset();
}

Expand Down Expand Up @@ -1741,7 +1739,7 @@ void Achievements::UnlockAchievementCallback(s32 status_code, std::string conten
}

void Achievements::SubmitLeaderboardCallback(s32 status_code, std::string content_type,
Common::HTTPDownloader::Request::Data data)
Common::HTTPDownloader::Request::Data data, u32 lboard_id)
{
if (!System::IsValid())
return;
Expand All @@ -1755,11 +1753,7 @@ void Achievements::SubmitLeaderboardCallback(s32 status_code, std::string conten
// Force the next leaderboard query to repopulate everything, just in case the user wants to see their new score
s_last_queried_lboard = 0;

// RA API doesn't send us the leaderboard ID back.. hopefully we don't submit two at once :/
if (s_submitting_lboard_id == 0)
return;

const Leaderboard* lb = GetLeaderboardByID(std::exchange(s_submitting_lboard_id, 0u));
const Leaderboard* lb = GetLeaderboardByID(lboard_id);
if (!lb || !FullscreenUI::IsInitialized() || !g_settings.achievements_notifications)
return;

Expand Down Expand Up @@ -1870,17 +1864,16 @@ void Achievements::SubmitLeaderboard(u32 leaderboard_id, int value)
return;
}

std::unique_lock lock(s_achievements_mutex);

s_submitting_lboard_id = leaderboard_id;

RAPIRequest<rc_api_submit_lboard_entry_request_t, rc_api_init_submit_lboard_entry_request> request;
request.username = s_username.c_str();
request.api_token = s_api_token.c_str();
request.game_hash = s_game_hash.c_str();
request.leaderboard_id = leaderboard_id;
request.score = value;
request.Send(SubmitLeaderboardCallback);
request.Send(
[leaderboard_id](s32 status_code, const std::string& content_type, Common::HTTPDownloader::Request::Data data) {
SubmitLeaderboardCallback(status_code, content_type, std::move(data), leaderboard_id);
});
}

void Achievements::AchievementPrimed(u32 achievement_id)
Expand Down

0 comments on commit bbf0346

Please sign in to comment.