Skip to content

Commit

Permalink
Initial support for UE4.27 + Packaging Fixes (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucoiso committed Feb 20, 2023
1 parent e66388c commit 572fc77
Show file tree
Hide file tree
Showing 29 changed files with 167 additions and 121 deletions.
2 changes: 1 addition & 1 deletion Source/ElementusInventory/ElementusInventory.Build.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

using UnrealBuildTool;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#include "Actors/ElementusInventoryPackage.h"
Expand All @@ -10,6 +10,10 @@
#include "LogElementusInventory.h"
#include <Net/UnrealNetwork.h>

#if ENGINE_MAJOR_VERSION < 5
#include <Net/Core/PushModel/PushModel.h>
#endif

#ifdef UE_INLINE_GENERATED_CPP_BY_NAME
#include UE_INLINE_GENERATED_CPP_BY_NAME(ElementusInventoryPackage)
#endif
Expand Down Expand Up @@ -40,7 +44,7 @@ void AElementusInventoryPackage::BeginPlay()

SetDestroyOnEmpty(bDestroyWhenInventoryIsEmpty);

if (bDestroyWhenInventoryIsEmpty && PackageInventory->GetItemsArray().IsEmpty())
if (bDestroyWhenInventoryIsEmpty && UElementusInventoryFunctions::HasEmptyParam(PackageInventory->GetItemsArray()))
{
Destroy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#include "Components/ElementusInventoryComponent.h"
Expand Down Expand Up @@ -90,7 +90,7 @@ bool UElementusInventoryComponent::CanGiveItem(const FElementusItemInfo InItemIn
return false;
}

if (TArray<int32> InIndex; FindAllItemIndexesWithInfo(InItemInfo, InIndex))
if (TArray<int32> InIndex; FindAllItemIndexesWithInfo(InItemInfo, InIndex, FGameplayTagContainer::EmptyContainer))
{
int32 Quantity = 0u;
for (const int32& Index : InIndex)
Expand Down Expand Up @@ -169,9 +169,9 @@ void UElementusInventoryComponent::ForceInventoryValidation()
}
}

if (!IndexesToRemove.IsEmpty())
if (!UElementusInventoryFunctions::HasEmptyParam(IndexesToRemove))
{
for (const uint32& Iterator : IndexesToRemove)
for (const int32& Iterator : IndexesToRemove)
{
if (bAllowEmptySlots)
{
Expand All @@ -183,15 +183,15 @@ void UElementusInventoryComponent::ForceInventoryValidation()
}
}
}
if (!NewItems.IsEmpty())
if (!UElementusInventoryFunctions::HasEmptyParam(NewItems))
{
ElementusItems.Append(NewItems);
}

NotifyInventoryChange();
}

bool UElementusInventoryComponent::FindFirstItemIndexWithInfo(const FElementusItemInfo InItemInfo, int32& OutIndex, const FGameplayTagContainer IgnoreTags, const int32 Offset) const
bool UElementusInventoryComponent::FindFirstItemIndexWithInfo(const FElementusItemInfo InItemInfo, int32& OutIndex, const FGameplayTagContainer& IgnoreTags, const int32 Offset) const
{
for (int32 Iterator = Offset; Iterator < ElementusItems.Num(); ++Iterator)
{
Expand All @@ -212,7 +212,7 @@ bool UElementusInventoryComponent::FindFirstItemIndexWithInfo(const FElementusIt
return false;
}

bool UElementusInventoryComponent::FindFirstItemIndexWithTags(const FGameplayTagContainer WithTags, int32& OutIndex, const FGameplayTagContainer IgnoreTags, const int32 Offset) const
bool UElementusInventoryComponent::FindFirstItemIndexWithTags(const FGameplayTagContainer WithTags, int32& OutIndex, const FGameplayTagContainer& IgnoreTags, const int32 Offset) const
{
for (int32 Iterator = Offset; Iterator < ElementusItems.Num(); ++Iterator)
{
Expand All @@ -230,7 +230,7 @@ bool UElementusInventoryComponent::FindFirstItemIndexWithTags(const FGameplayTag
return false;
}

bool UElementusInventoryComponent::FindFirstItemIndexWithId(const FPrimaryElementusItemId InId, int32& OutIndex, const FGameplayTagContainer IgnoreTags, const int32 Offset) const
bool UElementusInventoryComponent::FindFirstItemIndexWithId(const FPrimaryElementusItemId InId, int32& OutIndex, const FGameplayTagContainer& IgnoreTags, const int32 Offset) const
{
for (int32 Iterator = Offset; Iterator < ElementusItems.Num(); ++Iterator)
{
Expand All @@ -245,7 +245,7 @@ bool UElementusInventoryComponent::FindFirstItemIndexWithId(const FPrimaryElemen
return false;
}

bool UElementusInventoryComponent::FindAllItemIndexesWithInfo(const FElementusItemInfo InItemInfo, TArray<int32>& OutIndexes, const FGameplayTagContainer IgnoreTags) const
bool UElementusInventoryComponent::FindAllItemIndexesWithInfo(const FElementusItemInfo InItemInfo, TArray<int32>& OutIndexes, const FGameplayTagContainer& IgnoreTags) const
{
for (auto Iterator = ElementusItems.CreateConstIterator(); Iterator; ++Iterator)
{
Expand All @@ -267,10 +267,10 @@ bool UElementusInventoryComponent::FindAllItemIndexesWithInfo(const FElementusIt
}
}

return !OutIndexes.IsEmpty();
return !UElementusInventoryFunctions::HasEmptyParam(OutIndexes);
}

bool UElementusInventoryComponent::FindAllItemIndexesWithTags(const FGameplayTagContainer WithTags, TArray<int32>& OutIndexes, const FGameplayTagContainer IgnoreTags) const
bool UElementusInventoryComponent::FindAllItemIndexesWithTags(const FGameplayTagContainer WithTags, TArray<int32>& OutIndexes, const FGameplayTagContainer& IgnoreTags) const
{
for (auto Iterator = ElementusItems.CreateConstIterator(); Iterator; ++Iterator)
{
Expand All @@ -286,10 +286,10 @@ bool UElementusInventoryComponent::FindAllItemIndexesWithTags(const FGameplayTag
}
}

return !OutIndexes.IsEmpty();
return !UElementusInventoryFunctions::HasEmptyParam(OutIndexes);
}

bool UElementusInventoryComponent::FindAllItemIndexesWithId(const FPrimaryElementusItemId InId, TArray<int32>& OutIndexes, const FGameplayTagContainer IgnoreTags) const
bool UElementusInventoryComponent::FindAllItemIndexesWithId(const FPrimaryElementusItemId InId, TArray<int32>& OutIndexes, const FGameplayTagContainer& IgnoreTags) const
{
for (auto Iterator = ElementusItems.CreateConstIterator(); Iterator; ++Iterator)
{
Expand All @@ -299,7 +299,7 @@ bool UElementusInventoryComponent::FindAllItemIndexesWithId(const FPrimaryElemen
}
}

return !OutIndexes.IsEmpty();
return !UElementusInventoryFunctions::HasEmptyParam(OutIndexes);
}

bool UElementusInventoryComponent::ContainsItem(const FElementusItemInfo InItemInfo, const bool bIgnoreTags) const
Expand Down Expand Up @@ -331,7 +331,6 @@ bool UElementusInventoryComponent::IsInventoryEmpty() const
return bOutput;
}

#if WITH_EDITORONLY_DATA
void UElementusInventoryComponent::DebugInventory()
{
#if !UE_BUILD_SHIPPING
Expand All @@ -356,7 +355,6 @@ void UElementusInventoryComponent::DebugInventory()
UE_LOG(LogElementusInventory_Internal, Warning, TEXT("Component Memory Size: %d"), GetResourceSizeBytes(EResourceSizeMode::EstimatedTotal));
#endif
}
#endif

void UElementusInventoryComponent::ClearInventory_Implementation()
{
Expand All @@ -374,7 +372,7 @@ void UElementusInventoryComponent::GetItemIndexesFrom_Implementation(UElementusI
}

TArray<FElementusItemInfo> Modifiers;
for (const uint32& Iterator : ItemIndexes)
for (const int32& Iterator : ItemIndexes)
{
if (OtherInventory->ElementusItems.IsValidIndex(Iterator))
{
Expand Down Expand Up @@ -403,7 +401,7 @@ void UElementusInventoryComponent::GiveItemIndexesTo_Implementation(UElementusIn
}

TArray<FElementusItemInfo> Modifiers;
for (const uint32& Iterator : ItemIndexes)
for (const int32& Iterator : ItemIndexes)
{
if (OtherInventory->ElementusItems.IsValidIndex(Iterator))
{
Expand Down Expand Up @@ -468,12 +466,12 @@ void UElementusInventoryComponent::GiveItemsTo_Implementation(UElementusInventor

void UElementusInventoryComponent::DiscardItemIndexes_Implementation(const TArray<int32>& ItemIndexes)
{
if (GetOwnerRole() != ROLE_Authority || ItemIndexes.IsEmpty())
if (GetOwnerRole() != ROLE_Authority || UElementusInventoryFunctions::HasEmptyParam(ItemIndexes))
{
return;
}

for (const uint32& Index : ItemIndexes)
for (const int32& Index : ItemIndexes)
{
if (ElementusItems.IsValidIndex(Index))
{
Expand All @@ -493,7 +491,7 @@ void UElementusInventoryComponent::DiscardItemIndexes_Implementation(const TArra

void UElementusInventoryComponent::DiscardItems_Implementation(const TArray<FElementusItemInfo>& Items)
{
if (GetOwnerRole() != ROLE_Authority || Items.IsEmpty())
if (GetOwnerRole() != ROLE_Authority || UElementusInventoryFunctions::HasEmptyParam(Items))
{
return;
}
Expand All @@ -504,7 +502,7 @@ void UElementusInventoryComponent::DiscardItems_Implementation(const TArray<FEle

void UElementusInventoryComponent::AddItems_Implementation(const TArray<FElementusItemInfo>& Items)
{
if (GetOwnerRole() != ROLE_Authority || Items.IsEmpty())
if (GetOwnerRole() != ROLE_Authority || UElementusInventoryFunctions::HasEmptyParam(Items))
{
return;
}
Expand Down Expand Up @@ -635,7 +633,7 @@ void UElementusInventoryComponent::OnRep_ElementusItems()
{
ElementusItems.RemoveAt(LastValidIndex + 1, ElementusItems.Num() - LastValidIndex - 1, false);
}
else if (LastValidIndex == INDEX_NONE && !ElementusItems.IsEmpty())
else if (LastValidIndex == INDEX_NONE && !UElementusInventoryFunctions::HasEmptyParam(ElementusItems))
{
ElementusItems.Empty();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ElementusInventory/Private/ElementusInventory.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#include "ElementusInventory.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#include "LogElementusInventory.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#include "Management/ElementusInventoryData.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#include "Management/ElementusInventoryFunctions.h"
Expand Down Expand Up @@ -135,7 +135,7 @@ TArray<UElementusItemData*> UElementusInventoryFunctions::LoadElementusItemDatas

const auto PassItemArr_Lambda = [&CheckAssetValidity_Lambda, &Output, FuncName = __func__](TArray<UObject*>& InArr)
{
if (InArr.IsEmpty())
if (UElementusInventoryFunctions::HasEmptyParam(InArr))
{
UE_LOG(LogElementusInventory_Internal, Error, TEXT("%s: Failed to find items with the given parameters"), *FString(FuncName));
}
Expand Down Expand Up @@ -171,7 +171,7 @@ TArray<UElementusItemData*> UElementusInventoryFunctions::LoadElementusItemDatas
PassItemArr_Lambda(LoadedAssets);
}

if (!Output.IsEmpty())
if (!UElementusInventoryFunctions::HasEmptyParam(Output))
{
for (int32 Iterator = 0; Iterator < InIDs.Num(); ++Iterator)
{
Expand Down Expand Up @@ -215,7 +215,7 @@ TArray<FPrimaryAssetId> UElementusInventoryFunctions::GetAllElementusItemIds()

void UElementusInventoryFunctions::TradeElementusItem(TArray<FElementusItemInfo> ItemsToTrade, UElementusInventoryComponent* FromInventory, UElementusInventoryComponent* ToInventory)
{
if (ItemsToTrade.IsEmpty())
if (UElementusInventoryFunctions::HasEmptyParam(ItemsToTrade))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#pragma once

#include <CoreMinimal.h>
#include <GameFramework/Actor.h>
#include <Components/ElementusInventoryComponent.h>
#include "ElementusInventoryPackage.generated.h"

class UElementusInventoryComponent;

UCLASS(Category = "Elementus Inventory | Classes")
class ELEMENTUSINVENTORY_API AElementusInventoryPackage : public AActor
{
Expand All @@ -18,9 +17,9 @@ class ELEMENTUSINVENTORY_API AElementusInventoryPackage : public AActor
public:
explicit AElementusInventoryPackage(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

/* The inventory of this package actor */
UPROPERTY(Replicated, EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory")
TObjectPtr<UElementusInventoryComponent> PackageInventory;
/* The inventory component of this package actor */
UPROPERTY(Replicated, EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory")
UElementusInventoryComponent* PackageInventory;

/* Put a item in this package */
UFUNCTION(BlueprintCallable, Category = "Elementus Inventory")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#pragma once

#include <CoreMinimal.h>
#include <GameplayTagContainer.h>
#include <Components/ActorComponent.h>
#include "Management/ElementusInventoryData.h"
#include "ElementusInventoryComponent.generated.h"

struct FElementusItemInfo;

UENUM(Category = "Elementus Inventory | Enumerations")
enum class EElementusInventoryUpdateOperation : uint8
{
Expand Down Expand Up @@ -91,28 +90,28 @@ class ELEMENTUSINVENTORY_API UElementusInventoryComponent : public UActorCompone
virtual bool CanGiveItem(const FElementusItemInfo InItemInfo) const;

/* Find the first elementus item that matches the specified info */
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
bool FindFirstItemIndexWithInfo(const FElementusItemInfo InItemInfo, int32& OutIndex, const FGameplayTagContainer IgnoreTags = FGameplayTagContainer(), const int32 Offset = 0) const;
UFUNCTION(BlueprintPure, Category = "Elementus Inventory", meta = (AutoCreateRefTerm = "IgnoreTags"))
bool FindFirstItemIndexWithInfo(const FElementusItemInfo InItemInfo, int32& OutIndex, const FGameplayTagContainer& IgnoreTags, const int32 Offset = 0) const;

/* Find the first elementus item that matches the specified tag container */
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
bool FindFirstItemIndexWithTags(const FGameplayTagContainer WithTags, int32& OutIndex, const FGameplayTagContainer IgnoreTags = FGameplayTagContainer(), const int32 Offset = 0) const;
UFUNCTION(BlueprintPure, Category = "Elementus Inventory", meta = (AutoCreateRefTerm = "IgnoreTags"))
bool FindFirstItemIndexWithTags(const FGameplayTagContainer WithTags, int32& OutIndex, const FGameplayTagContainer& IgnoreTags, const int32 Offset = 0) const;

/* Find the first elementus item that matches the specified id */
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
bool FindFirstItemIndexWithId(const FPrimaryElementusItemId InId, int32& OutIndex, const FGameplayTagContainer IgnoreTags = FGameplayTagContainer(), const int32 Offset = 0) const;
UFUNCTION(BlueprintPure, Category = "Elementus Inventory", meta = (AutoCreateRefTerm = "IgnoreTags"))
bool FindFirstItemIndexWithId(const FPrimaryElementusItemId InId, int32& OutIndex, const FGameplayTagContainer& IgnoreTags, const int32 Offset = 0) const;

/* Find the first elementus item that matches the specified info */
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
bool FindAllItemIndexesWithInfo(const FElementusItemInfo InItemInfo, TArray<int32>& OutIndexes, const FGameplayTagContainer IgnoreTags = FGameplayTagContainer()) const;
UFUNCTION(BlueprintPure, Category = "Elementus Inventory", meta = (AutoCreateRefTerm = "IgnoreTags"))
bool FindAllItemIndexesWithInfo(const FElementusItemInfo InItemInfo, TArray<int32>& OutIndexes, const FGameplayTagContainer& IgnoreTags) const;

/* Find the first elementus item that matches the specified tag container */
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
bool FindAllItemIndexesWithTags(const FGameplayTagContainer WithTags, TArray<int32>& OutIndexes, const FGameplayTagContainer IgnoreTags = FGameplayTagContainer()) const;
UFUNCTION(BlueprintPure, Category = "Elementus Inventory", meta = (AutoCreateRefTerm = "IgnoreTags"))
bool FindAllItemIndexesWithTags(const FGameplayTagContainer WithTags, TArray<int32>& OutIndexes, const FGameplayTagContainer& IgnoreTags) const;

/* Find the first elementus item that matches the specified id */
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
bool FindAllItemIndexesWithId(const FPrimaryElementusItemId InId, TArray<int32>& OutIndexes, const FGameplayTagContainer IgnoreTags = FGameplayTagContainer()) const;
UFUNCTION(BlueprintPure, Category = "Elementus Inventory", meta = (AutoCreateRefTerm = "IgnoreTags"))
bool FindAllItemIndexesWithId(const FPrimaryElementusItemId InId, TArray<int32>& OutIndexes, const FGameplayTagContainer& IgnoreTags) const;

/* Check if the inventory stack contains a item that matches the specified info */
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
Expand All @@ -122,11 +121,9 @@ class ELEMENTUSINVENTORY_API UElementusInventoryComponent : public UActorCompone
UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
bool IsInventoryEmpty() const;

#if WITH_EDITORONLY_DATA
/* Print debug informations in the log about this inventory */
UFUNCTION(BlueprintCallable, Category = "Elementus Inventory")
virtual void DebugInventory();
#endif

/* Remove all items from this inventory */
UFUNCTION(NetMulticast, Reliable, BlueprintCallable, Category = "Elementus Inventory")
Expand Down
2 changes: 1 addition & 1 deletion Source/ElementusInventory/Public/ElementusInventory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#pragma once
Expand Down
2 changes: 1 addition & 1 deletion Source/ElementusInventory/Public/LogElementusInventory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#pragma once
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#pragma once
Expand Down

0 comments on commit 572fc77

Please sign in to comment.