Completed phase 1

This commit is contained in:
2026-05-25 14:14:52 +03:00
parent 799fc8a4ae
commit 43ddad9217
22 changed files with 255 additions and 55 deletions
@@ -5,12 +5,23 @@
#include "ClothingItem.h"
#include "ClothingItemInstance.h"
#include "GameFramework/Character.h"
#include "Kismet/GameplayStatics.h"
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
#include "NakedDesire/SaveGame/SaveSubsystem.h"
UClothingManager::UClothingManager()
{
PrimaryComponentTick.bCanEverTick = false;
}
void UClothingManager::BeginPlay()
{
Super::BeginPlay();
HydrateClothing();
}
bool UClothingManager::IsBodyTypeExposed(const EBodyPart BodyPart)
{
for (const auto& ClothingSlot : ClothingSlots)
@@ -63,13 +74,14 @@ TArray<UClothingItemInstance*> UClothingManager::GetEquippedClothing()
return EquippedClothingItems;
}
void UClothingManager::HydrateClothing(UGlobalSaveGameData* SaveGameData)
void UClothingManager::HydrateClothing()
{
// for (const FClothingItemSaveData& ClothingItemSaveData : SaveGameData->PlayerClothing)
// {
// UClothingItemData* ClothingItemData = UClothingItemData::CreateFromSaveData(ClothingItemSaveData);
// PutOnClothing(ClothingItemData);
// }
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
for (const FItemSaveRecord& ItemSaveRecord : SaveSubsystem->GetCurrentSave()->EquippedItems)
{
UClothingItemInstance* ClothingItemInstance = UClothingItemInstance::CreateFromSave(this, ItemSaveRecord);
PutOnClothing(ClothingItemInstance);
}
}
float UClothingManager::GetHeelHeight()
@@ -109,6 +121,22 @@ void UClothingManager::PutOnClothing(UClothingItemInstance* ClothingItemInstance
{
ClothingSlotData.MeshComponent->SetLeaderPoseComponent(Cast<ACharacter>(GetOwner())->GetMesh());
}
UClothingItem* ClothingItem = ClothingItemInstance->GetClothingItem();
if (ClothingItem->SlotType == EClothingSlotType::Bodysuit)
{
DropClothing(EClothingSlotType::Top);
DropClothing(EClothingSlotType::Bottom);
DropClothing(EClothingSlotType::UnderwearTop);
DropClothing(EClothingSlotType::UnderwearBottom);
}
else if (ClothingItem->SlotType == EClothingSlotType::Top ||
ClothingItem->SlotType == EClothingSlotType::Bottom ||
ClothingItem->SlotType == EClothingSlotType::UnderwearTop ||
ClothingItem->SlotType == EClothingSlotType::UnderwearBottom)
{
DropClothing(EClothingSlotType::Bodysuit);
}
OnClothingEquip.Broadcast(ClothingItemInstance);
}
@@ -125,6 +153,16 @@ void UClothingManager::TakeClothing(UClothingItemInstance* ClothingItemInstance)
ClothingSlotData.ClothingItemInstance = ClothingItemInstance;
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
FItemSaveRecord ItemSaveRecord;
ItemSaveRecord.Init(ClothingItemInstance);
SaveSubsystem->GetCurrentSave()->EquippedItems.Push(ItemSaveRecord);
SaveSubsystem->GetCurrentSave()->DroppedItems.RemoveAll([ClothingItemInstance](const FItemSaveRecord& Item)
{
return Item.InstanceId == ClothingItemInstance->GetInstanceId();
});
PutOnClothing(ClothingItemInstance);
}
@@ -149,6 +187,12 @@ UClothingItemInstance* UClothingManager::RemoveClothing(const EClothingSlotType
}
OnClothingUnequip.Broadcast(ClothingItemInstance);
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
SaveSubsystem->GetCurrentSave()->EquippedItems.RemoveAll([ClothingItemInstance](const FItemSaveRecord& Item)
{
return Item.InstanceId == ClothingItemInstance->GetInstanceId();
});
return ClothingItemInstance;
}
@@ -158,6 +202,11 @@ void UClothingManager::DropClothing(const EClothingSlotType ClothingType)
const UClothingItemInstance* ClothingItemInstance = RemoveClothing(ClothingType);
if (!ClothingItemInstance)
return;
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
FItemSaveRecord ItemSaveRecord;
ItemSaveRecord.Init(ClothingItemInstance);
SaveSubsystem->GetCurrentSave()->DroppedItems.Push(ItemSaveRecord);
OnClothingDropped.Broadcast(ClothingItemInstance);
}