// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #include "UserGameplayData/AwsGameKitUserGameplayDataExamples.h" // GameKit #include "AwsGameKitCore.h" #include "AwsGameKitEditor.h" #include "AwsGameKitRuntime.h" #include "FeatureResourceManager.h" #include "Core/AwsGameKitErrors.h" #include "Core/Logging.h" void AAwsGameKitUserGameplayDataExamples::BeginDestroy() { UE_LOG(LogAwsGameKit, Display, TEXT("AAwsGameKitUserGameplayDataExamples::BeginDestroy()")); Super::BeginDestroy(); } bool AAwsGameKitUserGameplayDataExamples::IsEditorOnly() const { return true; } bool AAwsGameKitUserGameplayDataExamples::ReloadSettings() const { FAwsGameKitRuntimeModule* runtimeModule = FModuleManager::GetModulePtr("AwsGameKitRuntime"); if (runtimeModule->AreFeatureSettingsLoaded(FeatureType::UserGameplayData)) { 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::UserGameplayData); *************/ FAwsGameKitEditorModule* editorModule = AWSGAMEKIT_EDITOR_MODULE_INSTANCE(); return runtimeModule->ReloadConfigFile(editorModule->GetFeatureResourceManager()->GetClientConfigSubdirectory()); } bool AAwsGameKitUserGameplayDataExamples::ReloadIdentitySettings() const { 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()); } /** * Must be called before using any of the Identity APIs. * * Load the DLL and create a GameKitIdentity instance. */ bool AAwsGameKitUserGameplayDataExamples::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; } UE_LOG(LogAwsGameKit, Display, TEXT("GameKitIdentity successfully initialized.")); return true; } /** * Must be called before using any of the User Gameplay Data APIs. * * Load the DLL and create a GameKitUserGameplayData instance. */ bool AAwsGameKitUserGameplayDataExamples::InitializeUserGameplayDataLibrary() { /* * This check is only meant for the examples. * This is to ensure that the User Gameplay Data 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 User Gameplay Data." " See Edit > Project Settings > Plugins > AWS GameKit to create the User Gameplay Data backend.")); return false; } return true; } void AAwsGameKitUserGameplayDataExamples::CallLoginApi() { if (!InitializeIdentityLibrary()) { return; } UE_LOG(LogAwsGameKit, Display, TEXT("CallLoginApi() called with parameters: UserName=%s, Password=