// © 2025 Naked People Team. All Rights Reserved. #include "GlobalSaveGameData.h" #include "NakedDesire/Global/Constants.h" #include "Kismet/GameplayStatics.h" #include "NakedDesire/Clothing/ClothingItemData.h" #include "NakedDesire/Clothing/ClothingList.h" UGlobalSaveGameData* UGlobalSaveGameData::CreateNewSaveGame(TArray CurrentWardrobeClothing, TArray CurrentPlayerClothing, float InMoney) { UGlobalSaveGameData* NewSave = Cast( UGameplayStatics::CreateSaveGameObject(UGlobalSaveGameData::StaticClass()) ); if (!NewSave) { 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()); } return NewSave; } UGlobalSaveGameData* UGlobalSaveGameData::LoadOrCreateSaveGame(UClothingList* DefaultPlayerClothing, UClothingList* DefaultWardrobeClothing) { if (UGameplayStatics::DoesSaveGameExist(SLOT_NAME, SLOT_PLAYER)) { return Cast( UGameplayStatics::LoadGameFromSlot(SLOT_NAME, SLOT_PLAYER) ); } UGlobalSaveGameData* NewSave = nullptr; if (DefaultWardrobeClothing && DefaultPlayerClothing) { NewSave = CreateNewSaveGame(DefaultWardrobeClothing->ClothingItems, DefaultPlayerClothing->ClothingItems, STARTING_MONEY); } if (NewSave) { UGameplayStatics::SaveGameToSlot(NewSave, SLOT_NAME, SLOT_PLAYER); } return NewSave; } bool UGlobalSaveGameData::SaveGame(const TArray CurrentWardrobeClothing, const TArray CurrentPlayerClothing, int32 Money) { if (UGlobalSaveGameData* Save = CreateNewSaveGame(CurrentWardrobeClothing, CurrentPlayerClothing, (float)Money)) { return UGameplayStatics::SaveGameToSlot(Save, SLOT_NAME, SLOT_PLAYER); } return false; }