From 435bb68f7e4b69c917e211143731c2838222255b Mon Sep 17 00:00:00 2001 From: koritsa Date: Wed, 27 May 2026 19:43:00 +0300 Subject: [PATCH] Added starting save data --- .../Blueprints/Data/StartingSaveData.uasset | 3 ++ Content/Blueprints/GI_NakedDesire.uasset | 4 +- .../Casual/Bra/DA_Casual_Bra_Black.uasset | 4 +- Source/NakedDesire/Clothing/ClothingItem.h | 4 +- .../NakedDesire/Clothing/ClothingManager.cpp | 13 ++++-- .../Global/NakedDesireGameInstance.h | 11 +++-- .../NakedDesire/Player/NakedDesireCharacter.h | 1 + .../SaveGame/GlobalSaveGameData.cpp | 21 ++------- .../NakedDesire/SaveGame/GlobalSaveGameData.h | 19 ++++---- Source/NakedDesire/SaveGame/SaveSubsystem.cpp | 43 +++++++++++++++++-- Source/NakedDesire/SaveGame/SaveSubsystem.h | 20 +++++---- .../NakedDesire/SaveGame/StartingSaveData.h | 19 ++++++++ 12 files changed, 109 insertions(+), 53 deletions(-) create mode 100644 Content/Blueprints/Data/StartingSaveData.uasset create mode 100644 Source/NakedDesire/SaveGame/StartingSaveData.h diff --git a/Content/Blueprints/Data/StartingSaveData.uasset b/Content/Blueprints/Data/StartingSaveData.uasset new file mode 100644 index 00000000..db5e08c5 --- /dev/null +++ b/Content/Blueprints/Data/StartingSaveData.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c18d2c02f4024ad31c51405e78aa1c125df8ffd39b14df8a4db61cb7cde835d +size 1589 diff --git a/Content/Blueprints/GI_NakedDesire.uasset b/Content/Blueprints/GI_NakedDesire.uasset index b51b7b43..b2457d33 100644 --- a/Content/Blueprints/GI_NakedDesire.uasset +++ b/Content/Blueprints/GI_NakedDesire.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b83720bca223e3186c1da3fd4e10fa2b41529a69dae1b819010838f42341f49d -size 36238 +oid sha256:3391733042d4ed5bcce041c9478295a19ff7d003edf6ec6f4dcb9c683f37bf0f +size 34867 diff --git a/Content/Characters/Yumi/Clothing/Data/Casual/Bra/DA_Casual_Bra_Black.uasset b/Content/Characters/Yumi/Clothing/Data/Casual/Bra/DA_Casual_Bra_Black.uasset index a12f463b..d80f5f2d 100644 --- a/Content/Characters/Yumi/Clothing/Data/Casual/Bra/DA_Casual_Bra_Black.uasset +++ b/Content/Characters/Yumi/Clothing/Data/Casual/Bra/DA_Casual_Bra_Black.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5b743c7c0a577296aca5e9f5950093ed123a4b0584e246c188dca5ad54b72d62 -size 2906 +oid sha256:d0f3cd78f72e224a2e2b793629f73db244323a6ee45efce9d66b4bc9b3514589 +size 3237 diff --git a/Source/NakedDesire/Clothing/ClothingItem.h b/Source/NakedDesire/Clothing/ClothingItem.h index f221a7ae..6a6d99fc 100644 --- a/Source/NakedDesire/Clothing/ClothingItem.h +++ b/Source/NakedDesire/Clothing/ClothingItem.h @@ -14,10 +14,10 @@ struct NAKEDDESIRE_API FBodyPartCoverage { GENERATED_BODY() - UPROPERTY() + UPROPERTY(EditDefaultsOnly) float Coverage = 1.0f; - UPROPERTY() + UPROPERTY(EditDefaultsOnly) EBodyPart BodyPart = EBodyPart::Ass; }; diff --git a/Source/NakedDesire/Clothing/ClothingManager.cpp b/Source/NakedDesire/Clothing/ClothingManager.cpp index 37d61ba0..a40c691b 100644 --- a/Source/NakedDesire/Clothing/ClothingManager.cpp +++ b/Source/NakedDesire/Clothing/ClothingManager.cpp @@ -153,7 +153,7 @@ void UClothingManager::PutOnClothing(UClothingItemInstance* ClothingItemInstance void UClothingManager::TakeClothing(UClothingItemInstance* ClothingItemInstance) { const EClothingSlotType SlotType = ClothingItemInstance->GetClothingItem()->SlotType; - if (const UClothingItemInstance* ExistingClothing = *EquippedClothing.Find(SlotType)) + if (EquippedClothing.Contains(SlotType)) { DropClothing(SlotType); } @@ -175,10 +175,17 @@ void UClothingManager::TakeClothing(UClothingItemInstance* ClothingItemInstance) UClothingItemInstance* UClothingManager::RemoveClothing(const EClothingSlotType ClothingSlotType) { - UClothingItemInstance* ExistingItem = *EquippedClothing.Find(ClothingSlotType); + TObjectPtr* ExistingItemRef = EquippedClothing.Find(ClothingSlotType); + if (!ExistingItemRef) + { + UE_LOG(LogTemp, Warning, TEXT("UClothingManager::RemoveClothing ExistingItemRef == nullptr")); + return nullptr; + } + + UClothingItemInstance* ExistingItem = *ExistingItemRef; if (!ExistingItem) { - UE_LOG(LogTemp, Warning, TEXT("UClothingManager::RemoveClothing No clothing found")); + UE_LOG(LogTemp, Warning, TEXT("UClothingManager::RemoveClothing ExistingItem == nullptr")); return nullptr; } diff --git a/Source/NakedDesire/Global/NakedDesireGameInstance.h b/Source/NakedDesire/Global/NakedDesireGameInstance.h index 2e154447..d8d776cb 100644 --- a/Source/NakedDesire/Global/NakedDesireGameInstance.h +++ b/Source/NakedDesire/Global/NakedDesireGameInstance.h @@ -5,11 +5,14 @@ #include "CoreMinimal.h" #include "NakedDesireGameInstance.generated.h" -/** - * - */ +class UStartingSaveData; + UCLASS() class NAKEDDESIRE_API UNakedDesireGameInstance : public UGameInstance { GENERATED_BODY() -}; + +public: + UPROPERTY(EditDefaultsOnly, Category = "Save") + TObjectPtr StartingSaveData; +}; \ No newline at end of file diff --git a/Source/NakedDesire/Player/NakedDesireCharacter.h b/Source/NakedDesire/Player/NakedDesireCharacter.h index 77ed65a6..bd4f1547 100644 --- a/Source/NakedDesire/Player/NakedDesireCharacter.h +++ b/Source/NakedDesire/Player/NakedDesireCharacter.h @@ -14,6 +14,7 @@ #include "NakedDesireCharacter.generated.h" class ANakedDesireHUD; +class UClothingItem; class UClothingItemInstance; class UClothingSlotsData; class URadialMenuController; diff --git a/Source/NakedDesire/SaveGame/GlobalSaveGameData.cpp b/Source/NakedDesire/SaveGame/GlobalSaveGameData.cpp index 5803c25f..7bbdf798 100644 --- a/Source/NakedDesire/SaveGame/GlobalSaveGameData.cpp +++ b/Source/NakedDesire/SaveGame/GlobalSaveGameData.cpp @@ -10,38 +10,23 @@ UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame() UGlobalSaveGameData* NewSave = Cast(UGameplayStatics::CreateSaveGameObject(StaticClass())); if (!NewSave) return nullptr; - + NewSave->Money = STARTING_MONEY; return NewSave; } -UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(const FString& SlotName) -{ - if (UGlobalSaveGameData* ExistingSave = LoadGame(SlotName)) - return ExistingSave; - - UGlobalSaveGameData* NewSave = CreateNewSaveGame(); - - if (NewSave) - { - UGameplayStatics::SaveGameToSlot(NewSave, SlotName, SLOT_PLAYER); - } - - return NewSave; -} - UGlobalSaveGameData* UGlobalSaveGameData::LoadGame(const FString& SlotName) { if (UGameplayStatics::DoesSaveGameExist(SlotName, SLOT_PLAYER)) { return Cast(UGameplayStatics::LoadGameFromSlot(SlotName, SLOT_PLAYER)); } - + return nullptr; } bool UGlobalSaveGameData::SaveGame(UGlobalSaveGameData* SaveGameData, const FString& SlotName) { return UGameplayStatics::SaveGameToSlot(SaveGameData, SlotName, SLOT_PLAYER); -} +} \ No newline at end of file diff --git a/Source/NakedDesire/SaveGame/GlobalSaveGameData.h b/Source/NakedDesire/SaveGame/GlobalSaveGameData.h index 2ae0dd7e..b2caa67f 100644 --- a/Source/NakedDesire/SaveGame/GlobalSaveGameData.h +++ b/Source/NakedDesire/SaveGame/GlobalSaveGameData.h @@ -15,31 +15,28 @@ class NAKEDDESIRE_API UGlobalSaveGameData : public USaveGame GENERATED_BODY() public: - static UGlobalSaveGameData* LoadOrCreateSaveGame(const FString& SlotName = DefaultSaveSlotName); + static UGlobalSaveGameData* CreateNewSaveGame(); static UGlobalSaveGameData* LoadGame(const FString& SlotName = DefaultSaveSlotName); static bool SaveGame(UGlobalSaveGameData* SaveGameData, const FString& SlotName = DefaultSaveSlotName); - + UPROPERTY(SaveGame) bool HaveSeenTutorial = false; UPROPERTY(SaveGame) float Money = 0; - + UPROPERTY(SaveGame) TArray WardrobeItems; - + UPROPERTY(SaveGame) TArray EquippedItems; - + UPROPERTY(SaveGame) TArray DroppedItems; - + UPROPERTY(SaveGame) int32 DaysPassed = 0; - + UPROPERTY(SaveGame) float HourOfDay = 0.0f; - -private: - static UGlobalSaveGameData* CreateNewSaveGame(); -}; +}; \ No newline at end of file diff --git a/Source/NakedDesire/SaveGame/SaveSubsystem.cpp b/Source/NakedDesire/SaveGame/SaveSubsystem.cpp index e0011309..fbbb3faf 100644 --- a/Source/NakedDesire/SaveGame/SaveSubsystem.cpp +++ b/Source/NakedDesire/SaveGame/SaveSubsystem.cpp @@ -1,6 +1,14 @@ +// © 2025 Naked People Team. All Rights Reserved. + + #include "SaveSubsystem.h" + #include "GlobalSaveGameData.h" #include "ItemSaveRecord.h" +#include "StartingSaveData.h" +#include "NakedDesire/Clothing/ClothingItem.h" +#include "NakedDesire/Clothing/ClothingItemInstance.h" +#include "NakedDesire/Global/NakedDesireGameInstance.h" void USaveSubsystem::LoadGame(const FString& SlotName) { @@ -28,7 +36,7 @@ void USaveSubsystem::RemoveItem(const FGuid& InstanceId) void USaveSubsystem::Initialize(FSubsystemCollectionBase& Collection) { Super::Initialize(Collection); - + LoadGame(); } @@ -36,8 +44,37 @@ UGlobalSaveGameData* USaveSubsystem::GetCurrentSave() { if (!CurrentSave) { - CurrentSave = UGlobalSaveGameData::LoadOrCreateSaveGame(ActiveSlotName); + CurrentSave = UGlobalSaveGameData::LoadGame(ActiveSlotName); + if (!CurrentSave) + { + CurrentSave = UGlobalSaveGameData::CreateNewSaveGame(); + PopulateStartingData(CurrentSave); + UGlobalSaveGameData::SaveGame(CurrentSave, ActiveSlotName); + } } - + return CurrentSave; } + +void USaveSubsystem::PopulateStartingData(UGlobalSaveGameData* Save) const +{ + if (!Save) + return; + + const UNakedDesireGameInstance* GameInstance = Cast(GetGameInstance()); + if (!GameInstance || !GameInstance->StartingSaveData) + return; + + for (UClothingItem* ClothingDef : GameInstance->StartingSaveData->StartingClothing) + { + if (!ClothingDef) + continue; + + UClothingItemInstance* Instance = NewObject(Save); + Instance->Init(ClothingDef); + + FItemSaveRecord Record; + Record.Init(Instance); + Save->EquippedItems.Add(Record); + } +} \ No newline at end of file diff --git a/Source/NakedDesire/SaveGame/SaveSubsystem.h b/Source/NakedDesire/SaveGame/SaveSubsystem.h index fcf2dab1..3af308e3 100644 --- a/Source/NakedDesire/SaveGame/SaveSubsystem.h +++ b/Source/NakedDesire/SaveGame/SaveSubsystem.h @@ -1,3 +1,5 @@ +// © 2025 Naked People Team. All Rights Reserved. + #pragma once #include "CoreMinimal.h" @@ -12,26 +14,28 @@ UCLASS() class NAKEDDESIRE_API USaveSubsystem : public UGameInstanceSubsystem { GENERATED_BODY() - + public: void LoadGame(const FString& SlotName = DefaultSaveSlotName); bool SaveGame(const FString& SlotName = DefaultSaveSlotName) const; - + const TArray& GetItems() const { return Items; } void AddItem(const FItemSaveRecord& Record); void RemoveItem(const FGuid& InstanceId); - + virtual void Initialize(FSubsystemCollectionBase& Collection) override; - + UGlobalSaveGameData* GetCurrentSave(); - + private: + void PopulateStartingData(UGlobalSaveGameData* Save) const; + UPROPERTY() FString ActiveSlotName = DefaultSaveSlotName; - + UPROPERTY() TArray Items; - + UPROPERTY() TObjectPtr CurrentSave; -}; +}; \ No newline at end of file diff --git a/Source/NakedDesire/SaveGame/StartingSaveData.h b/Source/NakedDesire/SaveGame/StartingSaveData.h new file mode 100644 index 00000000..396ad185 --- /dev/null +++ b/Source/NakedDesire/SaveGame/StartingSaveData.h @@ -0,0 +1,19 @@ +// © 2025 Naked People Team. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" +#include "Engine/DataAsset.h" +#include "StartingSaveData.generated.h" + +class UClothingItem; + +UCLASS() +class NAKEDDESIRE_API UStartingSaveData : public UPrimaryDataAsset +{ + GENERATED_BODY() + +public: + UPROPERTY(EditDefaultsOnly, Category = "Starting State") + TArray> StartingClothing; +}; \ No newline at end of file