Added AwardAchievement to AchievementManager
AwardAchievement performs the API call to notify the site that an achievement has been unlocked. As one of the parameters is the game hash (something I overlooked previously; I thought it was the game ID) this change also moves the game hash into a member field.
This commit is contained in:
parent
8c67083c87
commit
9a57216fd0
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include "Core/AchievementManager.h"
|
#include "Core/AchievementManager.h"
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <rcheevos/include/rc_hash.h>
|
#include <rcheevos/include/rc_hash.h>
|
||||||
|
|
||||||
#include "Common/HttpRequest.h"
|
#include "Common/HttpRequest.h"
|
||||||
|
@ -113,11 +112,10 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
|
||||||
},
|
},
|
||||||
.close = [](void* file_handle) { delete reinterpret_cast<FilereaderState*>(file_handle); }};
|
.close = [](void* file_handle) { delete reinterpret_cast<FilereaderState*>(file_handle); }};
|
||||||
rc_hash_init_custom_filereader(&volume_reader);
|
rc_hash_init_custom_filereader(&volume_reader);
|
||||||
std::array<char, HASH_LENGTH> game_hash;
|
if (!rc_hash_generate_from_file(m_game_hash.data(), RC_CONSOLE_GAMECUBE, iso_path.c_str()))
|
||||||
if (!rc_hash_generate_from_file(game_hash.data(), RC_CONSOLE_GAMECUBE, iso_path.c_str()))
|
|
||||||
return;
|
return;
|
||||||
m_queue.EmplaceItem([this, callback, game_hash] {
|
m_queue.EmplaceItem([this, callback] {
|
||||||
const auto resolve_hash_response = ResolveHash(game_hash);
|
const auto resolve_hash_response = ResolveHash(this->m_game_hash);
|
||||||
if (resolve_hash_response != ResponseType::SUCCESS || m_game_id == 0)
|
if (resolve_hash_response != ResponseType::SUCCESS || m_game_id == 0)
|
||||||
{
|
{
|
||||||
callback(resolve_hash_response);
|
callback(resolve_hash_response);
|
||||||
|
@ -366,6 +364,24 @@ void AchievementManager::ActivateDeactivateAchievement(AchievementId id, bool en
|
||||||
rc_runtime_deactivate_achievement(&m_runtime, id);
|
rc_runtime_deactivate_achievement(&m_runtime, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AchievementManager::ResponseType AchievementManager::AwardAchievement(AchievementId achievement_id)
|
||||||
|
{
|
||||||
|
std::string username = Config::Get(Config::RA_USERNAME);
|
||||||
|
std::string api_token = Config::Get(Config::RA_API_TOKEN);
|
||||||
|
rc_api_award_achievement_request_t award_request = {.username = username.c_str(),
|
||||||
|
.api_token = api_token.c_str(),
|
||||||
|
.achievement_id = achievement_id,
|
||||||
|
.hardcore = hardcore_mode_enabled,
|
||||||
|
.game_hash = m_game_hash.data()};
|
||||||
|
rc_api_award_achievement_response_t award_response = {};
|
||||||
|
ResponseType r_type =
|
||||||
|
Request<rc_api_award_achievement_request_t, rc_api_award_achievement_response_t>(
|
||||||
|
award_request, &award_response, rc_api_init_award_achievement_request,
|
||||||
|
rc_api_process_award_achievement_response);
|
||||||
|
rc_api_destroy_award_achievement_response(&award_response);
|
||||||
|
return r_type;
|
||||||
|
}
|
||||||
|
|
||||||
// Every RetroAchievements API call, with only a partial exception for fetch_image, follows
|
// 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):
|
// 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
|
// Create a specific rc_api_X_request_t struct and populate with the necessary values
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||||
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -62,6 +63,7 @@ private:
|
||||||
|
|
||||||
void ActivateDeactivateAchievement(AchievementId id, bool enabled, bool unofficial, bool encore);
|
void ActivateDeactivateAchievement(AchievementId id, bool enabled, bool unofficial, bool encore);
|
||||||
|
|
||||||
|
ResponseType AwardAchievement(AchievementId achievement_id);
|
||||||
template <typename RcRequest, typename RcResponse>
|
template <typename RcRequest, typename RcResponse>
|
||||||
ResponseType Request(RcRequest rc_request, RcResponse* rc_response,
|
ResponseType Request(RcRequest rc_request, RcResponse* rc_response,
|
||||||
const std::function<int(rc_api_request_t*, const RcRequest*)>& init_request,
|
const std::function<int(rc_api_request_t*, const RcRequest*)>& init_request,
|
||||||
|
@ -69,7 +71,8 @@ private:
|
||||||
|
|
||||||
rc_runtime_t m_runtime{};
|
rc_runtime_t m_runtime{};
|
||||||
bool m_is_runtime_initialized = false;
|
bool m_is_runtime_initialized = false;
|
||||||
unsigned int m_game_id = 0;
|
std::array<char, HASH_LENGTH> m_game_hash{};
|
||||||
|
u32 m_game_id = 0;
|
||||||
rc_api_fetch_game_data_response_t m_game_data{};
|
rc_api_fetch_game_data_response_t m_game_data{};
|
||||||
bool m_is_game_loaded = false;
|
bool m_is_game_loaded = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue