From 835937ace57a43bc0c301435688a924f762bd0c4 Mon Sep 17 00:00:00 2001 From: John-Philip Johansson Date: Mon, 11 Jul 2022 13:45:27 -0300 Subject: [PATCH 1/2] Support multiple path filters Paths that match with `StartWith` requires us to add a new path for every plugin with content. The Modular Game Features plugin type in UE5 promotes a project structure with multiple plugins, and it quickly becomes cumbersome (and easy to forget) to configure new paths. By also supporting `EndsWith` and `Contains` as path match conditions it's now easy to set up conditions that works across both game content and plugin content directories. --- .../Private/BUIValidatorSettings.cpp | 4 ++- .../Public/BUIValidatorSettings.h | 28 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Source/BUIValidator/Private/BUIValidatorSettings.cpp b/Source/BUIValidator/Private/BUIValidatorSettings.cpp index b2d5b3c..b4399e7 100644 --- a/Source/BUIValidator/Private/BUIValidatorSettings.cpp +++ b/Source/BUIValidator/Private/BUIValidatorSettings.cpp @@ -33,7 +33,9 @@ bool FBUIValidatorGroup::ShouldGroupValidateAsset( UObject* InAsset ) const bool bMatchAnyPath = MatchConditions.Paths.Num() == 0; for ( const auto& Path : MatchConditions.Paths ) { - if ( AssetPathInUnreal.StartsWith( Path.Path ) ) + if ( Path.Type == EBUIPathType::StartsWith && AssetPathInUnreal.StartsWith( Path.Path ) || + Path.Type == EBUIPathType::EndsWith && AssetPathInUnreal.EndsWith( Path.Path ) || + Path.Type == EBUIPathType::Contains && AssetPathInUnreal.Contains( Path.Path ) ) { bMatchAnyPath = true; break; diff --git a/Source/BUIValidator/Public/BUIValidatorSettings.h b/Source/BUIValidator/Public/BUIValidatorSettings.h index fa3c94c..65d5130 100644 --- a/Source/BUIValidator/Public/BUIValidatorSettings.h +++ b/Source/BUIValidator/Public/BUIValidatorSettings.h @@ -9,6 +9,28 @@ enum class EBUITextureSizeRequirement PowerOfTwo, }; +UENUM() +enum class EBUIPathType +{ + Contains, + EndsWith, + StartsWith, +}; + +USTRUCT( meta = ( ToolTip = " Match any part of an asset directory." ) ) +struct FBUIPathFilter +{ + GENERATED_BODY() + + // Which part of the directory path to search in. `EndsWith` and `Contains` are useful for content plugins. `StartsWith` is the default for backwards-compatibility. + UPROPERTY( EditAnywhere, meta = ( DisplayName = "Path" ) ) + EBUIPathType Type = EBUIPathType::StartsWith; + + // Match UTexture2D assets under any of these directories + UPROPERTY( EditAnywhere, meta = ( DisplayName = "Path segment" ) ) + FString Path; +}; + USTRUCT( meta = ( ToolTip = "All parts of a rule must pass in order for the rule to be applied" ) ) struct FBUIMatchConditions { @@ -23,8 +45,10 @@ struct FBUIMatchConditions TArray Prefixes = { "T_UI_" }; // Match UTexture2D assets under any of these directories - UPROPERTY( EditAnywhere, meta = ( ContentDir, TitleProperty = "Path" ) ) - TArray Paths; + UPROPERTY( EditAnywhere, meta = ( TitleProperty = "Path" ) ) + TArray Paths = { + { EBUIPathType::EndsWith, "/UI/" } + }; }; USTRUCT() From 330100b8f9d9c9e504ee32192d1c49473957717a Mon Sep 17 00:00:00 2001 From: John-Philip Johansson Date: Mon, 11 Jul 2022 14:33:50 -0300 Subject: [PATCH 2/2] `Contains` path `/UI/` should be default `EndsWith` doesn't make much sense as most will have a directory structure inside `/UI/`. --- Source/BUIValidator/Public/BUIValidatorSettings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/BUIValidator/Public/BUIValidatorSettings.h b/Source/BUIValidator/Public/BUIValidatorSettings.h index 65d5130..b37e391 100644 --- a/Source/BUIValidator/Public/BUIValidatorSettings.h +++ b/Source/BUIValidator/Public/BUIValidatorSettings.h @@ -47,7 +47,7 @@ struct FBUIMatchConditions // Match UTexture2D assets under any of these directories UPROPERTY( EditAnywhere, meta = ( TitleProperty = "Path" ) ) TArray Paths = { - { EBUIPathType::EndsWith, "/UI/" } + { EBUIPathType::Contains, "/UI/" } }; };