133 lines
3.3 KiB
C++
133 lines
3.3 KiB
C++
// © 2025 Naked People Team. All Rights Reserved.
|
|
|
|
|
|
#include "GlobalSaveGameData.h"
|
|
|
|
#include "ItemSaveRecord.h"
|
|
#include "NakedDesire/Global/Constants.h"
|
|
#include "Kismet/GameplayStatics.h"
|
|
|
|
UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame()
|
|
{
|
|
UGlobalSaveGameData* NewSave = Cast<UGlobalSaveGameData>(UGameplayStatics::CreateSaveGameObject(StaticClass()));
|
|
if (!NewSave)
|
|
return nullptr;
|
|
|
|
NewSave->Money = STARTING_MONEY;
|
|
|
|
return NewSave;
|
|
}
|
|
|
|
UGlobalSaveGameData* UGlobalSaveGameData::LoadGame(const FString& SlotName)
|
|
{
|
|
if (UGameplayStatics::DoesSaveGameExist(SlotName, SLOT_PLAYER))
|
|
{
|
|
return Cast<UGlobalSaveGameData>(UGameplayStatics::LoadGameFromSlot(SlotName, SLOT_PLAYER));
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
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;
|
|
}
|