Add inventory persistence restore hook
This commit is contained in:
@@ -136,6 +136,17 @@ bool UAgrarianInventoryComponent::SplitStackByIndex(int32 StackIndex, int32 Spli
|
||||
return true;
|
||||
}
|
||||
|
||||
void UAgrarianInventoryComponent::RestoreSavedItems(const TArray<FAgrarianItemStack>& SavedItems)
|
||||
{
|
||||
if (!GetOwner() || !GetOwner()->HasAuthority())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Items = SavedItems;
|
||||
BroadcastInventoryChanged();
|
||||
}
|
||||
|
||||
void UAgrarianInventoryComponent::ServerAddItem_Implementation(const FAgrarianItemStack& Stack)
|
||||
{
|
||||
AddItem(Stack);
|
||||
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
|
||||
bool SplitStackByIndex(int32 StackIndex, int32 SplitQuantity);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Inventory")
|
||||
void RestoreSavedItems(const TArray<FAgrarianItemStack>& SavedItems);
|
||||
|
||||
UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Agrarian|Inventory")
|
||||
void ServerAddItem(const FAgrarianItemStack& Stack);
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ int32 UAgrarianPersistenceSubsystem::RestorePlayers(const UAgrarianSaveGame* Sav
|
||||
|
||||
if (UAgrarianInventoryComponent* InventoryComponent = Character->GetInventoryComponent())
|
||||
{
|
||||
InventoryComponent->Items = SavedPlayer->Inventory;
|
||||
InventoryComponent->RestoreSavedItems(SavedPlayer->Inventory);
|
||||
}
|
||||
|
||||
RestoredCount++;
|
||||
|
||||
Reference in New Issue
Block a user