Added save subsystem
This commit is contained in:
@@ -1,4 +1 @@
|
|||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
|
||||||
|
|
||||||
|
|
||||||
#include "ClothingItemInstance.h"
|
#include "ClothingItemInstance.h"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define SLOT_NAME "Slot2"
|
inline const FString DefaultSaveSlotName = TEXT("Slot1");
|
||||||
#define SLOT_PLAYER 0
|
#define SLOT_PLAYER 0
|
||||||
#define IS_DEMO false
|
#define IS_DEMO false
|
||||||
#define STARTING_MONEY 1000
|
#define STARTING_MONEY 1000
|
||||||
|
|||||||
@@ -152,21 +152,12 @@ void ANakedDesireCharacter::BeginPlay()
|
|||||||
StimuliSourceComponent->RegisterForSense(TSubclassOf<UAISense_Sight>());
|
StimuliSourceComponent->RegisterForSense(TSubclassOf<UAISense_Sight>());
|
||||||
StimuliSourceComponent->RegisterWithPerceptionSystem();
|
StimuliSourceComponent->RegisterWithPerceptionSystem();
|
||||||
|
|
||||||
// UGlobalSaveGameData* SaveGameData = UGlobalSaveGameData::LoadOrCreateSaveGame(DefaultPlayerClothing, DefaultWardrobeClothing);
|
|
||||||
|
|
||||||
// if (SaveGameData)
|
|
||||||
// {
|
|
||||||
// Money = FMath::RoundToInt(SaveGameData->Money);
|
|
||||||
// }
|
|
||||||
|
|
||||||
SetupClothingSlots();
|
SetupClothingSlots();
|
||||||
|
|
||||||
ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &ANakedDesireCharacter::OnClothingEquip);
|
ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &ANakedDesireCharacter::OnClothingEquip);
|
||||||
ClothingManager->OnClothingUnequip.AddUniqueDynamic(this, &ANakedDesireCharacter::OnClothingUnequip);
|
ClothingManager->OnClothingUnequip.AddUniqueDynamic(this, &ANakedDesireCharacter::OnClothingUnequip);
|
||||||
|
|
||||||
UNakedDesireUserSettings::GetNakedDesireUserSettings()->OnSettingsChanged.AddUniqueDynamic(this, &ANakedDesireCharacter::OnSettingsChanged);
|
UNakedDesireUserSettings::GetNakedDesireUserSettings()->OnSettingsChanged.AddUniqueDynamic(this, &ANakedDesireCharacter::OnSettingsChanged);
|
||||||
|
|
||||||
// ClothingManager->HydrateClothing(SaveGameData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UAISense_Sight::EVisibilityResult ANakedDesireCharacter::CanBeSeenFrom(const FCanBeSeenFromContext& Context,
|
UAISense_Sight::EVisibilityResult ANakedDesireCharacter::CanBeSeenFrom(const FCanBeSeenFromContext& Context,
|
||||||
|
|||||||
@@ -7,59 +7,47 @@
|
|||||||
|
|
||||||
UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame()
|
UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame()
|
||||||
{
|
{
|
||||||
UGlobalSaveGameData* NewSave = Cast<UGlobalSaveGameData>(
|
UGlobalSaveGameData* NewSave = Cast<UGlobalSaveGameData>(UGameplayStatics::CreateSaveGameObject(StaticClass()));
|
||||||
UGameplayStatics::CreateSaveGameObject(UGlobalSaveGameData::StaticClass())
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!NewSave)
|
if (!NewSave)
|
||||||
{
|
{
|
||||||
return nullptr;
|
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;
|
return NewSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame()
|
UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(const FString& SlotName)
|
||||||
{
|
{
|
||||||
if (UGameplayStatics::DoesSaveGameExist(SLOT_NAME, SLOT_PLAYER))
|
if (UGlobalSaveGameData* ExistingSave = LoadGame(SlotName))
|
||||||
{
|
return ExistingSave;
|
||||||
return Cast<UGlobalSaveGameData>(
|
|
||||||
UGameplayStatics::LoadGameFromSlot(SLOT_NAME, SLOT_PLAYER)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
UGlobalSaveGameData* NewSave = nullptr;
|
UGlobalSaveGameData* NewSave = CreateNewSaveGame();
|
||||||
// if (DefaultWardrobeClothing && DefaultPlayerClothing)
|
|
||||||
// {
|
|
||||||
// NewSave = CreateNewSaveGame(DefaultWardrobeClothing->ClothingItems, DefaultPlayerClothing->ClothingItems, STARTING_MONEY);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (NewSave)
|
if (NewSave)
|
||||||
{
|
{
|
||||||
UGameplayStatics::SaveGameToSlot(NewSave, SLOT_NAME, SLOT_PLAYER);
|
UGameplayStatics::SaveGameToSlot(NewSave, SlotName, SLOT_PLAYER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewSave;
|
return NewSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UGlobalSaveGameData::SaveGame()
|
UGlobalSaveGameData* UGlobalSaveGameData::LoadGame(const FString& SlotName)
|
||||||
{
|
{
|
||||||
// if (UGlobalSaveGameData* Save = CreateNewSaveGame(CurrentWardrobeClothing, CurrentPlayerClothing, (float)InMoney))
|
if (UGameplayStatics::DoesSaveGameExist(SlotName, SLOT_PLAYER))
|
||||||
// {
|
{
|
||||||
// return UGameplayStatics::SaveGameToSlot(Save, SLOT_NAME, 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameFramework/SaveGame.h"
|
#include "GameFramework/SaveGame.h"
|
||||||
|
#include "NakedDesire/Global/Constants.h"
|
||||||
#include "GlobalSaveGameData.generated.h"
|
#include "GlobalSaveGameData.generated.h"
|
||||||
|
|
||||||
|
struct FItemSaveRecord;
|
||||||
class UClothingList;
|
class UClothingList;
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
@@ -14,17 +16,27 @@ class NAKEDDESIRE_API UGlobalSaveGameData : public USaveGame
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPROPERTY(BlueprintReadWrite, SaveGame)
|
static UGlobalSaveGameData* LoadOrCreateSaveGame(const FString& SlotName = DefaultSaveSlotName);
|
||||||
|
static UGlobalSaveGameData* LoadGame(const FString& SlotName = DefaultSaveSlotName);
|
||||||
|
static bool SaveGame(const FString& SlotName = DefaultSaveSlotName);
|
||||||
|
|
||||||
|
UPROPERTY(SaveGame)
|
||||||
bool HaveSeenTutorial = false;
|
bool HaveSeenTutorial = false;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, SaveGame)
|
UPROPERTY(SaveGame)
|
||||||
float Money = 0;
|
float Money = 0;
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
|
||||||
static UGlobalSaveGameData* LoadOrCreateSaveGame();
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
UPROPERTY(SaveGame)
|
||||||
static bool SaveGame();
|
TArray<FItemSaveRecord> WardrobeItems;
|
||||||
|
|
||||||
|
UPROPERTY(SaveGame)
|
||||||
|
TArray<FItemSaveRecord> EquippedItems;
|
||||||
|
|
||||||
|
UPROPERTY(SaceGame)
|
||||||
|
int32 DaysPassed = 0;
|
||||||
|
|
||||||
|
UPROPERTY(SaveGame)
|
||||||
|
float HourOfDay = 0.0f;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static UGlobalSaveGameData* CreateNewSaveGame();
|
static UGlobalSaveGameData* CreateNewSaveGame();
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "ItemSaveRecord.generated.h"
|
||||||
|
|
||||||
|
class UClothingItem;
|
||||||
|
|
||||||
|
USTRUCT()
|
||||||
|
struct NAKEDDESIRE_API FItemSaveRecord
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
UPROPERTY(SaveGame)
|
||||||
|
FGuid InstanceId;
|
||||||
|
|
||||||
|
UPROPERTY(SaveGame)
|
||||||
|
TSoftObjectPtr<UClothingItem> Definition;
|
||||||
|
|
||||||
|
UPROPERTY(SaveGame)
|
||||||
|
float Condition = 1.0f;
|
||||||
|
|
||||||
|
UPROPERTY(SaveGame)
|
||||||
|
FGuid ParentId;
|
||||||
|
};
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#include "SaveSubsystem.h"
|
||||||
|
#include "GlobalSaveGameData.h"
|
||||||
|
#include "ItemSaveRecord.h"
|
||||||
|
|
||||||
|
void USaveSubsystem::LoadGame(const FString& SlotName)
|
||||||
|
{
|
||||||
|
UGlobalSaveGameData* Save = UGlobalSaveGameData::LoadGame(SlotName);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool USaveSubsystem::SaveGame(const FString& SlotName)
|
||||||
|
{
|
||||||
|
return UGlobalSaveGameData::SaveGame(SlotName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void USaveSubsystem::AddItem(const FItemSaveRecord& Record)
|
||||||
|
{
|
||||||
|
Items.Add(Record);
|
||||||
|
}
|
||||||
|
|
||||||
|
void USaveSubsystem::RemoveItem(const FGuid& InstanceId)
|
||||||
|
{
|
||||||
|
FItemSaveRecord* ItemSaveRecord = Items.FindByPredicate([InstanceId](FItemSaveRecord ItemSaveRecord)
|
||||||
|
{
|
||||||
|
return ItemSaveRecord.InstanceId == InstanceId;
|
||||||
|
});
|
||||||
|
if (ItemSaveRecord)
|
||||||
|
{
|
||||||
|
Items.Remove(*ItemSaveRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void USaveSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||||
|
{
|
||||||
|
Super::Initialize(Collection);
|
||||||
|
|
||||||
|
LoadGame();
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "NakedDesire/Global/Constants.h"
|
||||||
|
#include "Subsystems/GameInstanceSubsystem.h"
|
||||||
|
#include "SaveSubsystem.generated.h"
|
||||||
|
|
||||||
|
class UGlobalSaveGameData;
|
||||||
|
struct FItemSaveRecord;
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class NAKEDDESIRE_API USaveSubsystem : public UGameInstanceSubsystem
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
void LoadGame(const FString& SlotName = DefaultSaveSlotName);
|
||||||
|
bool SaveGame(const FString& SlotName = DefaultSaveSlotName);
|
||||||
|
|
||||||
|
const TArray<FItemSaveRecord>& GetItems() const { return Items; }
|
||||||
|
void AddItem(const FItemSaveRecord& Record);
|
||||||
|
void RemoveItem(const FGuid& InstanceId);
|
||||||
|
|
||||||
|
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UPROPERTY()
|
||||||
|
FString ActiveSlotName = DefaultSaveSlotName;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TArray<FItemSaveRecord> Items;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<UGlobalSaveGameData> CurrentSave;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user