Finished phase 1
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
|
||||
#include "GlobalSaveGameData.h"
|
||||
|
||||
#include "ItemSaveRecord.h"
|
||||
#include "NakedDesire/Global/Constants.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
@@ -29,4 +31,102 @@ UGlobalSaveGameData* UGlobalSaveGameData::LoadGame(const FString& SlotName)
|
||||
bool UGlobalSaveGameData::SaveGame(UGlobalSaveGameData* SaveGameData, const FString& SlotName)
|
||||
{
|
||||
return UGameplayStatics::SaveGameToSlot(SaveGameData, SlotName, SLOT_PLAYER);
|
||||
}
|
||||
}
|
||||
|
||||
FItemSaveRecord UGlobalSaveGameData::AddWardrobeItem(const UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
FItemSaveRecord NewSaveRecord;
|
||||
NewSaveRecord.Init(ItemInstance);
|
||||
WardrobeItems.Push(NewSaveRecord);
|
||||
return NewSaveRecord;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::UpdateWardrobeItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
for (auto& ItemSaveRecord : WardrobeItems)
|
||||
{
|
||||
if (ItemSaveRecord.InstanceId == ItemInstance->GetInstanceId())
|
||||
{
|
||||
ItemSaveRecord.Init(ItemInstance);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::RemoveWardrobeItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
const int32 RemovedElementsCount = WardrobeItems.RemoveAll([ItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
return RemovedElementsCount > 0;
|
||||
}
|
||||
|
||||
FItemSaveRecord UGlobalSaveGameData::AddEquippedItem(const UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
FItemSaveRecord NewSaveRecord;
|
||||
NewSaveRecord.Init(ItemInstance);
|
||||
EquippedItems.Push(NewSaveRecord);
|
||||
return NewSaveRecord;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::UpdateEquippedItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
for (auto& ItemSaveRecord : EquippedItems)
|
||||
{
|
||||
if (ItemSaveRecord.InstanceId == ItemInstance->GetInstanceId())
|
||||
{
|
||||
ItemSaveRecord.Init(ItemInstance);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::RemoveEquippedItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
const int32 RemovedElementsCount = EquippedItems.RemoveAll([ItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
return RemovedElementsCount > 0;
|
||||
}
|
||||
|
||||
FItemSaveRecord UGlobalSaveGameData::AddWorldItem(const UClothingItemInstance* ItemInstance, FTransform Transform)
|
||||
{
|
||||
FItemSaveRecord NewSaveRecord;
|
||||
NewSaveRecord.Init(ItemInstance);
|
||||
NewSaveRecord.WorldTransform = Transform;
|
||||
WorldItems.Push(NewSaveRecord);
|
||||
return NewSaveRecord;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::UpdateWorldItem(UClothingItemInstance* ItemInstance, FTransform Transform)
|
||||
{
|
||||
for (auto& ItemSaveRecord : WorldItems)
|
||||
{
|
||||
if (ItemSaveRecord.InstanceId == ItemInstance->GetInstanceId())
|
||||
{
|
||||
ItemSaveRecord.Init(ItemInstance);
|
||||
ItemSaveRecord.WorldTransform = Transform;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::RemoveWorldItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
const int32 RemovedElementsCount = WorldItems.RemoveAll([ItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
return RemovedElementsCount > 0;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/SaveGame.h"
|
||||
#include "NakedDesire/Global/Constants.h"
|
||||
#include "ItemSaveRecord.h"
|
||||
#include "GlobalSaveGameData.generated.h"
|
||||
|
||||
struct FItemSaveRecord;
|
||||
class UClothingItemInstance;
|
||||
|
||||
UCLASS()
|
||||
class NAKEDDESIRE_API UGlobalSaveGameData : public USaveGame
|
||||
@@ -24,19 +25,35 @@ public:
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
float Money = 0;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WardrobeItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> EquippedItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WorldItems;
|
||||
|
||||
FItemSaveRecord AddWardrobeItem(const UClothingItemInstance* ItemInstance);
|
||||
bool UpdateWardrobeItem(UClothingItemInstance* ItemInstance);
|
||||
bool RemoveWardrobeItem(UClothingItemInstance* ItemInstance);
|
||||
TArray<FItemSaveRecord> GetWardrobeItems() const { return WardrobeItems; }
|
||||
|
||||
FItemSaveRecord AddEquippedItem(const UClothingItemInstance* ItemInstance);
|
||||
bool UpdateEquippedItem(UClothingItemInstance* ItemInstance);
|
||||
bool RemoveEquippedItem(UClothingItemInstance* ItemInstance);
|
||||
TArray<FItemSaveRecord> GetEquippedItems() const { return EquippedItems; }
|
||||
|
||||
FItemSaveRecord AddWorldItem(const UClothingItemInstance* ItemInstance, FTransform Transform);
|
||||
bool UpdateWorldItem(UClothingItemInstance* ItemInstance, FTransform Transform);
|
||||
bool RemoveWorldItem(UClothingItemInstance* ItemInstance);
|
||||
TArray<FItemSaveRecord> GetWorldItems() const { return WorldItems; }
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
int32 DaysPassed = 0;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
float HourOfDay = 0.0f;
|
||||
|
||||
private:
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WardrobeItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> EquippedItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WorldItems;
|
||||
};
|
||||
@@ -67,11 +67,9 @@ void USaveSubsystem::PopulateStartingData(UGlobalSaveGameData* Save) const
|
||||
if (!ClothingDef)
|
||||
continue;
|
||||
|
||||
// TODO: Refactor. Skip converting to ClothingItemInstance
|
||||
UClothingItemInstance* Instance = NewObject<UClothingItemInstance>(Save);
|
||||
Instance->Init(ClothingDef);
|
||||
|
||||
FItemSaveRecord Record;
|
||||
Record.Init(Instance);
|
||||
Save->EquippedItems.Add(Record);
|
||||
Save->AddEquippedItem(Instance);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user