Resolve Money duplication between ANakedDesireCharacter and UGlobalSaveGameData

This commit is contained in:
koritsa
2026-05-18 20:57:34 +03:00
parent 28ca1d0bd3
commit 84b0432be8
5 changed files with 17 additions and 9 deletions
@@ -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;