// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #include "Achievements/AwsGameKitAchievementsExamples.h" // GameKit #include "AwsGameKitCore.h" #include "AwsGameKitEditor.h" #include "AwsGameKitRuntime.h" #include "FeatureResourceManager.h" #include "Achievements/AwsGameKitAchievements.h" #include "Achievements/AwsGameKitAchievementsAdmin.h" #include "Core/AwsGameKitErrors.h" #include "Core/Logging.h" #include "Identity/AwsGameKitIdentity.h" #include "SessionManager/AwsGameKitSessionManager.h" // Unreal #include "Async/Async.h" #include "HAL/FileManagerGeneric.h" void AAwsGameKitAchievementsExamples::BeginDestroy() { UE_LOG(LogAwsGameKit, Display, TEXT("AAwsGameKitAchievementsExamples::BeginDestroy()")); Super::BeginDestroy(); } bool AAwsGameKitAchievementsExamples::IsEditorOnly() const { return true; } bool AAwsGameKitAchievementsExamples::ReloadSettings() { FAwsGameKitRuntimeModule* runtimeModule = FModuleManager::GetModulePtr("AwsGameKitRuntime"); if (runtimeModule->AreFeatureSettingsLoaded(FeatureType::Achievements)) { return true; } /************* // In order to call ReloadConfigFile() outside of AwsGameKitEditor module, use the lines below: FAwsGameKitRuntimeModule* runtimeModule = FModuleManager::GetModulePtr("AwsGameKitRuntime"); SessionManagerLibrary sessionManagerLibrary = runtimeModule->GetSessionManagerLibrary(); sessionManagerLibrary.SessionManagerWrapper->ReloadConfig(sessionManagerLibrary.SessionManagerInstanceHandle); return runtimeModule->AreFeatureSettingsLoaded(FeatureType::Achievements); *************/ FAwsGameKitEditorModule* editorModule = AWSGAMEKIT_EDITOR_MODULE_INSTANCE(); return runtimeModule->ReloadConfigFile(editorModule->GetFeatureResourceManager()->GetClientConfigSubdirectory()); } bool AAwsGameKitAchievementsExamples::ReloadIdentitySettings() { FAwsGameKitRuntimeModule* runtimeModule = FModuleManager::GetModulePtr("AwsGameKitRuntime"); if (runtimeModule->AreFeatureSettingsLoaded(FeatureType::Identity)) { return true; } /************* // In order to call ReloadConfigFile() outside of AwsGameKitEditor module, use the lines below: FAwsGameKitRuntimeModule* runtimeModule = FModuleManager::GetModulePtr("AwsGameKitRuntime"); SessionManagerLibrary sessionManagerLibrary = runtimeModule->GetSessionManagerLibrary(); sessionManagerLibrary.SessionManagerWrapper->ReloadConfig(sessionManagerLibrary.SessionManagerInstanceHandle); return runtimeModule->AreFeatureSettingsLoaded(FeatureType::Identity); *************/ FAwsGameKitEditorModule* editorModule = AWSGAMEKIT_EDITOR_MODULE_INSTANCE(); return runtimeModule->ReloadConfigFile(editorModule->GetFeatureResourceManager()->GetClientConfigSubdirectory()); } bool AAwsGameKitAchievementsExamples::InitializeIdentityLibrary() { if (!ReloadIdentitySettings()) { FMessageDialog::Open(EAppMsgType::Ok, FText::FromString("This example requires an AWS GameKit backend service for Identity/Authentication." " See Edit > Project Settings > Plugins > AWS GameKit to create the Identity/Authentication backend.")); return false; } return true; } /** * Must be called before using any of the Achievements APIs. * * Load the DLL and create a GameKitAchievements instance. */ bool AAwsGameKitAchievementsExamples::InitializeAchievementsLibrary() { /* * This check is only meant for the examples. * This is to ensure that the feature has been deployed before running any of the sample code. */ if (!ReloadSettings()) { FMessageDialog::Open(EAppMsgType::Ok, FText::FromString("This example requires an AWS GameKit backend service for Achievements." " See Edit > Project Settings > Plugins > AWS GameKit to create the Achievements backend.")); return false; } if(BaseIconUrl.IsEmpty()) { // Retrieve icon base url const auto Delegate = MakeAwsGameKitDelegate(this, &AAwsGameKitAchievementsExamples::OnGetIconBaseUrlComplete); AwsGameKitAchievements::GetAchievementIconBaseUrl(Delegate); ImageDownloaderInstance = ImageDownloader::MakeInstance(); } return true; } void AAwsGameKitAchievementsExamples::OnGetIconBaseUrlComplete(const IntResult& result, const FString& url) { if (result.Result != GameKit::GAMEKIT_SUCCESS) { UE_LOG(LogAwsGameKit, Error, TEXT("AAwsGameKitAchievementExamples::OnGetIconBaseUrlComplete(): Could not get base icon url because error: %s"), *result.ErrorMessage); BaseIconUrl = ""; return; } BaseIconUrl = url; } void AAwsGameKitAchievementsExamples::CallLoginApi() { if (!InitializeIdentityLibrary()) { return; } UE_LOG(LogAwsGameKit, Display, TEXT("CallLoginApi() called with parameters: UserName=%s, Password=