// © 2025 Naked People Team. All Rights Reserved. #include "SaveSubsystem.h" #include "GlobalSaveGameData.h" #include "ItemSaveRecord.h" #include "StartingSaveData.h" #include "NakedDesire/Clothing/ClothingItem.h" #include "NakedDesire/Clothing/ClothingItemInstance.h" #include "NakedDesire/Global/NakedDesireGameInstance.h" void USaveSubsystem::LoadGame(const FString& SlotName) { CurrentSave = UGlobalSaveGameData::LoadGame(SlotName); } bool USaveSubsystem::SaveGame(const FString& SlotName) const { return UGlobalSaveGameData::SaveGame(CurrentSave, SlotName); } void USaveSubsystem::AddItem(const FItemSaveRecord& Record) { Items.Add(Record); } void USaveSubsystem::RemoveItem(const FGuid& InstanceId) { Items.RemoveAll([InstanceId](const FItemSaveRecord& Item) { return Item.InstanceId == InstanceId; }); } void USaveSubsystem::Initialize(FSubsystemCollectionBase& Collection) { Super::Initialize(Collection); LoadGame(); } UGlobalSaveGameData* USaveSubsystem::GetCurrentSave() { if (!CurrentSave) { CurrentSave = UGlobalSaveGameData::LoadGame(ActiveSlotName); if (!CurrentSave) { CurrentSave = UGlobalSaveGameData::CreateNewSaveGame(); PopulateStartingData(CurrentSave); UGlobalSaveGameData::SaveGame(CurrentSave, ActiveSlotName); } } return CurrentSave; } void USaveSubsystem::PopulateStartingData(UGlobalSaveGameData* Save) const { if (!Save) return; const UNakedDesireGameInstance* GameInstance = Cast(GetGameInstance()); if (!GameInstance || !GameInstance->StartingSaveData) return; for (UClothingItem* ClothingDef : GameInstance->StartingSaveData->StartingClothing) { if (!ClothingDef) continue; UClothingItemInstance* Instance = NewObject(Save); Instance->Init(ClothingDef); FItemSaveRecord Record; Record.Init(Instance); Save->EquippedItems.Add(Record); } }