Split WingComponentReference into a static helper class and a simple data class
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include "WingUtils.h"
|
||||
#include "WingTypes.h"
|
||||
#include "WingServer.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "Engine/SimpleConstructionScript.h"
|
||||
#include "Engine/SCS_Node.h"
|
||||
@@ -64,15 +64,15 @@ public:
|
||||
if (!UWingTypes::TextToType(Class, PinType, Req, WingOut::Stdout)) return;
|
||||
UClass* ComponentClass = Cast<UClass>(PinType.PinSubCategoryObject.Get());
|
||||
check(ComponentClass);
|
||||
if (!UWingComponentReference::CheckValidComponentClass(ComponentClass, WingOut::Stdout)) return;
|
||||
if (!UWingComponent::CheckValidComponentClass(ComponentClass, WingOut::Stdout)) return;
|
||||
|
||||
// Find the specified parent component
|
||||
TArray<UWingComponentReference*> AllComponents = UWingComponentReference::GetAll(BP);
|
||||
TArray<UWingComponentReference*> AllComponents = UWingComponent::GetAll(BP);
|
||||
UWingComponentReference* ParentComp = WingUtils::FindOneWithExternalID(Parent, AllComponents, TEXT("Component"), WingOut::Stdout);
|
||||
if (!ParentComp) return;
|
||||
|
||||
// Create the SCS node
|
||||
if (!UWingComponentReference::AddComponent(BP, ComponentClass, ParentComp, InternalID, WingOut::Stdout)) return;
|
||||
if (!UWingComponent::AddComponent(BP, ComponentClass, ParentComp, InternalID, WingOut::Stdout)) return;
|
||||
|
||||
WingOut::Stdout.Printf(TEXT("Component Added.\n"));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "WingBasics.h"
|
||||
#include "WingFetcher.h"
|
||||
#include "WingServer.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "ActorComponent_Remove.generated.h"
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
UWingComponentReference* CompRef = F.Walk(Component).Cast<UWingComponentReference>();
|
||||
if (!CompRef) return;
|
||||
|
||||
if (!CompRef->DeleteComponent(WingOut::Stdout)) return;
|
||||
if (!UWingComponent::DeleteComponent(CompRef, WingOut::Stdout)) return;
|
||||
|
||||
WingOut::Stdout.Printf(TEXT("Removed component.\n"));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "WingFetcher.h"
|
||||
#include "WingUtils.h"
|
||||
#include "WingServer.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "Engine/SimpleConstructionScript.h"
|
||||
#include "Engine/SCS_Node.h"
|
||||
@@ -41,11 +41,11 @@ public:
|
||||
|
||||
// Find the new parent among all components (if specified)
|
||||
UBlueprint *BP = CompRef->BP;
|
||||
TArray<UWingComponentReference*> AllComponents = UWingComponentReference::GetAll(BP);
|
||||
TArray<UWingComponentReference*> AllComponents = UWingComponent::GetAll(BP);
|
||||
UWingComponentReference* NewParent = WingUtils::FindOneWithExternalID(Parent, AllComponents, TEXT("Component"), WingOut::Stdout);
|
||||
if (!NewParent) return;
|
||||
|
||||
if (!CompRef->ReparentComponent(NewParent, WingOut::Stdout)) return;
|
||||
if (!UWingComponent::ReparentComponent(CompRef, NewParent, WingOut::Stdout)) return;
|
||||
|
||||
WingOut::Stdout.Printf(TEXT("Reparented component."));
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "Animation/AnimBlueprint.h"
|
||||
#include "Animation/Skeleton.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "AnimationGraph.h"
|
||||
#include "AnimationGraphSchema.h"
|
||||
@@ -71,9 +71,9 @@ public:
|
||||
BlueprintVars.Print(WingOut::StdoutBuffer);
|
||||
|
||||
// Components
|
||||
TArray<UWingComponentReference*> Components = UWingComponentReference::GetAll(BP);
|
||||
TArray<UWingComponentReference*> Components = UWingComponent::GetAll(BP);
|
||||
if (!Components.IsEmpty()) WingOut::Stdout.Print(TEXT("\nComponents:\n"));
|
||||
UWingComponentReference::PrintAll(BP, WingOut::Stdout);
|
||||
UWingComponent::PrintAll(BP, WingOut::Stdout);
|
||||
|
||||
// Widget Tree
|
||||
if (UWidgetBlueprint* WidgetBP = Cast<UWidgetBlueprint>(BP))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "WingServer.h"
|
||||
#include "WingTypes.h"
|
||||
#include "WingUtils.h"
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "Engine/InheritableComponentHandler.h"
|
||||
|
||||
UActorComponent *UWingComponentReference::FindComponentInCDO(UClass *Class, FName Name)
|
||||
UActorComponent *UWingComponent::FindComponentInCDO(UClass *Class, FName Name)
|
||||
{
|
||||
if (!Class) return nullptr;
|
||||
AActor* CDO = Cast<AActor>(Class->GetDefaultObject());
|
||||
@@ -19,7 +19,7 @@ UActorComponent *UWingComponentReference::FindComponentInCDO(UClass *Class, FNam
|
||||
return FindObjectFast<UActorComponent>(CDO, Name);
|
||||
}
|
||||
|
||||
USCS_Node* UWingComponentReference::FindSCSNodeByName(UBlueprint *BP, FName Name)
|
||||
USCS_Node* UWingComponent::FindSCSNodeByName(UBlueprint *BP, FName Name)
|
||||
{
|
||||
for (UBlueprint *WalkBP : WingUtils::GetAncestorBlueprints(BP))
|
||||
{
|
||||
@@ -30,7 +30,7 @@ USCS_Node* UWingComponentReference::FindSCSNodeByName(UBlueprint *BP, FName Name
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UWingComponentReference::FoundComponent UWingComponentReference::FindComponent(UBlueprint *BP, FName Name)
|
||||
UWingComponent::FoundComponent UWingComponent::FindComponent(UBlueprint *BP, FName Name)
|
||||
{
|
||||
UClass* NativeClass = FBlueprintEditorUtils::FindFirstNativeClass(BP->ParentClass);
|
||||
FoundComponent Result;
|
||||
@@ -40,7 +40,7 @@ UWingComponentReference::FoundComponent UWingComponentReference::FindComponent(U
|
||||
return Result;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::CheckExists(UWingComponentReference::FoundComponent FC, WingOut Errors)
|
||||
bool UWingComponent::CheckExists(UWingComponent::FoundComponent FC, WingOut Errors)
|
||||
{
|
||||
if ((FC.SCS == nullptr) && (FC.Native == nullptr))
|
||||
{
|
||||
@@ -50,7 +50,7 @@ bool UWingComponentReference::CheckExists(UWingComponentReference::FoundComponen
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::CheckValidParent(UWingComponentReference::FoundComponent FC, WingOut Errors)
|
||||
bool UWingComponent::CheckValidParent(UWingComponent::FoundComponent FC, WingOut Errors)
|
||||
{
|
||||
if (FC.SCS && FC.Native)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ bool UWingComponentReference::CheckValidParent(UWingComponentReference::FoundCom
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::CheckNoSuchComponent(FoundComponent FC, WingOut Errors)
|
||||
bool UWingComponent::CheckNoSuchComponent(FoundComponent FC, WingOut Errors)
|
||||
{
|
||||
if (FC.SCS || FC.Native)
|
||||
{
|
||||
@@ -84,7 +84,7 @@ bool UWingComponentReference::CheckNoSuchComponent(FoundComponent FC, WingOut Er
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::CheckNotNative(FoundComponent FC, const TCHAR *Action, WingOut Errors)
|
||||
bool UWingComponent::CheckNotNative(FoundComponent FC, const TCHAR *Action, WingOut Errors)
|
||||
{
|
||||
if (FC.Native != nullptr)
|
||||
{
|
||||
@@ -95,7 +95,7 @@ bool UWingComponentReference::CheckNotNative(FoundComponent FC, const TCHAR *Act
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::CheckOwnedByBlueprint(FoundComponent FC, UBlueprint *BP, WingOut Errors)
|
||||
bool UWingComponent::CheckOwnedByBlueprint(FoundComponent FC, UBlueprint *BP, WingOut Errors)
|
||||
{
|
||||
if ((FC.SCS == nullptr) || (FC.SCS->GetSCS() != BP->SimpleConstructionScript))
|
||||
{
|
||||
@@ -106,7 +106,7 @@ bool UWingComponentReference::CheckOwnedByBlueprint(FoundComponent FC, UBlueprin
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::CheckValidComponentClass(UClass *Class, WingOut Errors)
|
||||
bool UWingComponent::CheckValidComponentClass(UClass *Class, WingOut Errors)
|
||||
{
|
||||
if (!Class->IsChildOf(UActorComponent::StaticClass()))
|
||||
{
|
||||
@@ -118,7 +118,7 @@ bool UWingComponentReference::CheckValidComponentClass(UClass *Class, WingOut Er
|
||||
}
|
||||
|
||||
|
||||
void UWingComponentReference::AddChildNode(UBlueprint *BP, USCS_Node *NewNode, FoundComponent Parent)
|
||||
void UWingComponent::AddChildNode(UBlueprint *BP, USCS_Node *NewNode, FoundComponent Parent)
|
||||
{
|
||||
if (Parent.SCS)
|
||||
{
|
||||
@@ -139,7 +139,7 @@ void UWingComponentReference::AddChildNode(UBlueprint *BP, USCS_Node *NewNode, F
|
||||
}
|
||||
}
|
||||
|
||||
bool UWingComponentReference::AddComponent(UBlueprint *BP, UClass *Class, UWingComponentReference *Parent, FName Name, WingOut Errors)
|
||||
bool UWingComponent::AddComponent(UBlueprint *BP, UClass *Class, UWingComponentReference *Parent, FName Name, WingOut Errors)
|
||||
{
|
||||
TSet<FName> Names;
|
||||
FBlueprintEditorUtils::GetClassVariableList(BP, Names);
|
||||
@@ -167,14 +167,14 @@ bool UWingComponentReference::AddComponent(UBlueprint *BP, UClass *Class, UWingC
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::ReparentComponent(UWingComponentReference *Parent, WingOut Errors)
|
||||
bool UWingComponent::ReparentComponent(UWingComponentReference *Ref, UWingComponentReference *Parent, WingOut Errors)
|
||||
{
|
||||
FoundComponent ParentComponent = FindComponent(BP, Parent->VariableName);
|
||||
FoundComponent ParentComponent = FindComponent(Ref->BP, Parent->VariableName);
|
||||
if (!CheckValidParent(ParentComponent, Errors)) return false;
|
||||
FoundComponent ThisComponent = FindComponent(BP, VariableName);
|
||||
FoundComponent ThisComponent = FindComponent(Ref->BP, Ref->VariableName);
|
||||
if (!CheckExists(ThisComponent, Errors)) return false;
|
||||
if (!CheckNotNative(ThisComponent, TEXT("reparent"), Errors)) return false;
|
||||
if (!CheckOwnedByBlueprint(ThisComponent, BP, Errors)) return false;
|
||||
if (!CheckOwnedByBlueprint(ThisComponent, Ref->BP, Errors)) return false;
|
||||
|
||||
if (ParentComponent.SCS && ParentComponent.SCS->IsChildOf(ThisComponent.SCS))
|
||||
{
|
||||
@@ -182,22 +182,22 @@ bool UWingComponentReference::ReparentComponent(UWingComponentReference *Parent,
|
||||
return false;
|
||||
}
|
||||
|
||||
BP->SimpleConstructionScript->RemoveNode(ThisComponent.SCS);
|
||||
AddChildNode(BP, ThisComponent.SCS, ParentComponent);
|
||||
Ref->BP->SimpleConstructionScript->RemoveNode(ThisComponent.SCS);
|
||||
AddChildNode(Ref->BP, ThisComponent.SCS, ParentComponent);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UWingComponentReference::DeleteComponent(WingOut Errors)
|
||||
bool UWingComponent::DeleteComponent(UWingComponentReference *Ref, WingOut Errors)
|
||||
{
|
||||
FoundComponent ThisComponent = FindComponent(BP, VariableName);
|
||||
FoundComponent ThisComponent = FindComponent(Ref->BP, Ref->VariableName);
|
||||
if (!CheckExists(ThisComponent, Errors)) return false;
|
||||
if (!CheckNotNative(ThisComponent, TEXT("delete"), Errors)) return false;
|
||||
if (!CheckOwnedByBlueprint(ThisComponent, BP, Errors)) return false;
|
||||
BP->SimpleConstructionScript->RemoveNodeAndPromoteChildren(ThisComponent.SCS);
|
||||
if (!CheckOwnedByBlueprint(ThisComponent, Ref->BP, Errors)) return false;
|
||||
Ref->BP->SimpleConstructionScript->RemoveNodeAndPromoteChildren(ThisComponent.SCS);
|
||||
return true;
|
||||
}
|
||||
|
||||
TMap<FName, FName> UWingComponentReference::CalculateParentNames(USimpleConstructionScript *Script)
|
||||
TMap<FName, FName> UWingComponent::CalculateParentNames(USimpleConstructionScript *Script)
|
||||
{
|
||||
TMap<FName, FName> ParentNames;
|
||||
for (USCS_Node* Node : Script->GetAllNodes())
|
||||
@@ -214,14 +214,14 @@ TMap<FName, FName> UWingComponentReference::CalculateParentNames(USimpleConstruc
|
||||
return ParentNames;
|
||||
}
|
||||
|
||||
UActorComponent* UWingComponentReference::GetImmutableTemplate() const
|
||||
UActorComponent* UWingComponent::GetImmutableTemplate(const UWingComponentReference *Ref)
|
||||
{
|
||||
FoundComponent FC = FindComponent(BP, VariableName);
|
||||
FoundComponent FC = FindComponent(Ref->BP, Ref->VariableName);
|
||||
if (FC.Native) return FC.Native;
|
||||
if (FC.SCS == nullptr) return nullptr;
|
||||
FComponentKey Key(FC.SCS);
|
||||
|
||||
for (UBlueprint *WalkBP : WingUtils::GetAncestorBlueprints(BP, false))
|
||||
for (UBlueprint *WalkBP : WingUtils::GetAncestorBlueprints(Ref->BP, false))
|
||||
{
|
||||
if (FC.SCS->GetSCS()->GetBlueprint() == WalkBP) return FC.SCS->ComponentTemplate;
|
||||
UInheritableComponentHandler* ICH = WalkBP->GetInheritableComponentHandler(/*bCreateIfNecessary=*/ false);
|
||||
@@ -232,22 +232,22 @@ UActorComponent* UWingComponentReference::GetImmutableTemplate() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UActorComponent* UWingComponentReference::GetMutableTemplate() const
|
||||
UActorComponent* UWingComponent::GetMutableTemplate(const UWingComponentReference *Ref)
|
||||
{
|
||||
FoundComponent FC = FindComponent(BP, VariableName);
|
||||
FoundComponent FC = FindComponent(Ref->BP, Ref->VariableName);
|
||||
if (FC.Native) return FC.Native;
|
||||
if (!FC.SCS) return nullptr;
|
||||
if (FC.SCS->GetSCS()->GetBlueprint() == BP) return FC.SCS->ComponentTemplate;
|
||||
if (FC.SCS->GetSCS()->GetBlueprint() == Ref->BP) return FC.SCS->ComponentTemplate;
|
||||
|
||||
FComponentKey Key(FC.SCS);
|
||||
UInheritableComponentHandler* ICH = BP->GetInheritableComponentHandler(/*bCreateIfNecessary=*/ true);
|
||||
UInheritableComponentHandler* ICH = Ref->BP->GetInheritableComponentHandler(/*bCreateIfNecessary=*/ true);
|
||||
if (!ICH) return nullptr;
|
||||
UActorComponent* Override = ICH->GetOverridenComponentTemplate(Key);
|
||||
if (!Override) Override = ICH->CreateOverridenComponentTemplate(Key);
|
||||
return Override;
|
||||
}
|
||||
|
||||
TArray<UWingComponentReference*> UWingComponentReference::GetAll(UBlueprint* BP)
|
||||
TArray<UWingComponentReference*> UWingComponent::GetAll(UBlueprint* BP)
|
||||
{
|
||||
TArray<UWingComponentReference*> Result;
|
||||
if (!BP) return Result;
|
||||
@@ -288,7 +288,7 @@ TArray<UWingComponentReference*> UWingComponentReference::GetAll(UBlueprint* BP)
|
||||
return Result;
|
||||
}
|
||||
|
||||
void UWingComponentReference::PrintComponentInfo(const FString& TypeName, const FString& VarName, const FString& ParentName, bool Inherited, WingOut Out)
|
||||
void UWingComponent::PrintComponentInfo(const FString& TypeName, const FString& VarName, const FString& ParentName, bool Inherited, WingOut Out)
|
||||
{
|
||||
Out.Printf(TEXT(" %s %s"), *TypeName, *VarName);
|
||||
if (!ParentName.IsEmpty())
|
||||
@@ -298,7 +298,7 @@ void UWingComponentReference::PrintComponentInfo(const FString& TypeName, const
|
||||
Out.Print(TEXT("\n"));
|
||||
}
|
||||
|
||||
void UWingComponentReference::PrintAll(UBlueprint* BP, WingOut Out)
|
||||
void UWingComponent::PrintAll(UBlueprint* BP, WingOut Out)
|
||||
{
|
||||
if (!BP) return;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "WingServer.h"
|
||||
#include "WingBasics.h"
|
||||
#include "WingUtils.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "WingReferences.h"
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "EdGraph/EdGraph.h"
|
||||
@@ -286,7 +286,7 @@ WingFetcher& WingFetcher::Component(const FString& Value)
|
||||
return SetError();
|
||||
}
|
||||
|
||||
TArray<UWingComponentReference*> AllComponents = UWingComponentReference::GetAll(BP);
|
||||
TArray<UWingComponentReference*> AllComponents = UWingComponent::GetAll(BP);
|
||||
UWingComponentReference* Found = WingUtils::FindOneWithExternalID(Value, AllComponents, TEXT("component"), Errors);
|
||||
if (!Found)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "WingProperty.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "WingUtils.h"
|
||||
#include "WingBasics.h"
|
||||
#include "WingReferences.h"
|
||||
@@ -455,7 +455,7 @@ TArray<FWingProperty> FWingProperty::GetDetails(UObject* Obj, bool Mutable)
|
||||
// Component references: get the proper template.
|
||||
if (UWingComponentReference* Ref = ::Cast<UWingComponentReference>(Obj))
|
||||
{
|
||||
Obj = Mutable ? Ref->GetMutableTemplate() : Ref->GetImmutableTemplate();
|
||||
Obj = Mutable ? UWingComponent::GetMutableTemplate(Ref) : UWingComponent::GetImmutableTemplate(Ref);
|
||||
if (!Obj)
|
||||
{
|
||||
WingOut::Stdout.Printf(TEXT("ERROR: Component '%s' has no template\n"), *Ref->VariableName.ToString());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "WingUtils.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "WingProperty.h"
|
||||
#include "WingTypes.h"
|
||||
#include "WingServer.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "WingBasics.h"
|
||||
#include "WingActorComponent.generated.h"
|
||||
#include "WingComponent.generated.h"
|
||||
|
||||
class UBlueprint;
|
||||
class USCS_Node;
|
||||
@@ -24,12 +24,16 @@ public:
|
||||
|
||||
// The component name.
|
||||
FName VariableName;
|
||||
};
|
||||
|
||||
UActorComponent* GetImmutableTemplate() const;
|
||||
UActorComponent* GetMutableTemplate() const;
|
||||
struct UWingComponent
|
||||
{
|
||||
public:
|
||||
static UActorComponent* GetImmutableTemplate(const UWingComponentReference *Ref);
|
||||
static UActorComponent* GetMutableTemplate(const UWingComponentReference *Ref);
|
||||
|
||||
bool ReparentComponent(UWingComponentReference *Parent, WingOut Errors);
|
||||
bool DeleteComponent(WingOut Errors);
|
||||
static bool ReparentComponent(UWingComponentReference *Ref, UWingComponentReference *Parent, WingOut Errors);
|
||||
static bool DeleteComponent(UWingComponentReference *Ref, WingOut Errors);
|
||||
static bool AddComponent(UBlueprint *BP, UClass *Class,
|
||||
UWingComponentReference *Parent, FName Name, WingOut Errors);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "K2Node_EditablePinBase.h"
|
||||
#include "Components/Widget.h"
|
||||
#include "WingActorComponent.h"
|
||||
#include "WingComponent.h"
|
||||
#include "WingVariables.h"
|
||||
#include "WingBasics.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user