LifePlay-Revival/Source/LifePlay/LPModSettingsLibrary.cpp

37 lines
1.6 KiB
C++
Raw Normal View History

// Portage UE 5.5 - voir LPModSettingsLibrary.h
#include "LPModSettingsLibrary.h"
#include "GameFramework/SaveGame.h"
#include "Kismet/GameplayStatics.h"
#include "LifePlay.h"
#include "UObject/UnrealType.h"
bool ULPModSettingsLibrary::SaveModSelection(UObject* GameInstance)
{
static const TCHAR* Slot = TEXT("GameSettings");
static const FName SettingsModEnabledsName(TEXT("ModEnableds"));
if (!GameInstance)
{
return false;
}
if (!UGameplayStatics::DoesSaveGameExist(Slot, 0))
{
UE_LOG(LogLifePlay, Display, TEXT("Modules : pas encore de %s.sav, choix enregistre a la premiere sauvegarde"), Slot);
return false;
}
USaveGame* Settings = UGameplayStatics::LoadGameFromSlot(Slot, 0);
const FArrayProperty* From = CastField<FArrayProperty>(GameInstance->GetClass()->FindPropertyByName(SettingsModEnabledsName));
const FArrayProperty* To = Settings ? CastField<FArrayProperty>(Settings->GetClass()->FindPropertyByName(SettingsModEnabledsName)) : nullptr;
if (!From || !To || !From->SameType(To))
{
UE_LOG(LogLifePlay, Warning, TEXT("Modules : %s.sav illisible ou sans ModEnableds compatible, choix non enregistre"), Slot);
return false;
}
To->CopyCompleteValue(To->ContainerPtrToValuePtr<void>(Settings), From->ContainerPtrToValuePtr<void>(GameInstance));
const bool bSaved = UGameplayStatics::SaveGameToSlot(Settings, Slot, 0);
FScriptArrayHelper Helper(To, To->ContainerPtrToValuePtr<void>(Settings));
UE_LOG(LogLifePlay, Display, TEXT("Modules : choix (%d module(s)) %s dans %s.sav"), Helper.Num(), bSaved ? TEXT("enregistre") : TEXT("NON enregistre"), Slot);
return bSaved;
}