Added world items to save game

This commit is contained in:
2026-05-28 22:36:29 +03:00
parent 78840dcfb1
commit 8c49583a69
8 changed files with 41 additions and 13 deletions
@@ -123,6 +123,12 @@ void UClothingManager::SpawnClothingPickup(UClothingItemInstance* ItemInstance)
UE_LOG(LogTemp, Warning, TEXT("UClothingManager::SpawnClothingPickup NewItemPickup == nullptr"));
return;
}
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
FItemSaveRecord ItemSaveRecord;
ItemSaveRecord.Init(ItemInstance);
ItemSaveRecord.WorldTransform = NewItemPickup->GetActorTransform();
SaveSubsystem->GetCurrentSave()->WorldItems.Push(ItemSaveRecord);
NewItemPickup->SetItem(ItemInstance);
}
@@ -184,10 +190,6 @@ void UClothingManager::TakeClothing(UClothingItemInstance* ClothingItemInstance)
ItemSaveRecord.Init(ClothingItemInstance);
SaveSubsystem->GetCurrentSave()->EquippedItems.Push(ItemSaveRecord);
SaveSubsystem->GetCurrentSave()->DroppedItems.RemoveAll([ClothingItemInstance](const FItemSaveRecord& Item)
{
return Item.InstanceId == ClothingItemInstance->GetInstanceId();
});
PutOnClothing(ClothingItemInstance);
}
@@ -235,11 +237,6 @@ void UClothingManager::DropClothing(const EClothingSlotType ClothingType)
if (!ClothingItemInstance)
return;
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
FItemSaveRecord ItemSaveRecord;
ItemSaveRecord.Init(ClothingItemInstance);
SaveSubsystem->GetCurrentSave()->DroppedItems.Push(ItemSaveRecord);
SpawnClothingPickup(ClothingItemInstance);
OnClothingDropped.Broadcast(ClothingItemInstance);
@@ -4,12 +4,14 @@
#include "Kismet/GameplayStatics.h"
#include "NakedDesire/Clothing/ClothingItem.h"
#include "NakedDesire/Clothing/ClothingItemInstance.h"
#include "NakedDesire/Interactables/ItemPickup.h"
#include "UObject/ConstructorHelpers.h"
#include "NakedDesire/Interactables/Wardrobe.h"
#include "NakedDesire/MissionBuilder/MissionsConfig.h"
#include "NakedDesire/MissionBuilder/MissionsManager.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
#include "NakedDesire/SaveGame/SaveSubsystem.h"
void ANakedDesireGameMode::RestartGame()
@@ -67,6 +69,17 @@ void ANakedDesireGameMode::BeginPlay()
Wardrobe = WardrobeActor;
}
}
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
for (const auto& Item : SaveSubsystem->GetCurrentSave()->WorldItems)
{
UClothingItemInstance* NewItemInstance = NewObject<UClothingItemInstance>(this);
NewItemInstance->Init(Item.Definition.Get());
NewItemInstance->Condition = Item.Condition;
NewItemInstance->SetInstanceId(Item.InstanceId);
AItemPickup* NewItemPickup = GetWorld()->SpawnActor<AItemPickup>(ItemPickupClass, Item.WorldTransform);
NewItemPickup->SetItem(NewItemInstance);
}
}
void ANakedDesireGameMode::RefreshDailyMissions()
@@ -6,6 +6,7 @@
#include "GameFramework/GameModeBase.h"
#include "NakedDesireGameMode.generated.h"
class AItemPickup;
class UClothingItemInstance;
class UMissionsConfig;
class AWardrobe;
@@ -49,6 +50,9 @@ protected:
private:
void RefreshDailyMissions();
UPROPERTY(EditDefaultsOnly, Category = "Items")
TSubclassOf<AItemPickup> ItemPickupClass;
};
@@ -4,10 +4,14 @@
#include "ItemPickup.h"
#include "Components/BoxComponent.h"
#include "Components/WidgetComponent.h"
#include "Kismet/GameplayStatics.h"
#include "NakedDesire/Clothing/ClothingItem.h"
#include "NakedDesire/Clothing/ClothingItemInstance.h"
#include "NakedDesire/Clothing/ClothingManager.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
#include "NakedDesire/SaveGame/SaveSubsystem.h"
AItemPickup::AItemPickup()
{
@@ -27,7 +31,12 @@ void AItemPickup::Interact_Implementation(ANakedDesireCharacter* Player)
{
if (ClothingItemInstance)
{
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
Player->ClothingManager->TakeClothing(ClothingItemInstance);
SaveSubsystem->GetCurrentSave()->WorldItems.RemoveAll([this](const FItemSaveRecord& Item)
{
return ClothingItemInstance->GetInstanceId() == Item.InstanceId;
});
Destroy();
}
}
@@ -15,3 +15,8 @@ void UItemInstance::PostDuplicate(EDuplicateMode::Type DuplicateMode)
Super::PostDuplicate(DuplicateMode);
InstanceId = FGuid::NewGuid();
}
void UItemInstance::SetInstanceId(FGuid InId)
{
InstanceId = InId;
}
+1 -1
View File
@@ -13,8 +13,8 @@ public:
virtual void PostInitProperties() override;
virtual void PostDuplicate(EDuplicateMode::Type DuplicateMode) override;
UFUNCTION(BlueprintPure, Category = "Item")
FGuid GetInstanceId() const { return InstanceId; }
void SetInstanceId(FGuid InId);
protected:
UPROPERTY(VisibleAnywhere, SaveGame, BlueprintReadOnly, Category = "Item", meta = (AllowPrivateAccess = "true"))
@@ -32,7 +32,7 @@ public:
TArray<FItemSaveRecord> EquippedItems;
UPROPERTY(SaveGame)
TArray<FItemSaveRecord> DroppedItems;
TArray<FItemSaveRecord> WorldItems;
UPROPERTY(SaveGame)
int32 DaysPassed = 0;