Program Listing for File ZagalaSpecFeatureSettings.h#

↰ Return to documentation for file (ZagalaSpec/Public/Settings/ZagalaSpecFeatureSettings.h)

// Copyright (c) 2026, Zagala Game Solutions. All rights reserved.

#pragma once

#include "CoreMinimal.h"
#include "Engine/DeveloperSettings.h"
#include "Core/Regex/ZagalaSpecGlobalGroupData.h"
#include "Core/Regex/ZagalaSpecRegexRecord.h"
#include "GameplayTagContainer.h"
#include "Templates/SubclassOf.h"
#include "UObject/SoftObjectPath.h"
#include "ZagalaSpecFeatureSettings.generated.h"

DECLARE_LOG_CATEGORY_EXTERN(LogZagalaSpecFeatureSettings, Log, All);


USTRUCT()
struct ZAGALASPEC_API FZagalaSpecCachedRegistryEntry
{
    GENERATED_BODY()


    UPROPERTY(VisibleAnywhere, EditFixedSize, meta=(ForceInlineRow), Category = "Regex Registry")
    TMap<FString, FSoftObjectPath> RegisteredEntries;
};

USTRUCT()
struct ZAGALASPEC_API FZagalaSpecRegexIdentityData
{
    GENERATED_BODY()


    UPROPERTY(VisibleAnywhere, Category = "Identity")
    FString Pattern;

    UPROPERTY(VisibleAnywhere, Category = "Identity")
    FSoftObjectPath Entry;
};

UCLASS(Config = "ZagalaSpecFeatureSettings", AutoCollapseCategories = "Config", AutoExpandCategories = "Regex Finder", meta = (DisplayName = "ZagalaSpec Common"))
class ZAGALASPEC_API UZagalaSpecFeatureSettings : public UDeveloperSettings
{
    GENERATED_BODY()

public:
    UZagalaSpecFeatureSettings(const FObjectInitializer& ObjectInitializer);
    static UZagalaSpecFeatureSettings& GetFeatureSettingsMutable();
    static const UZagalaSpecFeatureSettings& GetFeatureSettings();

    static void CacheRegistry(const UObject* Registry);

    const TMap<TObjectPtr<UObject>, FZagalaSpecCachedRegistryEntry>& GetCachedRegistries() const;
    static void ClearCachedRegistries();

    TArray<FZagalaSpecRegexRecord> GetRegexRecordsFor(const UClass* RegistryClass) const;

    const TArray<FZagalaSpecRegexRecord>& GetRegexRecords() const;

    static const FZagalaSpecGlobalGroupData* FindGlobalGroupClass(const FString& Key);

    void RebuildGlobalGroupDataIndexMap();

    const TArray<FZagalaSpecGlobalGroupData>& GetGlobalCaptureGroupClasses() const;

    TArray<FZagalaSpecGlobalGroupData>& GetGlobalCaptureGroupClassesMutable();

    float GetDebounceDelaySeconds() const;

    TArray<FString> GetNamesOfScenarios();

    TArray<FString> GetNamesOfScenariosFiltered();

    FGameplayTagContainer GetScenarioFilterTags(const FGameplayTag& ScenarioTag) const;

    void SetScenarioFilterTags(const FGameplayTag& ScenarioTag, const FGameplayTagContainer& FilterTags);

    TArray<TSubclassOf<UObject>>& GetScenarioFilterClassesMutable();

    void PruneScenarioFilterTags();
    TObjectPtr<UObject> GetScenario(const FString& Identifier) const;
    TObjectPtr<UObject> GetScenario(const FGameplayTag& Identifier) const;
    TObjectPtr<UObject> GetFeatureForScenario(const FGameplayTag& ScenarioTag) const;
    TObjectPtr<UObject> GetFeatureForScenario(const FString& Identifier) const;
    TObjectPtr<UObject> GetFeatureForScenario(TObjectPtr<UObject> Scenario) const;

    virtual void PostInitProperties() override;
    virtual void BeginDestroy() override;

#if WITH_EDITOR
    void UpdateScenariosFor(const TObjectPtr<UObject> Feature);

    void OnAssetRemoved(const FAssetData& AssetData);

    void OnAssetRenamed(const FAssetData& AssetData, const FString& OldObjectPath);

    bool AddRegexRecord(const FZagalaSpecRegexRecord& Record);

    bool RemoveRegexRecord(const FSoftClassPath& Registry, const FString& Pattern);

    int32 RemoveRegexRecordsForEntry(const FSoftClassPath& Registry, const FSoftObjectPath& Entry);

    void CleanDanglingRegexRecords();

    void CleanDanglingFeatures();

    void CleanDanglingScenarios();


    void RemoveInvalidFeature(FSoftObjectPath SoftFeature);

    virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;

    void FillBestMatchesForSearch();

    void TryFillExactMatchForSearch();
#endif

public:
    void BeginConfigWriteBatch();

    void EndConfigWriteBatch();

    static UClass* GetDefaultStepClass();

    static UClass* GetDefaultScenarioClass();

    static UClass* GetDefaultFeatureClass();

    static UClass* GetDefaultExecutionContextClass();

    static UClass* GetDefaultCaptureGroupConverterClass();

protected:

    UPROPERTY(Config, EditAnywhere, meta = (DisplayAfter = "AvailablePatterns"), Category = "Capture Group Classes")
    TArray<FZagalaSpecGlobalGroupData> GlobalCaptureGroupClasses;

private:

#if WITH_EDITOR
    FDelegateHandle AssetRemovedHandle;
    FDelegateHandle AssetRenamedHandle;
#endif

    UPROPERTY(Config, EditAnywhere, Category = "Config")
    bool bSaveConfigToPluginFolder;

    UPROPERTY(Config, EditAnywhere, meta = (MustImplement = "/Script/ZagalaSpec.ZagalaSpecConfigStep"), Category = "Config")
    TSubclassOf<UObject> DefaultStepClass;

    UPROPERTY(Config, EditAnywhere, meta = (MustImplement = "/Script/ZagalaSpec.ZagalaSpecExecutionContext"), Category = "Config")
    TSubclassOf<UObject> DefaultExecutionContextClass;

    UPROPERTY(Config, EditAnywhere, meta = (MustImplement = "/Script/ZagalaSpec.ZagalaSpecScenarioInterface"), Category = "Config")
    TSubclassOf<UObject> DefaultScenarioClass;

    UPROPERTY(Config, EditAnywhere, meta = (MustImplement = "/Script/ZagalaSpec.ZagalaSpecFeature"), Category = "Config")
    TSubclassOf<UObject> DefaultFeatureClass;

    UPROPERTY(Config, EditAnywhere, meta = (MustImplement = "/Script/ZagalaSpec.ZagalaSpecCaptureGroupConverter"), Category = "Config")
    TSubclassOf<UObject> DefaultCaptureGroupConverterClass;

    UPROPERTY(Config, EditAnywhere, Category = "Debounce")
    float DebounceDelaySeconds = 0.5f;

    UPROPERTY(Config, VisibleAnywhere, EditFixedSize, meta = (DisplayName = "Scenarios", ToolTip = "List of all scenarios from all features.", ForceInlineRow), Category = "Config")
    TMap<FSoftObjectPath, FGameplayTagContainer> FeaturesMap;

    UPROPERTY(Config)
    TMap<FGameplayTag, FSoftObjectPath> ScenariosMap;

    UPROPERTY(Config, EditAnywhere, meta = (MustImplement = "/Script/ZagalaSpec.ZagalaSpecScenarioFilter"), Category = "Scenario Filters")
    TArray<TSubclassOf<UObject>> ScenarioFilterClasses;

    UPROPERTY(Config, VisibleAnywhere, EditFixedSize, AdvancedDisplay, meta = (ForceInlineRow, Categories = "ZagalaSpec.ScenarioFilter"), Category = "Scenario Filters")
    TMap<FGameplayTag, FGameplayTagContainer> ScenarioFilterTagsMap;

    UPROPERTY(Transient, VisibleAnywhere, EditFixedSize, meta=(ForceInlineRow, DisplayAfter="FeaturesMap"), Category = "Regex Registries")
    TMap<TObjectPtr<UObject>, FZagalaSpecCachedRegistryEntry> CachedRegistries;

    UPROPERTY(Config, VisibleAnywhere, EditFixedSize, meta=(DisplayAfter="CachedRegistries"), Category = "Regex Registries")
    TArray<FZagalaSpecRegexRecord> RegexRecords;

    UPROPERTY(EditAnywhere, Transient, meta = (DisplayAfter="CachedRegistries"), Category = "Regex Finder")
    FString RegexText;

    UPROPERTY(VisibleAnywhere, Transient, EditFixedSize, meta = (DisplayAfter="RegexText"), Category = "Regex Finder")
    TArray<FZagalaSpecRegexIdentityData> AvailablePatterns;

    UPROPERTY(Transient)
    TMap<FString, int32> GlobalGroupDataIndexMap;

    void CustomTryUpdateDefaultConfigFile();

    int32 ConfigWriteBatchDepth = 0;

    bool bConfigWritePending = false;

    FString CustomGetDefaultConfigFilePath() const;
};

struct ZAGALASPEC_API FZagalaSpecConfigWriteBatch
{
    explicit FZagalaSpecConfigWriteBatch(UZagalaSpecFeatureSettings& InSettings);
    ~FZagalaSpecConfigWriteBatch();

    FZagalaSpecConfigWriteBatch(const FZagalaSpecConfigWriteBatch&) = delete;
    FZagalaSpecConfigWriteBatch& operator=(const FZagalaSpecConfigWriteBatch&) = delete;

private:
    TWeakObjectPtr<UZagalaSpecFeatureSettings> Settings;
};