Resolve Money duplication between ANakedDesireCharacter and UGlobalSaveGameData

This commit is contained in:
2026-05-18 20:57:34 +03:00
parent a5bd139f62
commit 1c50237958
5 changed files with 17 additions and 9 deletions
+1
View File
@@ -5,4 +5,5 @@
#define SLOT_NAME "Slot2"
#define SLOT_PLAYER 0
#define IS_DEMO false
#define STARTING_MONEY 1000
@@ -154,6 +154,11 @@ void ANakedDesireCharacter::BeginPlay()
UGlobalSaveGameData* SaveGameData = UGlobalSaveGameData::LoadOrCreateSaveGame(DefaultPlayerClothing, DefaultWardrobeClothing);
if (SaveGameData)
{
Money = FMath::RoundToInt(SaveGameData->Money);
}
SetupClothingSlots();
ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &ANakedDesireCharacter::OnClothingEquip);
@@ -136,7 +136,7 @@ public:
float RunSpeed = 500.0f;
UPROPERTY(BlueprintReadWrite)
int Money = 300000;
int Money = 0;
int XP = 0;
@@ -8,7 +8,7 @@
#include "NakedDesire/Clothing/ClothingItemData.h"
#include "NakedDesire/Clothing/ClothingList.h"
UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing)
UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing, float InMoney)
{
UGlobalSaveGameData* NewSave = Cast<UGlobalSaveGameData>(
UGameplayStatics::CreateSaveGameObject(UGlobalSaveGameData::StaticClass())
@@ -19,11 +19,13 @@ UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame(TArray<UClothingItem
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());
@@ -44,7 +46,7 @@ UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(UClothingList* De
UGlobalSaveGameData* NewSave = nullptr;
if (DefaultWardrobeClothing && DefaultPlayerClothing)
{
NewSave = CreateNewSaveGame(DefaultWardrobeClothing->ClothingItems, DefaultPlayerClothing->ClothingItems);
NewSave = CreateNewSaveGame(DefaultWardrobeClothing->ClothingItems, DefaultPlayerClothing->ClothingItems, STARTING_MONEY);
}
if (NewSave)
@@ -56,11 +58,11 @@ UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(UClothingList* De
}
bool UGlobalSaveGameData::SaveGame(const TArray<UClothingItemData*> CurrentWardrobeClothing,
const TArray<UClothingItemData*> CurrentPlayerClothing)
const TArray<UClothingItemData*> CurrentPlayerClothing, int32 Money)
{
if (UGlobalSaveGameData* SaveGame = CreateNewSaveGame(CurrentWardrobeClothing, CurrentPlayerClothing))
if (UGlobalSaveGameData* Save = CreateNewSaveGame(CurrentWardrobeClothing, CurrentPlayerClothing, (float)Money))
{
return UGameplayStatics::SaveGameToSlot(SaveGame, SLOT_NAME, SLOT_PLAYER);
return UGameplayStatics::SaveGameToSlot(Save, SLOT_NAME, SLOT_PLAYER);
}
return false;
@@ -34,8 +34,8 @@ public:
static UGlobalSaveGameData* LoadOrCreateSaveGame(UClothingList* DefaultPlayerClothing, UClothingList* DefaultWardrobeClothing);
UFUNCTION(BlueprintCallable)
static bool SaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing);
static bool SaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing, int32 Money);
private:
static UGlobalSaveGameData* CreateNewSaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing);
static UGlobalSaveGameData* CreateNewSaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing, float InMoney);
};