Resolve Money duplication between ANakedDesireCharacter and UGlobalSaveGameData
This commit is contained in:
@@ -5,4 +5,5 @@
|
|||||||
#define SLOT_NAME "Slot2"
|
#define SLOT_NAME "Slot2"
|
||||||
#define SLOT_PLAYER 0
|
#define SLOT_PLAYER 0
|
||||||
#define IS_DEMO false
|
#define IS_DEMO false
|
||||||
|
#define STARTING_MONEY 1000
|
||||||
|
|
||||||
|
|||||||
@@ -154,6 +154,11 @@ void ANakedDesireCharacter::BeginPlay()
|
|||||||
|
|
||||||
UGlobalSaveGameData* SaveGameData = UGlobalSaveGameData::LoadOrCreateSaveGame(DefaultPlayerClothing, DefaultWardrobeClothing);
|
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);
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public:
|
|||||||
float RunSpeed = 500.0f;
|
float RunSpeed = 500.0f;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite)
|
UPROPERTY(BlueprintReadWrite)
|
||||||
int Money = 300000;
|
int Money = 0;
|
||||||
|
|
||||||
int XP = 0;
|
int XP = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "NakedDesire/Clothing/ClothingItemData.h"
|
#include "NakedDesire/Clothing/ClothingItemData.h"
|
||||||
#include "NakedDesire/Clothing/ClothingList.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>(
|
UGlobalSaveGameData* NewSave = Cast<UGlobalSaveGameData>(
|
||||||
UGameplayStatics::CreateSaveGameObject(UGlobalSaveGameData::StaticClass())
|
UGameplayStatics::CreateSaveGameObject(UGlobalSaveGameData::StaticClass())
|
||||||
@@ -19,11 +19,13 @@ UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame(TArray<UClothingItem
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NewSave->Money = InMoney;
|
||||||
|
|
||||||
for (const UClothingItemData* Item : CurrentWardrobeClothing)
|
for (const UClothingItemData* Item : CurrentWardrobeClothing)
|
||||||
{
|
{
|
||||||
NewSave->WardrobeClothing.Add(Item->ToSaveData());
|
NewSave->WardrobeClothing.Add(Item->ToSaveData());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const UClothingItemData* Item : CurrentPlayerClothing)
|
for (const UClothingItemData* Item : CurrentPlayerClothing)
|
||||||
{
|
{
|
||||||
NewSave->PlayerClothing.Add(Item->ToSaveData());
|
NewSave->PlayerClothing.Add(Item->ToSaveData());
|
||||||
@@ -44,7 +46,7 @@ UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(UClothingList* De
|
|||||||
UGlobalSaveGameData* NewSave = nullptr;
|
UGlobalSaveGameData* NewSave = nullptr;
|
||||||
if (DefaultWardrobeClothing && DefaultPlayerClothing)
|
if (DefaultWardrobeClothing && DefaultPlayerClothing)
|
||||||
{
|
{
|
||||||
NewSave = CreateNewSaveGame(DefaultWardrobeClothing->ClothingItems, DefaultPlayerClothing->ClothingItems);
|
NewSave = CreateNewSaveGame(DefaultWardrobeClothing->ClothingItems, DefaultPlayerClothing->ClothingItems, STARTING_MONEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NewSave)
|
if (NewSave)
|
||||||
@@ -56,11 +58,11 @@ UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(UClothingList* De
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool UGlobalSaveGameData::SaveGame(const TArray<UClothingItemData*> CurrentWardrobeClothing,
|
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;
|
return false;
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ public:
|
|||||||
static UGlobalSaveGameData* LoadOrCreateSaveGame(UClothingList* DefaultPlayerClothing, UClothingList* DefaultWardrobeClothing);
|
static UGlobalSaveGameData* LoadOrCreateSaveGame(UClothingList* DefaultPlayerClothing, UClothingList* DefaultWardrobeClothing);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
static bool SaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing);
|
static bool SaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing, int32 Money);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static UGlobalSaveGameData* CreateNewSaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing);
|
static UGlobalSaveGameData* CreateNewSaveGame(TArray<UClothingItemData*> CurrentWardrobeClothing, TArray<UClothingItemData*> CurrentPlayerClothing, float InMoney);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user