Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
v1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lucoiso authored Feb 20, 2023
2 parents 56ecd9d + 572fc77 commit 84ae12b
Show file tree
Hide file tree
Showing 32 changed files with 598 additions and 227 deletions.
4 changes: 2 additions & 2 deletions ElementusInventory.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 2,
"VersionName": "1.1.4",
"Version": 3,
"VersionName": "1.1.5",
"FriendlyName": "Elementus Inventory",
"Description": "Plugin that provides a Data-Driven Inventory & Items system based on FPrimaryAssetIds and the Asset Manager.",
"Category": "Game Features",
Expand Down
6 changes: 4 additions & 2 deletions 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 All @@ -19,8 +19,10 @@ public ElementusInventory(ReadOnlyTargetRules Target) : base(Target)
PrivateDependencyModuleNames.AddRange(new[]
{
"Engine",
"NetCore",
"CoreUObject",
"GameplayTags"
"GameplayTags",
"DeveloperSettings"
});
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
// Author: Lucas Vilas-Boas
// Year: 2022
// Year: 2023
// Repo: https://github.com/lucoiso/UEElementusInventory

#include "Actors/ElementusInventoryPackage.h"
#include <Components/ElementusInventoryComponent.h>
#include "Components/ElementusInventoryComponent.h"
#include "Management/ElementusInventorySettings.h"
#include "Management/ElementusInventoryFunctions.h"
#include "Management/ElementusInventoryData.h"
#include "LogElementusInventory.h"
#include <Net/UnrealNetwork.h>

AElementusInventoryPackage::AElementusInventoryPackage(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer), bDestroyWhenInventoryIsEmpty(false)
#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

AElementusInventoryPackage::AElementusInventoryPackage(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
bNetStartup = false;
bNetLoadOnClient = false;
Expand All @@ -22,6 +31,11 @@ AElementusInventoryPackage::AElementusInventoryPackage(const FObjectInitializer&

PackageInventory = CreateDefaultSubobject<UElementusInventoryComponent>(TEXT("PackageInventory"));
PackageInventory->SetIsReplicated(true);

if (const UElementusInventorySettings* const Settings = UElementusInventorySettings::Get())
{
bDestroyWhenInventoryIsEmpty = Settings->bDestroyWhenInventoryIsEmpty;
}
}

void AElementusInventoryPackage::BeginPlay()
Expand All @@ -30,7 +44,7 @@ void AElementusInventoryPackage::BeginPlay()

SetDestroyOnEmpty(bDestroyWhenInventoryIsEmpty);

if (bDestroyWhenInventoryIsEmpty && PackageInventory->GetItemsArray().IsEmpty())
if (bDestroyWhenInventoryIsEmpty && UElementusInventoryFunctions::HasEmptyParam(PackageInventory->GetItemsArray()))
{
Destroy();
}
Expand All @@ -40,17 +54,22 @@ void AElementusInventoryPackage::GetLifetimeReplicatedProps(TArray<FLifetimeProp
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);

DOREPLIFETIME(AElementusInventoryPackage, PackageInventory);
FDoRepLifetimeParams SharedParams;
SharedParams.bIsPushBased = true;

DOREPLIFETIME_WITH_PARAMS_FAST(AElementusInventoryPackage, PackageInventory, SharedParams);
}

void AElementusInventoryPackage::PutItemIntoPackage(const TArray<FElementusItemInfo> ItemInfo, UElementusInventoryComponent* FromInventory)
{
UElementusInventoryFunctions::TradeElementusItem(ItemInfo, FromInventory, PackageInventory);
MARK_PROPERTY_DIRTY_FROM_NAME(AElementusInventoryPackage, PackageInventory, this);
}

void AElementusInventoryPackage::GetItemFromPackage(const TArray<FElementusItemInfo> ItemInfo, UElementusInventoryComponent* ToInventory)
{
UElementusInventoryFunctions::TradeElementusItem(ItemInfo, PackageInventory, ToInventory);
MARK_PROPERTY_DIRTY_FROM_NAME(AElementusInventoryPackage, PackageInventory, this);
}

void AElementusInventoryPackage::SetDestroyOnEmpty(const bool bDestroy)
Expand All @@ -61,10 +80,9 @@ void AElementusInventoryPackage::SetDestroyOnEmpty(const bool bDestroy)
}

bDestroyWhenInventoryIsEmpty = bDestroy;
FElementusInventoryEmpty& Delegate = PackageInventory->OnInventoryEmpty;
FElementusInventoryEmpty Delegate = PackageInventory->OnInventoryEmpty;

if (const bool bIsAlreadyBound = Delegate.IsAlreadyBound(this, &AElementusInventoryPackage::BeginPackageDestruction);
bDestroy && !bIsAlreadyBound)
if (const bool bIsAlreadyBound = Delegate.IsAlreadyBound(this, &AElementusInventoryPackage::BeginPackageDestruction); bDestroy && !bIsAlreadyBound)
{
Delegate.AddDynamic(this, &AElementusInventoryPackage::BeginPackageDestruction);
}
Expand All @@ -81,7 +99,7 @@ bool AElementusInventoryPackage::GetDestroyOnEmpty() const

void AElementusInventoryPackage::BeginPackageDestruction_Implementation()
{
// Check if this option is still active
// Check if this option is still active before the destruction
if (bDestroyWhenInventoryIsEmpty)
{
Destroy();
Expand Down
Loading

0 comments on commit 84ae12b

Please sign in to comment.