Files
ChildHood/Source/ChildHood/Interaction/PersistenceSubsystem.cpp
T

71 lines
2.4 KiB
C++

// ChildHood Project - 跨场景持久化子系统 实现
#include "Interaction/PersistenceSubsystem.h"
#include "ChildHood.h"
// ============================================================================
// 物品消耗状态
// ============================================================================
bool UPersistenceSubsystem::IsInteractableConsumed(FName InteractableId) const
{
return ConsumedInteractableIDs.Contains(InteractableId);
}
void UPersistenceSubsystem::MarkInteractableConsumed(FName InteractableId)
{
ConsumedInteractableIDs.Add(InteractableId);
UE_LOG(LogChildHood, Log, TEXT("PersistenceSubsystem: 交互物已消耗: %s"), *InteractableId.ToString());
}
// ============================================================================
// 门状态
// ============================================================================
bool UPersistenceSubsystem::IsDoorOpen(FName DoorId) const
{
const bool* Found = DoorStates.Find(DoorId);
return Found ? *Found : false;
}
void UPersistenceSubsystem::SetDoorOpen(FName DoorId, bool bIsOpen)
{
DoorStates.Add(DoorId, bIsOpen);
UE_LOG(LogChildHood, Log, TEXT("PersistenceSubsystem: 门状态更新: %s → %s"),
*DoorId.ToString(), bIsOpen ? TEXT("开") : TEXT("关"));
}
// ============================================================================
// 收集系统状态
// ============================================================================
void UPersistenceSubsystem::GetCollectionState(TSet<FName>& OutIDs, int32& OutProgress, bool& OutComplete) const
{
OutIDs = CollectionCollectedIDs;
OutProgress = CollectionProgress;
OutComplete = bCollectionComplete;
}
void UPersistenceSubsystem::SetCollectionState(const TSet<FName>& InIDs, int32 InProgress, bool bInComplete)
{
CollectionCollectedIDs = InIDs;
CollectionProgress = InProgress;
bCollectionComplete = bInComplete;
UE_LOG(LogChildHood, Log, TEXT("PersistenceSubsystem: 收集状态更新 - 进度 %d, 完成 %s"),
CollectionProgress, bCollectionComplete ? TEXT("是") : TEXT("否"));
}
// ============================================================================
// 重置
// ============================================================================
void UPersistenceSubsystem::ResetAll()
{
ConsumedInteractableIDs.Empty();
DoorStates.Empty();
CollectionCollectedIDs.Empty();
CollectionProgress = 0;
bCollectionComplete = false;
UE_LOG(LogChildHood, Log, TEXT("PersistenceSubsystem: 所有持久数据已重置"));
}