Added save subsystem
This commit is contained in:
@@ -7,59 +7,47 @@
|
||||
|
||||
UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame()
|
||||
{
|
||||
UGlobalSaveGameData* NewSave = Cast<UGlobalSaveGameData>(
|
||||
UGameplayStatics::CreateSaveGameObject(UGlobalSaveGameData::StaticClass())
|
||||
);
|
||||
UGlobalSaveGameData* NewSave = Cast<UGlobalSaveGameData>(UGameplayStatics::CreateSaveGameObject(StaticClass()));
|
||||
|
||||
if (!NewSave)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// NewSave->Money = InMoney;
|
||||
|
||||
// for (const UClothingItemData* Item : CurrentWardrobeClothing)
|
||||
// {
|
||||
// NewSave->WardrobeClothing.Add(Item->ToSaveData());
|
||||
// }
|
||||
//
|
||||
// for (const UClothingItemData* Item : CurrentPlayerClothing)
|
||||
// {
|
||||
// NewSave->PlayerClothing.Add(Item->ToSaveData());
|
||||
// }
|
||||
|
||||
return NewSave;
|
||||
}
|
||||
|
||||
UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame()
|
||||
UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(const FString& SlotName)
|
||||
{
|
||||
if (UGameplayStatics::DoesSaveGameExist(SLOT_NAME, SLOT_PLAYER))
|
||||
{
|
||||
return Cast<UGlobalSaveGameData>(
|
||||
UGameplayStatics::LoadGameFromSlot(SLOT_NAME, SLOT_PLAYER)
|
||||
);
|
||||
}
|
||||
if (UGlobalSaveGameData* ExistingSave = LoadGame(SlotName))
|
||||
return ExistingSave;
|
||||
|
||||
UGlobalSaveGameData* NewSave = nullptr;
|
||||
// if (DefaultWardrobeClothing && DefaultPlayerClothing)
|
||||
// {
|
||||
// NewSave = CreateNewSaveGame(DefaultWardrobeClothing->ClothingItems, DefaultPlayerClothing->ClothingItems, STARTING_MONEY);
|
||||
// }
|
||||
UGlobalSaveGameData* NewSave = CreateNewSaveGame();
|
||||
|
||||
if (NewSave)
|
||||
{
|
||||
UGameplayStatics::SaveGameToSlot(NewSave, SLOT_NAME, SLOT_PLAYER);
|
||||
UGameplayStatics::SaveGameToSlot(NewSave, SlotName, SLOT_PLAYER);
|
||||
}
|
||||
|
||||
return NewSave;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::SaveGame()
|
||||
UGlobalSaveGameData* UGlobalSaveGameData::LoadGame(const FString& SlotName)
|
||||
{
|
||||
// if (UGlobalSaveGameData* Save = CreateNewSaveGame(CurrentWardrobeClothing, CurrentPlayerClothing, (float)InMoney))
|
||||
// {
|
||||
// return UGameplayStatics::SaveGameToSlot(Save, SLOT_NAME, SLOT_PLAYER);
|
||||
// }
|
||||
if (UGameplayStatics::DoesSaveGameExist(SlotName, SLOT_PLAYER))
|
||||
{
|
||||
return Cast<UGlobalSaveGameData>(UGameplayStatics::LoadGameFromSlot(SlotName, SLOT_PLAYER));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::SaveGame(const FString& SlotName)
|
||||
{
|
||||
if (UGlobalSaveGameData* Save = CreateNewSaveGame())
|
||||
{
|
||||
return UGameplayStatics::SaveGameToSlot(Save, SlotName, SLOT_PLAYER);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user