From 6f51dd6d360467226a3e83f3b0296b3fafd7beb0 Mon Sep 17 00:00:00 2001 From: muit Date: Sun, 27 Nov 2022 22:07:33 +0100 Subject: [PATCH 1/5] Added Collection asset --- .../AssetTypeAction_FactionCollection.cpp | 38 ++++++++++++ .../Asset/FactionCollectionFactory.cpp | 58 +++++++++++++++++++ Source/Editor/Private/FactionsEditor.cpp | 4 +- .../Asset/AssetTypeAction_FactionCollection.h | 18 ++++++ .../Public/Asset/FactionCollectionFactory.h | 21 +++++++ Source/Factions/Public/FactionCollection.h | 38 ++++++++++++ 6 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp create mode 100644 Source/Editor/Private/Asset/FactionCollectionFactory.cpp create mode 100644 Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h create mode 100644 Source/Editor/Public/Asset/FactionCollectionFactory.h create mode 100644 Source/Factions/Public/FactionCollection.h diff --git a/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp b/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp new file mode 100644 index 0000000..5b2c65d --- /dev/null +++ b/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp @@ -0,0 +1,38 @@ +// Copyright 2015-2020 Piperift. All Rights Reserved. + +#include "Asset/AssetTypeAction_FactionCollection.h" +#include "FactionCollection.h" +#include "FactionsModule.h" + +#include "AssetToolsModule.h" +#include "ContentBrowserModule.h" + +#define LOCTEXT_NAMESPACE "AssetTypeActions" + + +////////////////////////////////////////////////////////////////////////// +// FAssetTypeAction_FactionCollection + +FText FAssetTypeAction_FactionCollection::GetName() const +{ + return LOCTEXT("FAssetTypeAction_FactionAssetName", "Faction Descriptor"); +} + +FColor FAssetTypeAction_FactionCollection::GetTypeColor() const +{ + return FColor(170, 66, 244); +} + +UClass* FAssetTypeAction_FactionCollection::GetSupportedClass() const +{ + return UFactionCollection::StaticClass(); +} + +uint32 FAssetTypeAction_FactionCollection::GetCategories() +{ + return EAssetTypeCategories::Misc; +} + +////////////////////////////////////////////////////////////////////////// + +#undef LOCTEXT_NAMESPACE diff --git a/Source/Editor/Private/Asset/FactionCollectionFactory.cpp b/Source/Editor/Private/Asset/FactionCollectionFactory.cpp new file mode 100644 index 0000000..f00b63e --- /dev/null +++ b/Source/Editor/Private/Asset/FactionCollectionFactory.cpp @@ -0,0 +1,58 @@ +// Copyright 2015-2020 Piperift. All Rights Reserved. + +#include "Asset/FactionCollectionFactory.h" + +#include +#include +#include "Kismet2/SClassPickerDialog.h" +#include "FactionCollection.h" + +#define LOCTEXT_NAMESPACE "FactionCollection" + + +class FAssetClassParentFilter : public IClassViewerFilter +{ +public: + /** All children of these classes will be included unless filtered out by another setting. */ + TSet< const UClass* > AllowedChildrenOfClasses; + + /** Disallowed class flags. */ + EClassFlags DisallowedClassFlags; + + virtual bool IsClassAllowed(const FClassViewerInitializationOptions& InInitOptions, const UClass* InClass, TSharedRef< FClassViewerFilterFuncs > InFilterFuncs) override + { + return !InClass->HasAnyClassFlags(DisallowedClassFlags) + && InFilterFuncs->IfInChildOfClassesSet(AllowedChildrenOfClasses, InClass) != EFilterReturn::Failed; + } + + virtual bool IsUnloadedClassAllowed(const FClassViewerInitializationOptions& InInitOptions, const TSharedRef< const IUnloadedBlueprintData > InUnloadedClassData, TSharedRef< FClassViewerFilterFuncs > InFilterFuncs) override + { + return !InUnloadedClassData->HasAnyClassFlags(DisallowedClassFlags) + && InFilterFuncs->IfInChildOfClassesSet(AllowedChildrenOfClasses, InUnloadedClassData) != EFilterReturn::Failed; + } +}; + + +UFactionCollectionFactory::UFactionCollectionFactory() + : Super() +{ + SupportedClass = UFactionCollection::StaticClass(); + + //bText = true; + bCreateNew = true; + bEditorImport = true; + bEditAfterNew = true; +} + +UObject* UFactionCollectionFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) +{ + if(Class != nullptr) + { + // if we have no asset class, use the passed-in class instead + check(Class == UFactionCollection::StaticClass() || Class->IsChildOf(UFactionCollection::StaticClass())); + return NewObject(InParent, Class, Name, Flags); + } + return nullptr; +} + +#undef LOCTEXT_NAMESPACE diff --git a/Source/Editor/Private/FactionsEditor.cpp b/Source/Editor/Private/FactionsEditor.cpp index 0c98d27..4e49e4e 100644 --- a/Source/Editor/Private/FactionsEditor.cpp +++ b/Source/Editor/Private/FactionsEditor.cpp @@ -11,7 +11,7 @@ #include -//#include "Asset/AssetTypeAction_FactionCollection.h" +#include "Asset/AssetTypeAction_FactionCollection.h" DEFINE_LOG_CATEGORY(LogFactionsEditor) @@ -28,7 +28,7 @@ void FFactionsEditorModule::StartupModule() PrepareAutoGeneratedDefaultEvents(); IAssetTools& AssetTools = FModuleManager::LoadModuleChecked("AssetTools").Get(); - //RegisterAssetTypeAction(AssetTools, MakeShared()); + RegisterAssetTypeAction(AssetTools, MakeShared()); } void FFactionsEditorModule::ShutdownModule() diff --git a/Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h b/Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h new file mode 100644 index 0000000..04d5fb4 --- /dev/null +++ b/Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h @@ -0,0 +1,18 @@ +// Copyright 2015-2020 Piperift. All Rights Reserved. + +#pragma once + +#include "AssetTypeActions_Base.h" + +class FACTIONSEDITOR_API FAssetTypeAction_FactionCollection : public FAssetTypeActions_Base +{ +public: + // IAssetTypeActions interface + virtual FText GetName() const override; + virtual FColor GetTypeColor() const override; + virtual UClass* GetSupportedClass() const override; + virtual bool HasActions(const TArray& InObjects) const override { return false; } + virtual uint32 GetCategories() override; + // End of IAssetTypeActions interface + +}; diff --git a/Source/Editor/Public/Asset/FactionCollectionFactory.h b/Source/Editor/Public/Asset/FactionCollectionFactory.h new file mode 100644 index 0000000..e3a074e --- /dev/null +++ b/Source/Editor/Public/Asset/FactionCollectionFactory.h @@ -0,0 +1,21 @@ +// Copyright 2015-2020 Piperift. All Rights Reserved. + +#pragma once + +#include "Factories/Factory.h" +#include "FactionCollection.h" +#include "FactionCollectionFactory.generated.h" + + +UCLASS() +class UFactionCollectionFactory : public UFactory +{ + GENERATED_BODY() + + + UFactionCollectionFactory(); + + // UFactory interface + virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override; + // End of UFactory interface +}; diff --git a/Source/Factions/Public/FactionCollection.h b/Source/Factions/Public/FactionCollection.h new file mode 100644 index 0000000..af0036e --- /dev/null +++ b/Source/Factions/Public/FactionCollection.h @@ -0,0 +1,38 @@ +// Copyright 2015-2020 Piperift. All Rights Reserved. + +#pragma once + +#include "FactionTable.h" +#include "RelationTable.h" + +#include + + +#include "FactionCollection.generated.h" + + +#define LOCTEXT_NAMESPACE "FactionCollection" + + +/** + * Struct containing information about a faction. Static use. + */ +UCLASS(Blueprintable) +class FACTIONS_API UFactionCollection : public UPrimaryDataAsset +{ + GENERATED_BODY() + +protected: + + // Preffix to be added to faction ids where final ids become: {Scope}.{Id} + UPROPERTY(EditAnywhere, Category = Collection) + FString Scope; + + UPROPERTY(EditAnywhere, Category = Collection) + FFactionTable Factions; + + UPROPERTY(EditAnywhere, Category = Collection) + FRelationTable Relations; +}; + +#undef LOCTEXT_NAMESPACE From 7d15c94cbe5dbb5bbcfba1eaa4b2305806a714b1 Mon Sep 17 00:00:00 2001 From: muit Date: Sun, 27 Nov 2022 22:18:11 +0100 Subject: [PATCH 2/5] Remvoed direct access to faction table --- Source/Factions/Private/FactionsSubsystem.cpp | 2 +- Source/Factions/Public/FactionsSubsystem.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Factions/Private/FactionsSubsystem.cpp b/Source/Factions/Private/FactionsSubsystem.cpp index 7cee846..fc89269 100644 --- a/Source/Factions/Private/FactionsSubsystem.cpp +++ b/Source/Factions/Private/FactionsSubsystem.cpp @@ -217,7 +217,7 @@ bool UFactionsSubsystem::GetActorsByFaction(const FFaction Faction, TArray Date: Sun, 27 Nov 2022 22:21:22 +0100 Subject: [PATCH 3/5] Removed unused code --- .../Asset/FactionCollectionFactory.cpp | 25 ------------------- .../Asset/AssetTypeAction_FactionCollection.h | 1 - .../Public/Asset/FactionCollectionFactory.h | 1 - Source/Factions/Public/FactionCollection.h | 2 -- 4 files changed, 29 deletions(-) diff --git a/Source/Editor/Private/Asset/FactionCollectionFactory.cpp b/Source/Editor/Private/Asset/FactionCollectionFactory.cpp index f00b63e..f565f8f 100644 --- a/Source/Editor/Private/Asset/FactionCollectionFactory.cpp +++ b/Source/Editor/Private/Asset/FactionCollectionFactory.cpp @@ -10,37 +10,12 @@ #define LOCTEXT_NAMESPACE "FactionCollection" -class FAssetClassParentFilter : public IClassViewerFilter -{ -public: - /** All children of these classes will be included unless filtered out by another setting. */ - TSet< const UClass* > AllowedChildrenOfClasses; - - /** Disallowed class flags. */ - EClassFlags DisallowedClassFlags; - - virtual bool IsClassAllowed(const FClassViewerInitializationOptions& InInitOptions, const UClass* InClass, TSharedRef< FClassViewerFilterFuncs > InFilterFuncs) override - { - return !InClass->HasAnyClassFlags(DisallowedClassFlags) - && InFilterFuncs->IfInChildOfClassesSet(AllowedChildrenOfClasses, InClass) != EFilterReturn::Failed; - } - - virtual bool IsUnloadedClassAllowed(const FClassViewerInitializationOptions& InInitOptions, const TSharedRef< const IUnloadedBlueprintData > InUnloadedClassData, TSharedRef< FClassViewerFilterFuncs > InFilterFuncs) override - { - return !InUnloadedClassData->HasAnyClassFlags(DisallowedClassFlags) - && InFilterFuncs->IfInChildOfClassesSet(AllowedChildrenOfClasses, InUnloadedClassData) != EFilterReturn::Failed; - } -}; - - UFactionCollectionFactory::UFactionCollectionFactory() : Super() { SupportedClass = UFactionCollection::StaticClass(); - //bText = true; bCreateNew = true; - bEditorImport = true; bEditAfterNew = true; } diff --git a/Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h b/Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h index 04d5fb4..073911b 100644 --- a/Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h +++ b/Source/Editor/Public/Asset/AssetTypeAction_FactionCollection.h @@ -14,5 +14,4 @@ class FACTIONSEDITOR_API FAssetTypeAction_FactionCollection : public FAssetTypeA virtual bool HasActions(const TArray& InObjects) const override { return false; } virtual uint32 GetCategories() override; // End of IAssetTypeActions interface - }; diff --git a/Source/Editor/Public/Asset/FactionCollectionFactory.h b/Source/Editor/Public/Asset/FactionCollectionFactory.h index e3a074e..d283fea 100644 --- a/Source/Editor/Public/Asset/FactionCollectionFactory.h +++ b/Source/Editor/Public/Asset/FactionCollectionFactory.h @@ -12,7 +12,6 @@ class UFactionCollectionFactory : public UFactory { GENERATED_BODY() - UFactionCollectionFactory(); // UFactory interface diff --git a/Source/Factions/Public/FactionCollection.h b/Source/Factions/Public/FactionCollection.h index af0036e..2f7832e 100644 --- a/Source/Factions/Public/FactionCollection.h +++ b/Source/Factions/Public/FactionCollection.h @@ -7,13 +7,11 @@ #include - #include "FactionCollection.generated.h" #define LOCTEXT_NAMESPACE "FactionCollection" - /** * Struct containing information about a faction. Static use. */ From b966f5fdb9a00c3a61a4126ae08eea1ac3a72eb5 Mon Sep 17 00:00:00 2001 From: muit Date: Tue, 6 Dec 2022 23:10:11 +0100 Subject: [PATCH 4/5] Can add collections, added FindDescriptor --- .../AssetTypeAction_FactionCollection.cpp | 2 +- Source/Factions/Private/FactionsSubsystem.cpp | 85 ++++++++++++++++--- Source/Factions/Public/FactionCollection.h | 6 +- Source/Factions/Public/FactionRelation.h | 10 +++ Source/Factions/Public/FactionsSubsystem.h | 43 ++++++++-- 5 files changed, 123 insertions(+), 23 deletions(-) diff --git a/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp b/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp index 5b2c65d..78ef485 100644 --- a/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp +++ b/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp @@ -15,7 +15,7 @@ FText FAssetTypeAction_FactionCollection::GetName() const { - return LOCTEXT("FAssetTypeAction_FactionAssetName", "Faction Descriptor"); + return LOCTEXT("FAssetTypeAction_FactionCollectionName", "Faction Collection"); } FColor FAssetTypeAction_FactionCollection::GetTypeColor() const diff --git a/Source/Factions/Private/FactionsSubsystem.cpp b/Source/Factions/Private/FactionsSubsystem.cpp index fc89269..4b8e25d 100644 --- a/Source/Factions/Private/FactionsSubsystem.cpp +++ b/Source/Factions/Private/FactionsSubsystem.cpp @@ -30,9 +30,26 @@ void UFactionsSubsystem::PostInitProperties() } } -const FFactionDescriptor* UFactionsSubsystem::GetDescriptor(FFaction Faction) const +const FFactionDescriptor* UFactionsSubsystem::FindDescriptor( + FFaction Faction, UFactionCollection** OutCollection) const { - return GetFactions().GetDescriptor(Faction); + const FFactionDescriptor* Descriptor = GetFactions().GetDescriptor(Faction); + UFactionCollection* Collection = nullptr; + + for (auto It = Collections.begin(); !Descriptor && It != Collections.end(); ++It) + { + Collection = *It; + if (Collection) + { + Descriptor = Collection->Factions.GetDescriptor(Faction); + } + } + + if (Descriptor && OutCollection) + { + *OutCollection = Collection; + } + return nullptr; } TEnumAsByte UFactionsSubsystem::GetAttitude( @@ -86,8 +103,7 @@ FGenericTeamId UFactionsSubsystem::ToTeamId(FFaction Faction) const FString UFactionsSubsystem::GetDisplayName(const FFaction Faction) const { - const auto* Descriptor = GetDescriptor(Faction); - if (Descriptor) + if (const auto* Descriptor = FindDescriptor(Faction)) { const bool bUseId = Descriptor->bIdAsDisplayName || (bUseIdsIfDisplayNamesAreEmpty && Descriptor->DisplayName.IsEmpty()); @@ -147,6 +163,45 @@ bool UFactionsSubsystem::RemoveRelation(const FFactionRelation& Relation) return false; } +bool UFactionsSubsystem::AddCollection(UFactionCollection* Collection) +{ + if (Collections.Contains(Collection)) + { + UE_LOG(LogFactions, Warning, TEXT("Collection ('%s') has already been added before."), + *Collection->GetName()); + return false; + } + + Collections.Add(Collection); + + bool bFactionExisted = false; + for (const auto& Descriptor : Collection->Factions.List) + { + AddBakedFaction(Descriptor.Key, Descriptor.Value, &bFactionExisted); + if (bFactionExisted) + { + UE_LOG(LogFactions, Warning, + TEXT("Added a duplicated faction from a collection. Relation: (%s)"), + *Descriptor.Key.ToString()); + } + } + + + bool bRepeated = false; + Relations.List.Reserve(Relations.List.Num() + Collection->Relations.List.Num()); + for (const auto& Relation : Collection->Relations.List) + { + Relations.List.Add(Relation, &bRepeated); + if (bRepeated) + { + UE_LOG(LogFactions, Warning, TEXT("Added a duplicated relation from a collection. Relation: (%s)"), *Relation.ToString(Collection)); + } + } + Relations.List.Append(Collection->Relations.List); + + return true; +} + int32 UFactionsSubsystem::ClearFactions() { const int32 Count = Factions.Num(); @@ -235,18 +290,17 @@ bool UFactionsSubsystem::SetDescriptor(const FFaction Faction, const FFactionDes void UFactionsSubsystem::GetAllFactions(TArray& OutFactions) const { - const auto& AllFactions = GetFactions().List; - - OutFactions.Reserve(OutFactions.Num() + AllFactions.Num()); - for (const auto& Entry : AllFactions) + OutFactions.Reserve(OutFactions.Num() + BakedBehaviors.Num()); + for (const auto& Behavior : BakedBehaviors) { - OutFactions.Add({Entry.Key}); + OutFactions.Add({Behavior.Id}); } } -bool UFactionsSubsystem::BPGetDescriptor(const FFaction Faction, FFactionDescriptor& Descriptor) const +bool UFactionsSubsystem::BPFindDescriptor( + const FFaction Faction, FFactionDescriptor& Descriptor, UFactionCollection*& Collection) const { - if (auto* Found = GetFactions().GetDescriptor(Faction)) + if (auto* Found = FindDescriptor(Faction, &Collection)) { Descriptor = *Found; return true; @@ -304,7 +358,7 @@ void UFactionsSubsystem::BakeFactions() }); } -void UFactionsSubsystem::AddBakedFaction(FName Id, const FFactionDescriptor& Descriptor) +void UFactionsSubsystem::AddBakedFaction(FName Id, const FFactionDescriptor& Descriptor, bool* bWasAlreadyAdded) { // Insert sorted const int32 Index = Algo::LowerBoundBy(BakedBehaviors, Id, [](const auto& Behavior) { @@ -317,6 +371,7 @@ void UFactionsSubsystem::AddBakedFaction(FName Id, const FFactionDescriptor& Des Descriptor.SelfAttitude, Descriptor.ExternalAttitude }; + bool bReplaced = false; if (BakedBehaviors.IsValidIndex(Index)) { // Since we returned lower bound we already know Id <= Index key. So if Id is not < Index key, they must be equal @@ -324,6 +379,7 @@ void UFactionsSubsystem::AddBakedFaction(FName Id, const FFactionDescriptor& Des { // Found, replace BakedBehaviors[Index] = Behavior; + bReplaced = true; } else { @@ -334,6 +390,11 @@ void UFactionsSubsystem::AddBakedFaction(FName Id, const FFactionDescriptor& Des { BakedBehaviors.Add(Behavior); } + + if (bWasAlreadyAdded) + { + *bWasAlreadyAdded = bReplaced; + } } void UFactionsSubsystem::RemoveBakedFaction(FFaction Faction) diff --git a/Source/Factions/Public/FactionCollection.h b/Source/Factions/Public/FactionCollection.h index 2f7832e..8fa2d39 100644 --- a/Source/Factions/Public/FactionCollection.h +++ b/Source/Factions/Public/FactionCollection.h @@ -20,11 +20,7 @@ class FACTIONS_API UFactionCollection : public UPrimaryDataAsset { GENERATED_BODY() -protected: - - // Preffix to be added to faction ids where final ids become: {Scope}.{Id} - UPROPERTY(EditAnywhere, Category = Collection) - FString Scope; +public: UPROPERTY(EditAnywhere, Category = Collection) FFactionTable Factions; diff --git a/Source/Factions/Public/FactionRelation.h b/Source/Factions/Public/FactionRelation.h index 19af5b7..602524c 100644 --- a/Source/Factions/Public/FactionRelation.h +++ b/Source/Factions/Public/FactionRelation.h @@ -68,6 +68,16 @@ struct FACTIONS_API FFactionRelation { return GetTypeHash(InRelation.Source) ^ GetTypeHash(InRelation.Target); } + + FString ToString(const UObject* Owner) const; }; +inline FString FFactionRelation::ToString(const UObject* Owner) const +{ + FString Value{}; + StaticStruct()->ExportText(Value, this, nullptr, const_cast(Owner), + (PPF_ExportsNotFullyQualified | PPF_Copy | PPF_Delimited | PPF_IncludeTransient), nullptr); + return Value; +} + #undef LOCTEXT_NAMESPACE diff --git a/Source/Factions/Public/FactionsSubsystem.h b/Source/Factions/Public/FactionsSubsystem.h index 8018cf4..fec50a5 100644 --- a/Source/Factions/Public/FactionsSubsystem.h +++ b/Source/Factions/Public/FactionsSubsystem.h @@ -5,6 +5,7 @@ #include "FactionAgentInterface.h" #include "FactionTable.h" #include "RelationTable.h" +#include "FactionCollection.h" #include #include @@ -69,6 +70,10 @@ class FACTIONS_API UFactionsSubsystem : public UWorldSubsystem UPROPERTY(Transient) TArray BakedBehaviors; + /** Currently added collections */ + UPROPERTY(Transient) + TArray Collections; + static bool hasSetTeamIdAttitudeSolver; @@ -89,7 +94,6 @@ class FACTIONS_API UFactionsSubsystem : public UWorldSubsystem static UFactionsSubsystem* Get(const UObject* ContextObject); - const FFactionDescriptor* GetDescriptor(FFaction Faction) const; /** C++ ONLY API */ @@ -100,8 +104,9 @@ class FACTIONS_API UFactionsSubsystem : public UWorldSubsystem bool IsFriendly(const UObject* Source, const UObject* Target) const; bool IsNeutral(const UObject* Source, const UObject* Target) const; - int32 GetFactionIndex(FFaction Faction) const; + const FFactionDescriptor* FindDescriptor(FFaction Faction, UFactionCollection** OutCollection = nullptr) const; + int32 GetFactionIndex(FFaction Faction) const; FFaction FromTeamId(FGenericTeamId TeamId) const; FGenericTeamId ToTeamId(FFaction Faction) const; @@ -205,6 +210,14 @@ class FACTIONS_API UFactionsSubsystem : public UWorldSubsystem UFUNCTION(BlueprintCallable, Category = Factions) bool RemoveRelation(const FFactionRelation& Relation); + /** + * Add a faction collection (along with its factions and relations) + * @param Collection to be added + * @return true if the collection was registered, false if the two factions were the same or invalid. + */ + UFUNCTION(BlueprintCallable, Category = Factions) + bool AddCollection(UFactionCollection* Collection); + /** * Removes all factions * @return number of removed factions @@ -244,8 +257,9 @@ class FACTIONS_API UFactionsSubsystem : public UWorldSubsystem * @param Descriptor of the faction, if found * @return true if the faction was valid and information was found */ - UFUNCTION(BlueprintPure, Category = Factions, meta = (DisplayName = "Get Descriptor")) - bool BPGetDescriptor(const FFaction Faction, FFactionDescriptor& Descriptor) const; + UFUNCTION(BlueprintPure, Category = Factions, meta = (DisplayName = "Find Descriptor")) + bool BPFindDescriptor( + const FFaction Faction, FFactionDescriptor& Descriptor, UFactionCollection*& Collection) const; /** Return the faction of an actor. None if the actor doesn't implement FactionAgentInterface */ UFUNCTION(BlueprintPure, Category = Factions, meta = (DefaultToSelf = "Source", DisplayName = "Get Faction")) @@ -283,8 +297,27 @@ class FACTIONS_API UFactionsSubsystem : public UWorldSubsystem #endif void BakeFactions(); - void AddBakedFaction(FName Id, const FFactionDescriptor& Descriptor); + void AddBakedFaction( + FName Id, const FFactionDescriptor& Descriptor, bool* bWasAlreadyAdded = nullptr); void RemoveBakedFaction(FFaction Faction); + + + /** DEPRECATIONS */ +public: + UE_DEPRECATED(5.1, "This function is deprecated. Use FindDescriptor instead") + const FFactionDescriptor* GetDescriptor(FFaction Faction) const + { + return FindDescriptor(Faction); + } + + UFUNCTION(BlueprintPure, Category = Factions, + meta = (DisplayName = "Get Descriptor", DeprecatedFunction, + DeprecationMessage = "This function is deprecated. Use FindDescriptor instead")) + bool BPGetDescriptor(const FFaction Faction, FFactionDescriptor& Descriptor) const + { + UFactionCollection* Collection = nullptr; + return BPFindDescriptor(Faction, Descriptor, Collection); + } }; From 2bf703c7841d0149495e6a18b616aacd86b79835 Mon Sep 17 00:00:00 2001 From: muit Date: Mon, 12 Jun 2023 23:31:44 +0200 Subject: [PATCH 5/5] Collections partial progress --- .../Asset/AssetTypeAction_FactionCollection.cpp | 2 +- .../Private/Asset/FactionCollectionFactory.cpp | 2 +- Source/Factions/Private/FactionsSubsystem.cpp | 14 ++++++++++++++ Source/Factions/Public/FactionCollection.h | 11 +++++++++++ Source/Factions/Public/FactionsSubsystem.h | 16 ++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp b/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp index 5b2c65d..993a06b 100644 --- a/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp +++ b/Source/Editor/Private/Asset/AssetTypeAction_FactionCollection.cpp @@ -15,7 +15,7 @@ FText FAssetTypeAction_FactionCollection::GetName() const { - return LOCTEXT("FAssetTypeAction_FactionAssetName", "Faction Descriptor"); + return LOCTEXT("FAssetTypeAction_FactionAssetName", "Faction Collection"); } FColor FAssetTypeAction_FactionCollection::GetTypeColor() const diff --git a/Source/Editor/Private/Asset/FactionCollectionFactory.cpp b/Source/Editor/Private/Asset/FactionCollectionFactory.cpp index f565f8f..b061c54 100644 --- a/Source/Editor/Private/Asset/FactionCollectionFactory.cpp +++ b/Source/Editor/Private/Asset/FactionCollectionFactory.cpp @@ -7,8 +7,8 @@ #include "Kismet2/SClassPickerDialog.h" #include "FactionCollection.h" -#define LOCTEXT_NAMESPACE "FactionCollection" +#define LOCTEXT_NAMESPACE "FactionCollection" UFactionCollectionFactory::UFactionCollectionFactory() : Super() diff --git a/Source/Factions/Private/FactionsSubsystem.cpp b/Source/Factions/Private/FactionsSubsystem.cpp index fc89269..fd1aed6 100644 --- a/Source/Factions/Private/FactionsSubsystem.cpp +++ b/Source/Factions/Private/FactionsSubsystem.cpp @@ -147,6 +147,20 @@ bool UFactionsSubsystem::RemoveRelation(const FFactionRelation& Relation) return false; } +bool UFactionsSubsystem::AddCollection(const UFactionCollection* collection) +{ + return false; +} + +void UFactionsSubsystem::RemoveCollection(const UFactionCollection* collection) +{ +} + +bool UFactionsSubsystem::HasCollection(TSoftObjectPtr collection) const +{ + return false; +} + int32 UFactionsSubsystem::ClearFactions() { const int32 Count = Factions.Num(); diff --git a/Source/Factions/Public/FactionCollection.h b/Source/Factions/Public/FactionCollection.h index 2f7832e..702e698 100644 --- a/Source/Factions/Public/FactionCollection.h +++ b/Source/Factions/Public/FactionCollection.h @@ -31,6 +31,17 @@ class FACTIONS_API UFactionCollection : public UPrimaryDataAsset UPROPERTY(EditAnywhere, Category = Collection) FRelationTable Relations; + + + const FFactionTable& GetFactions() const + { + return Factions; + } + + const FRelationTable& GetRelations() const + { + return Relations; + } }; #undef LOCTEXT_NAMESPACE diff --git a/Source/Factions/Public/FactionsSubsystem.h b/Source/Factions/Public/FactionsSubsystem.h index 8018cf4..47ee056 100644 --- a/Source/Factions/Public/FactionsSubsystem.h +++ b/Source/Factions/Public/FactionsSubsystem.h @@ -5,6 +5,7 @@ #include "FactionAgentInterface.h" #include "FactionTable.h" #include "RelationTable.h" +#include "FactionCollection.h" #include #include @@ -205,6 +206,21 @@ class FACTIONS_API UFactionsSubsystem : public UWorldSubsystem UFUNCTION(BlueprintCallable, Category = Factions) bool RemoveRelation(const FFactionRelation& Relation); + /** + * Add a collection with all its factions and relations + * @return true if the collection was added successfully + */ + UFUNCTION(BlueprintCallable, Category = Factions) + bool AddCollection(const UFactionCollection* collection); + + /** Remove a collection with all its factions and relations */ + UFUNCTION(BlueprintCallable, Category = Factions) + void RemoveCollection(const UFactionCollection* collection); + + /** @return true if collection has been added */ + UFUNCTION(BlueprintPure, Category = Factions) + bool HasCollection(TSoftObjectPtr collection) const; + /** * Removes all factions * @return number of removed factions