Finished phase 1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void ANakedDesireGameMode::BeginPlay()
|
||||
}
|
||||
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
for (const auto& Item : SaveSubsystem->GetCurrentSave()->WorldItems)
|
||||
for (const auto& Item : SaveSubsystem->GetCurrentSave()->GetWorldItems())
|
||||
{
|
||||
UClothingItemInstance* NewItemInstance = NewObject<UClothingItemInstance>(this);
|
||||
NewItemInstance->Init(Item.Definition.Get());
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#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()
|
||||
@@ -33,10 +32,7 @@ void AItemPickup::Interact_Implementation(ANakedDesireCharacter* Player)
|
||||
{
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
Player->ClothingManager->TakeClothing(ClothingItemInstance);
|
||||
SaveSubsystem->GetCurrentSave()->WorldItems.RemoveAll([this](const FItemSaveRecord& Item)
|
||||
{
|
||||
return ClothingItemInstance->GetInstanceId() == Item.InstanceId;
|
||||
});
|
||||
SaveSubsystem->GetCurrentSave()->RemoveWorldItem(ClothingItemInstance);
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,22 +10,14 @@
|
||||
void AWardrobe::AddItem(UClothingItemInstance* ClothingItemInstance)
|
||||
{
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
|
||||
ClothingItems.Push(ClothingItemInstance);
|
||||
FItemSaveRecord ItemSaveRecord;
|
||||
ItemSaveRecord.Init(ClothingItemInstance);
|
||||
|
||||
SaveSubsystem->GetCurrentSave()->WardrobeItems.Push(ItemSaveRecord);
|
||||
SaveSubsystem->GetCurrentSave()->AddWardrobeItem(ClothingItemInstance);
|
||||
}
|
||||
|
||||
void AWardrobe::RemoveItem(UClothingItemInstance* ClothingItemInstance) const
|
||||
{
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
|
||||
SaveSubsystem->GetCurrentSave()->WardrobeItems.RemoveAll([ClothingItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ClothingItemInstance->GetInstanceId();
|
||||
});
|
||||
SaveSubsystem->GetCurrentSave()->RemoveWardrobeItem(ClothingItemInstance);
|
||||
}
|
||||
|
||||
void AWardrobe::BeginPlay()
|
||||
@@ -35,7 +27,7 @@ void AWardrobe::BeginPlay()
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
UGlobalSaveGameData* SaveGame = SaveSubsystem->GetCurrentSave();
|
||||
|
||||
for (const FItemSaveRecord& ItemSaveRecord : SaveGame->WardrobeItems)
|
||||
for (const FItemSaveRecord& ItemSaveRecord : SaveGame->GetWardrobeItems())
|
||||
{
|
||||
UClothingItemInstance* NewItemInstance = UClothingItemInstance::CreateFromSave(this, ItemSaveRecord);
|
||||
ClothingItems.Push(NewItemInstance);
|
||||
|
||||
@@ -16,7 +16,6 @@ void UMissionsManager::BeginPlay()
|
||||
Super::BeginPlay();
|
||||
|
||||
Player = Cast<ANakedDesireCharacter>(GetOwner());
|
||||
UE_LOG(LogTemp, Warning, TEXT("Player is NULL %s"), Player == nullptr ? TEXT("True") : TEXT("False"));
|
||||
|
||||
for (const auto& Mission : AvailableMissions)
|
||||
{
|
||||
|
||||
@@ -219,6 +219,12 @@ bool ANakedDesireCharacter::CheckSight(const FVector& StartLocation, const FVect
|
||||
return bHit;
|
||||
}
|
||||
|
||||
void ANakedDesireCharacter::LogTest()
|
||||
{
|
||||
UClothingItemInstance* ClothingItemInstance = ClothingManager->GetSlotClothing(EClothingSlotType::UnderwearTop);
|
||||
UE_LOG(LogTemp, Warning, TEXT("ANakedDesireCharacter::LogTest %s"), *ClothingItemInstance->GetInstanceId().ToString());
|
||||
}
|
||||
|
||||
void ANakedDesireCharacter::OnClothingEquip(UClothingItemInstance* ClothingItemInstance)
|
||||
{
|
||||
if (ClothingItemInstance->GetClothingItem()->HiddenBodyParts.Contains(EBodyPart::Ass))
|
||||
|
||||
@@ -191,6 +191,9 @@ private:
|
||||
|
||||
bool CheckSight(const FVector& StartLocation, const FVector& EndLocation, FHitResult& HitResult, const AActor* IgnoreActor);
|
||||
|
||||
UFUNCTION(Exec)
|
||||
void LogTest();
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<ANakedDesireHUD> HUD;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
|
||||
#include "GlobalSaveGameData.h"
|
||||
|
||||
#include "ItemSaveRecord.h"
|
||||
#include "NakedDesire/Global/Constants.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
@@ -29,4 +31,102 @@ UGlobalSaveGameData* UGlobalSaveGameData::LoadGame(const FString& SlotName)
|
||||
bool UGlobalSaveGameData::SaveGame(UGlobalSaveGameData* SaveGameData, const FString& SlotName)
|
||||
{
|
||||
return UGameplayStatics::SaveGameToSlot(SaveGameData, SlotName, SLOT_PLAYER);
|
||||
}
|
||||
}
|
||||
|
||||
FItemSaveRecord UGlobalSaveGameData::AddWardrobeItem(const UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
FItemSaveRecord NewSaveRecord;
|
||||
NewSaveRecord.Init(ItemInstance);
|
||||
WardrobeItems.Push(NewSaveRecord);
|
||||
return NewSaveRecord;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::UpdateWardrobeItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
for (auto& ItemSaveRecord : WardrobeItems)
|
||||
{
|
||||
if (ItemSaveRecord.InstanceId == ItemInstance->GetInstanceId())
|
||||
{
|
||||
ItemSaveRecord.Init(ItemInstance);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::RemoveWardrobeItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
const int32 RemovedElementsCount = WardrobeItems.RemoveAll([ItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
return RemovedElementsCount > 0;
|
||||
}
|
||||
|
||||
FItemSaveRecord UGlobalSaveGameData::AddEquippedItem(const UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
FItemSaveRecord NewSaveRecord;
|
||||
NewSaveRecord.Init(ItemInstance);
|
||||
EquippedItems.Push(NewSaveRecord);
|
||||
return NewSaveRecord;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::UpdateEquippedItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
for (auto& ItemSaveRecord : EquippedItems)
|
||||
{
|
||||
if (ItemSaveRecord.InstanceId == ItemInstance->GetInstanceId())
|
||||
{
|
||||
ItemSaveRecord.Init(ItemInstance);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::RemoveEquippedItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
const int32 RemovedElementsCount = EquippedItems.RemoveAll([ItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
return RemovedElementsCount > 0;
|
||||
}
|
||||
|
||||
FItemSaveRecord UGlobalSaveGameData::AddWorldItem(const UClothingItemInstance* ItemInstance, FTransform Transform)
|
||||
{
|
||||
FItemSaveRecord NewSaveRecord;
|
||||
NewSaveRecord.Init(ItemInstance);
|
||||
NewSaveRecord.WorldTransform = Transform;
|
||||
WorldItems.Push(NewSaveRecord);
|
||||
return NewSaveRecord;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::UpdateWorldItem(UClothingItemInstance* ItemInstance, FTransform Transform)
|
||||
{
|
||||
for (auto& ItemSaveRecord : WorldItems)
|
||||
{
|
||||
if (ItemSaveRecord.InstanceId == ItemInstance->GetInstanceId())
|
||||
{
|
||||
ItemSaveRecord.Init(ItemInstance);
|
||||
ItemSaveRecord.WorldTransform = Transform;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UGlobalSaveGameData::RemoveWorldItem(UClothingItemInstance* ItemInstance)
|
||||
{
|
||||
const int32 RemovedElementsCount = WorldItems.RemoveAll([ItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
return RemovedElementsCount > 0;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/SaveGame.h"
|
||||
#include "NakedDesire/Global/Constants.h"
|
||||
#include "ItemSaveRecord.h"
|
||||
#include "GlobalSaveGameData.generated.h"
|
||||
|
||||
struct FItemSaveRecord;
|
||||
class UClothingItemInstance;
|
||||
|
||||
UCLASS()
|
||||
class NAKEDDESIRE_API UGlobalSaveGameData : public USaveGame
|
||||
@@ -24,19 +25,35 @@ public:
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
float Money = 0;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WardrobeItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> EquippedItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WorldItems;
|
||||
|
||||
FItemSaveRecord AddWardrobeItem(const UClothingItemInstance* ItemInstance);
|
||||
bool UpdateWardrobeItem(UClothingItemInstance* ItemInstance);
|
||||
bool RemoveWardrobeItem(UClothingItemInstance* ItemInstance);
|
||||
TArray<FItemSaveRecord> GetWardrobeItems() const { return WardrobeItems; }
|
||||
|
||||
FItemSaveRecord AddEquippedItem(const UClothingItemInstance* ItemInstance);
|
||||
bool UpdateEquippedItem(UClothingItemInstance* ItemInstance);
|
||||
bool RemoveEquippedItem(UClothingItemInstance* ItemInstance);
|
||||
TArray<FItemSaveRecord> GetEquippedItems() const { return EquippedItems; }
|
||||
|
||||
FItemSaveRecord AddWorldItem(const UClothingItemInstance* ItemInstance, FTransform Transform);
|
||||
bool UpdateWorldItem(UClothingItemInstance* ItemInstance, FTransform Transform);
|
||||
bool RemoveWorldItem(UClothingItemInstance* ItemInstance);
|
||||
TArray<FItemSaveRecord> GetWorldItems() const { return WorldItems; }
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
int32 DaysPassed = 0;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
float HourOfDay = 0.0f;
|
||||
|
||||
private:
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WardrobeItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> EquippedItems;
|
||||
|
||||
UPROPERTY(SaveGame)
|
||||
TArray<FItemSaveRecord> WorldItems;
|
||||
};
|
||||
@@ -67,11 +67,9 @@ void USaveSubsystem::PopulateStartingData(UGlobalSaveGameData* Save) const
|
||||
if (!ClothingDef)
|
||||
continue;
|
||||
|
||||
// TODO: Refactor. Skip converting to ClothingItemInstance
|
||||
UClothingItemInstance* Instance = NewObject<UClothingItemInstance>(Save);
|
||||
Instance->Init(ClothingDef);
|
||||
|
||||
FItemSaveRecord Record;
|
||||
Record.Init(Instance);
|
||||
Save->EquippedItems.Add(Record);
|
||||
Save->AddEquippedItem(Instance);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user