FItemRegistry
Overview
FItemRegistry is a simple data structure that holds a TSoftClassPtr<AActor> representing an item class and a TArray<TScriptInterface<[ILimenInventoryItem](LimenInventoryItem.md)>> containing instances of items of that class. It is used within the ULimenInventoryComponent to manage inventory items.
Properties
Type | Name | Access | Description |
|---|---|---|---|
TSoftClassPtr | ItemClass | Public | A soft pointer to the item class. |
TArray<TScriptInterface< ILimenInventoryItem >> | ItemInstances | Public | An array of item instances. |
Functions
Return Type | Signature | Description |
|---|---|---|
void | GetLifetimeReplicatedProps(TArray & OutLifetimeProps) const | Registers properties to be replicated over the network. |
void | BeginPlay() override | Called when the component is initialized and added to an actor. |
FInventoryUpdate& | GetOnInventoryUpdated() override | Returns a reference to the |
FInventoryUpdate& | GetOnInventoryRefreshed() override | Returns a reference to the |
FInventoryItemUpdate& | GetOnItemFailedToAdd() override | Returns a reference to the |
FInventoryItemUpdate& | GetOnItemAdded() override | Returns a reference to the |
FInventoryItemUpdate& | GetOnItemRemoved() override | Returns a reference to the |
FInventoryItemUpdate& | GetOnItemUpdated() override | Returns a reference to the |
TArray<TScriptInterface< ILimenInventoryItem >> | LoadInventory(const TArray<TSubclassOf >& NewInventoryToLoad) | Loads new inventory items into the component. |
TArray<TScriptInterface< ILimenInventoryItem >> | SaveInventory() const | Saves the current inventory by collecting all item instances. |
bool | IsEmpty() const | Checks if the inventory is empty. |
bool | AddItem(const TScriptInterface< ILimenInventoryItem >& NewItem) | Adds a new item to the inventory. |
bool | CanAddItem(const TScriptInterface< ILimenInventoryItem >& NewItem) const | Checks if an item can be added to the inventory. |
bool | GetItemInstance(const TScriptInterface< ILimenInventoryItem >& Instance) | Removes a specific item instance from the inventory. |
template T* GetItem() | Retrieves an item of the specified type from the inventory. | |
template TScriptInterface< ILimenInventoryItem > GetItemInterface() | Retrieves an item interface of the specified type from the inventory. | |
template TArray<T*> GetAllItems() | Retrieves all items of a specific type from the inventory. | |
template T* GetItem(const TSubclassOf & Class) | Retrieves an item of the specified class from the inventory. | |
TArray<TScriptInterface< ILimenInventoryItem >> GetItems(TSubclassOf Class, const int32 Count) | Retrieves a specified number of items of a given class from the inventory. | |
TScriptInterface< ILimenInventoryItem > GetItem(TSubclassOf Class) | Retrieves an item instance of the specified class from the inventory. | |
bool ContainsItem(const TSubclassOf & Class) const | Checks if the inventory contains an item of the specified class. | |
bool ContainsInstance(const TScriptInterface< ILimenInventoryItem >& Instance) const | Checks if the inventory contains a specific item instance. | |
TMap<TSubclassOf , int32> PeekInventory() const | Retrieves a summary of inventory items without modifying the inventory. | |
TArray<TScriptInterface< ILimenInventoryItem >> PeekInventoryInstances(const TSubclassOf Class) const | Retrieves all instances of a specified class from the inventory without removing them. | |
TScriptInterface< ILimenInventoryItem > PeekInventoryInstance(const TSubclassOf Class) const | Retrieves the first instance of a specified class from the inventory without removing it. | |
TMap<TSubclassOf , int32> PeekItems() const | Provides a read-only view of the items currently available in the inventory. | |
TArray<TSubclassOf > PeekItemsClass() const | Retrieves a list of item classes currently stored in the inventory. | |
TMap<TSubclassOf , int32> PeekItems(const TSubclassOf & ItemClass) const | Retrieves a map of item classes and their counts that match or derive from the specified class. | |
TMap<TSubclassOf , int32> PeekItems(const UClass* InterfaceClass) const | Retrieves a mapping of item classes to their instance counts implementing a specific interface. | |
template T* PeekItemInstance(const TSubclassOf & ItemClass) const | Retrieves the first instance of a specific class from the inventory without removing it. | |
template T* PeekItemInstance() const | Retrieves the first available item instance of the specified type from the inventory without removing it. | |
template T* PeekItemInstance(const int32 Index) | Retrieves an item instance of the specified type at a given index without removing it. | |
template TArray<T*> PeekItemInstances() const | Retrieves an array with item instances of the specified type from the item registries without modifying their state. | |
template TArray<TScriptInterface< ILimenInventoryItem >> PeekItemInstancesByInterface() | Retrieves item instances that implement a specific interface. | |
int32 GetItemQuantity(const TSubclassOf & ItemClass) const | Retrieves how many items of the specified class are stored in the inventory. | |
bool HasCapacity(const int32 ExtraDesiredSpace) const | Checks if the inventory has enough capacity to accommodate additional space. | |
void ItemAdded(const TScriptInterface< ILimenInventoryItem >& NewItem) | Called when an item is added to the inventory. | |
void ItemRemoved(const TScriptInterface< ILimenInventoryItem >& Item) | Called when an item is removed from the inventory. | |
void ReplicateAddItem(const TScriptInterface< ILimenInventoryItem >& NewItem) | Replicates adding an item to the inventory on the server. | |
void ReplicateRemoveItem(const TScriptInterface< ILimenInventoryItem >& NewItem) | Replicates removing an item from the inventory on the server. | |
void AddItemToRegistry(const TScriptInterface< ILimenInventoryItem >& NewItem) | Adds a new item to the registry. | |
void RemoveItemsFromRegistry(const TSubclassOf & ItemToRemove, const int32 Count) | Removes items from the registry. | |
void UpdateInventoryLoad() | Updates the current inventory load. | |
FItemRegistry* FindItemRegistry(const TSubclassOf & ItemClass) | Finds an item registry by class. | |
const FItemRegistry* FindItemRegistry(const TSubclassOf & ItemClass) const | Finds a const item registry by class. | |
bool IsFirstOfType(const TSubclassOf & ItemClass) | Checks if the inventory is empty for items of the specified type. | |
TArray<TScriptInterface< ILimenInventoryItem >> SpawnItemInstances(const TScriptInterface< ILimenInventoryItem >& InItem) const | Spawns item instances based on an existing item. |
Usage & Implementation Notes
The component uses replication to ensure that inventory changes are synchronized across clients and the server.
It supports adding, removing, and retrieving items of various types.
The
OnInventoryUpdatedevent is triggered whenever the inventory state changes.The component can be configured with a limited size if needed.