Finished phase 1

This commit is contained in:
2026-05-29 18:57:20 +03:00
parent 01cad5d8da
commit 6e44e9d4e8
11 changed files with 152 additions and 59 deletions
@@ -61,7 +61,7 @@ bool UClothingManager::IsBodyPartExposed(const EBodyPart BodyPart)
void UClothingManager::HydrateClothing()
{
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
for (const FItemSaveRecord& ItemSaveRecord : SaveSubsystem->GetCurrentSave()->EquippedItems)
for (const FItemSaveRecord& ItemSaveRecord : SaveSubsystem->GetCurrentSave()->GetEquippedItems())
{
UClothingItemInstance* ClothingItemInstance = UClothingItemInstance::CreateFromSave(this, ItemSaveRecord);
PutOnClothing(ClothingItemInstance);
@@ -125,10 +125,7 @@ void UClothingManager::SpawnClothingPickup(UClothingItemInstance* ItemInstance)
}
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
FItemSaveRecord ItemSaveRecord;
ItemSaveRecord.Init(ItemInstance);
ItemSaveRecord.WorldTransform = NewItemPickup->GetActorTransform();
SaveSubsystem->GetCurrentSave()->WorldItems.Push(ItemSaveRecord);
SaveSubsystem->GetCurrentSave()->AddWorldItem(ItemInstance, NewItemPickup->GetActorTransform());
NewItemPickup->SetItem(ItemInstance);
}
@@ -186,29 +183,17 @@ void UClothingManager::TakeClothing(UClothingItemInstance* ClothingItemInstance)
SetClothingSlotItem(SlotType, ClothingItemInstance);
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
FItemSaveRecord ItemSaveRecord;
ItemSaveRecord.Init(ClothingItemInstance);
SaveSubsystem->GetCurrentSave()->EquippedItems.Push(ItemSaveRecord);
SaveSubsystem->GetCurrentSave()->AddEquippedItem(ClothingItemInstance);
PutOnClothing(ClothingItemInstance);
}
UClothingItemInstance* UClothingManager::RemoveClothing(const EClothingSlotType ClothingSlotType)
{
TObjectPtr<UClothingItemInstance>* ExistingItemRef = EquippedClothing.Find(ClothingSlotType);
if (!ExistingItemRef)
{
UE_LOG(LogTemp, Warning, TEXT("UClothingManager::RemoveClothing ExistingItemRef == nullptr"));
if (!EquippedClothing.Contains(ClothingSlotType))
return nullptr;
}
UClothingItemInstance* ExistingItem = *ExistingItemRef;
if (!ExistingItem)
{
UE_LOG(LogTemp, Warning, TEXT("UClothingManager::RemoveClothing ExistingItem == nullptr"));
return nullptr;
}
UClothingItemInstance* ExistingItem = EquippedClothing[ClothingSlotType];
SetClothingSlotItem(ClothingSlotType, nullptr);
@@ -223,10 +208,7 @@ UClothingItemInstance* UClothingManager::RemoveClothing(const EClothingSlotType
OnClothingUnequip.Broadcast(ExistingItem);
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
SaveSubsystem->GetCurrentSave()->EquippedItems.RemoveAll([ExistingItem](const FItemSaveRecord& Item)
{
return Item.InstanceId == ExistingItem->GetInstanceId();
});
SaveSubsystem->GetCurrentSave()->RemoveEquippedItem(ExistingItem);
return ExistingItem;
}