Skip to content

Commit

Permalink
[#9] [#53] Implement FindChildTag Utility Method
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyPaddock committed Feb 7, 2024
1 parent 73cecb2 commit beba60f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Source/OpenPF2Core/Private/Libraries/PF2TagLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// OpenPF2 for UE Game Logic, Copyright 2023, Guy Elsmore-Paddock. All Rights Reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
// distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "Libraries/PF2TagLibrary.h"

FGameplayTag UPF2TagLibrary::FindChildTag(const FGameplayTagContainer& AllTags,
const FGameplayTag& ParentTag,
bool& bMatchFound)
{
FGameplayTag Result;
const FGameplayTagContainer AllChildren = AllTags.Filter(FGameplayTagContainer(ParentTag));

if (AllChildren.IsEmpty())
{
bMatchFound = false;
}
else
{
Result = AllChildren.First();
bMatchFound = true;

if (AllChildren.Num() > 1)
{
UE_LOG(
LogPf2Core,
Warning,
TEXT("More than one child tag ('%s') matched parent tag ('%s')."),
*(AllChildren.ToStringSimple()),
*(ParentTag.ToString())
);
}
}

return Result;
}
51 changes: 51 additions & 0 deletions Source/OpenPF2Core/Public/Libraries/PF2TagLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// OpenPF2 for UE Game Logic, Copyright 2023, Guy Elsmore-Paddock. All Rights Reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
// distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

// ReSharper disable CppUEBlueprintCallableFunctionUnused
#pragma once

#include <GameplayTagContainer.h>

#include <Kismet/BlueprintFunctionLibrary.h>

#include "PF2TagLibrary.generated.h"

// =====================================================================================================================
// Forward Declarations (to minimize header dependencies)
// =====================================================================================================================

// =====================================================================================================================
// Normal Declarations
// =====================================================================================================================
/**
* Function library for working with gameplay abilities in OpenPF2.
*/
UCLASS()
class OPENPF2CORE_API UPF2TagLibrary final : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

public:
/**
* Locates the tag within the specified tag container that is a child of another tag.
*
* If there are multiple tags in the container that are children or grandchildren of the given tag, only the first
* one gets returned.
*
* @param [in] AllTags
* The tags to search.
* @param [in] ParentTag
* The parent (or grandparent) tag of the desired tag.
* @param [out] bMatchFound
* Whether a tag was found that is a child of the specified tag.
*
* @return
* Either the matching tag; or a gameplay tag that is not valid if there is no tag that matches.
*/
UFUNCTION(BlueprintCallable, BlueprintPure, meta=(AutoCreateRefTerm="ParentTag"), Category="OpenPF2|Gameplay Tags")
static FGameplayTag FindChildTag(const FGameplayTagContainer& AllTags,
const FGameplayTag& ParentTag,
bool& bMatchFound);
};

0 comments on commit beba60f

Please sign in to comment.