Files
MaybeThisTime/Source/MaybeThisTime/Private/Items/ItemRegistry.cpp
T
2026-08-15 14:53:19 +02:00

50 lines
1.3 KiB
C++

// ItemRegistry.cpp
#include "Items/ItemRegistry.h"
void UItemRegistry::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
ItemDataTable = TSoftObjectPtr<UDataTable>(FSoftObjectPath(TEXT("/Game/Inventory/ItemRegisterDataTable.ItemRegisterDataTable")));
LoadTable();
}
void UItemRegistry::LoadTable()
{
if (ItemDataTable.IsNull())
{
UE_LOG(LogTemp, Warning, TEXT("ItemRegistry: No DataTable assigned!"));
return;
}
LoadedTable = ItemDataTable.LoadSynchronous();
if (!LoadedTable)
{
UE_LOG(LogTemp, Error, TEXT("ItemRegistry: Failed to load DataTable!"));
return;
}
UE_LOG(LogTemp, Log, TEXT("ItemRegistry: Loaded %d items"),LoadedTable->GetRowNames().Num());
}
UItemDefinition* UItemRegistry::GetDefinition(FName ItemID) const
{
if (!LoadedTable || ItemID.IsNone()) return nullptr;
const FItemRegistryRow* Row = LoadedTable->FindRow<FItemRegistryRow>(ItemID, TEXT("ItemRegistry::GetDefinition"));
if (!Row || !Row->Definition) return nullptr;
return Row->Definition;
}
bool UItemRegistry::IsValidItem(FName ItemID) const
{
return GetDefinition(ItemID) != nullptr;
}
TArray<FName> UItemRegistry::GetAllItemIDs() const
{
if (!LoadedTable) return {};
return LoadedTable->GetRowNames();
}