Various null checks, const correctness, remove unused headers

This commit is contained in:
Arnaud Jamin
2023-12-17 01:02:05 -05:00
parent a90881555b
commit 85a903a341
61 changed files with 346 additions and 369 deletions
@@ -2,7 +2,6 @@
#include "AbilitySystemComponent.h"
#include "CogAbilityDataAsset.h"
#include "CogImguiHelper.h"
#include "GameplayEffect.h"
//--------------------------------------------------------------------------------------------------------------------------
@@ -27,6 +26,11 @@ FVector4f UCogAbilityConfig_Alignment::GetAttributeColor(const UAbilitySystemCom
//--------------------------------------------------------------------------------------------------------------------------
FVector4f UCogAbilityConfig_Alignment::GetEffectColor(const UCogAbilityDataAsset* Asset, const UGameplayEffect& Effect) const
{
if (Asset == nullptr)
{
return NeutralColor;
}
const FGameplayTagContainer& Tags = Effect.InheritableGameplayEffectTags.CombinedTags;
if (Tags.HasTag(Asset->NegativeEffectTag))
@@ -1,8 +1,5 @@
#include "CogAbilityHelper.h"
#include "CogAbilityDataAsset.h"
#include "CogImguiHelper.h"
#include "GameplayEffect.h"
#include "GameplayTagContainer.h"
#include "imgui.h"
@@ -236,12 +236,17 @@ void ACogAbilityReplicator::Server_ResetAllTweaks_Implementation()
//--------------------------------------------------------------------------------------------------------------------------
void ACogAbilityReplicator::OnAnyActorSpawned(AActor* Actor)
{
if (AbilityAsset == nullptr)
{
return;
}
if (AbilityAsset->ActorRootClass != nullptr && Actor->GetClass()->IsChildOf(AbilityAsset->ActorRootClass) == false)
{
return;
}
int32 TweakCategoryIndex = FindTweakCategoryFromActor(Actor);
const int32 TweakCategoryIndex = FindTweakCategoryFromActor(Actor);
if (TweakCategoryIndex == INDEX_NONE)
{
return;
@@ -6,10 +6,8 @@
#include "CogAbilityHelper.h"
#include "CogAbilityReplicator.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h"
#include "imgui.h"
#include "imgui_internal.h"
//--------------------------------------------------------------------------------------------------------------------------
void FCogAbilityWindow_Abilities::Initialize()
@@ -103,12 +101,14 @@ void FCogAbilityWindow_Abilities::RenderContent()
AActor* Selection = GetSelection();
if (Selection == nullptr)
{
ImGui::TextDisabled("Invalid selection");
return;
}
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(Selection, true);
if (AbilitySystemComponent == nullptr)
{
ImGui::TextDisabled("Selection has no ability system component");
return;
}
@@ -6,11 +6,8 @@
#include "CogAbilityDataAsset.h"
#include "CogAbilityHelper.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h"
#include "AttributeSet.h"
#include "EngineUtils.h"
#include "GameFramework/Character.h"
//--------------------------------------------------------------------------------------------------------------------------
void FCogAbilityWindow_Attributes::Initialize()
@@ -52,6 +49,7 @@ void FCogAbilityWindow_Attributes::RenderContent()
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true);
if (AbilitySystemComponent == nullptr)
{
ImGui::TextDisabled("Selection has no ability system component");
return;
}
@@ -1,13 +1,10 @@
#include "CogAbilityWindow_Cheats.h"
#include "AbilitySystemGlobals.h"
#include "CogAbilityConfig_Alignment.h"
#include "CogAbilityDataAsset.h"
#include "CogAbilityReplicator.h"
#include "CogCommonAllegianceActorInterface.h"
#include "CogDebugDraw.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h"
#include "EngineUtils.h"
#include "GameFramework/Character.h"
@@ -129,20 +126,20 @@ void FCogAbilityWindow_Cheats::RenderContent()
if (Config == nullptr)
{
ImGui::Text("Invalid Config");
ImGui::TextDisabled("Invalid Config");
return;
}
AActor* SelectedActor = GetSelection();
if (SelectedActor == nullptr)
{
ImGui::Text("Invalid Selection");
ImGui::TextDisabled("Invalid Selection");
return;
}
if (Asset == nullptr)
{
ImGui::Text("Invalid Asset");
ImGui::TextDisabled("Invalid Asset");
return;
}
@@ -7,10 +7,7 @@
#include "CogAbilityDataAsset.h"
#include "CogAbilityHelper.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h"
#include "EngineUtils.h"
#include "GameFramework/Character.h"
//--------------------------------------------------------------------------------------------------------------------------
void FCogAbilityWindow_Effects::Initialize()
@@ -87,9 +84,10 @@ void FCogAbilityWindow_Effects::RenderContent()
//--------------------------------------------------------------------------------------------------------------------------
void FCogAbilityWindow_Effects::RenderEffectsTable()
{
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true);
const UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true);
if (AbilitySystemComponent == nullptr)
{
ImGui::TextDisabled("Selection has no ability system component");
return;
}
@@ -113,7 +111,7 @@ void FCogAbilityWindow_Effects::RenderEffectsTable()
static int SelectedIndex = -1;
int Index = 0;
FGameplayEffectQuery Query;
const FGameplayEffectQuery Query;
TArray<FActiveGameplayEffectHandle> Effects = AbilitySystemComponent->GetActiveEffects(Query);
if (Config->SortByName || Config->SortByAlignment)
@@ -138,7 +136,7 @@ void FCogAbilityWindow_Effects::RenderEffectsTable()
}
bool AlignmentOrder = false;
if (Config->SortByAlignment)
if (Config->SortByAlignment && Asset != nullptr)
{
const FGameplayTagContainer& Tags1 = Effect1->InheritableGameplayEffectTags.CombinedTags;
const FGameplayTagContainer& Tags2 = Effect2->InheritableGameplayEffectTags.CombinedTags;
@@ -267,7 +265,7 @@ void FCogAbilityWindow_Effects::RenderEffectInfo(const UAbilitySystemComponent&
{
if (ImGui::BeginTable("Effect", 2, ImGuiTableFlags_Borders))
{
const ImVec4 TextColor(1.0f, 1.0f, 1.0f, 0.5f);
constexpr ImVec4 TextColor(1.0f, 1.0f, 1.0f, 0.5f);
ImGui::TableSetupColumn("Property");
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch);
@@ -407,7 +405,7 @@ void FCogAbilityWindow_Effects::RenderRemainingTime(const UAbilitySystemComponen
if (Duration >= 0)
{
UWorld* World = AbilitySystemComponent.GetWorld();
const UWorld* World = AbilitySystemComponent.GetWorld();
const float RemainingTime = StartTime + Duration - World->GetTimeSeconds();
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, IM_COL32(100, 100, 100, 255));
@@ -473,13 +471,13 @@ void FCogAbilityWindow_Effects::CloseEffect(const FActiveGameplayEffectHandle& H
//--------------------------------------------------------------------------------------------------------------------------
void FCogAbilityWindow_Effects::RenderOpenEffects()
{
AActor* Selection = GetSelection();
const AActor* Selection = GetSelection();
if (Selection == nullptr)
{
return;
}
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(Selection, true);
const UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(Selection, true);
if (AbilitySystemComponent == nullptr)
{
return;
@@ -487,7 +485,7 @@ void FCogAbilityWindow_Effects::RenderOpenEffects()
for (int i = OpenedEffects.Num() - 1; i >= 0; --i)
{
FActiveGameplayEffectHandle Handle = OpenedEffects[i];
const FActiveGameplayEffectHandle Handle = OpenedEffects[i];
const FActiveGameplayEffect* ActiveEffectPtr = AbilitySystemComponent->GetActiveGameplayEffect(Handle);
if (ActiveEffectPtr == nullptr)
@@ -4,7 +4,6 @@
#include "AbilitySystemGlobals.h"
#include "CogAbilityDataAsset.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h"
#include "imgui_internal.h"
@@ -33,12 +32,20 @@ void FCogAbilityWindow_Pools::RenderContent()
if (Asset == nullptr)
{
ImGui::TextDisabled("Invalid Asset");
return;
}
UAbilitySystemComponent* AbilitySystem = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true);
const UAbilitySystemComponent* AbilitySystem = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true);
if (AbilitySystem == nullptr)
{
ImGui::TextDisabled("No ability system found on selection");
return;
}
if (Asset->Pools.Num() == 0)
{
ImGui::TextDisabled("No pool have been defined");
return;
}
@@ -35,9 +35,10 @@ void FCogAbilityWindow_Tags::RenderContent()
RenderMenu();
UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true);
const UAbilitySystemComponent* AbilitySystemComponent = UAbilitySystemGlobals::GetAbilitySystemComponentFromActor(GetSelection(), true);
if (AbilitySystemComponent == nullptr)
{
ImGui::TextDisabled("Selection has no ability system component");
return;
}
@@ -1,10 +1,8 @@
#include "CogAbilityWindow_Tweaks.h"
#include "AbilitySystemComponent.h"
#include "CogAbilityDataAsset.h"
#include "CogAbilityReplicator.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h"
//--------------------------------------------------------------------------------------------------------------------------
@@ -35,12 +33,14 @@ void FCogAbilityWindow_Tweaks::RenderContent()
if (Asset == nullptr)
{
ImGui::TextDisabled("Invalid Asset");
return;
}
ACogAbilityReplicator* Replicator = ACogAbilityReplicator::GetLocalReplicator(*GetWorld());
if (Replicator == nullptr)
{
ImGui::TextDisabled("Invalid Replicator");
return;
}
@@ -54,7 +54,7 @@ void FCogAbilityWindow_Tweaks::RenderContent()
ImGui::EndMenuBar();
}
int32 CurrentTweakProfileIndex = Replicator->GetTweakProfileIndex();
const int32 CurrentTweakProfileIndex = Replicator->GetTweakProfileIndex();
FName CurrentProfileName = FName("None");
if (Asset->TweakProfiles.IsValidIndex(CurrentTweakProfileIndex))
{
@@ -64,7 +64,7 @@ void FCogAbilityWindow_Tweaks::RenderContent()
if (ImGui::BeginCombo("Profile", TCHAR_TO_ANSI(*CurrentProfileName.ToString())))
{
{
bool IsSelected = CurrentTweakProfileIndex == INDEX_NONE;
const bool IsSelected = CurrentTweakProfileIndex == INDEX_NONE;
if (ImGui::Selectable("None", IsSelected))
{
Replicator->SetTweakProfile(INDEX_NONE);
@@ -74,7 +74,7 @@ void FCogAbilityWindow_Tweaks::RenderContent()
for (int32 TweakProfileIndex = 0; TweakProfileIndex < Asset->TweakProfiles.Num(); ++TweakProfileIndex)
{
const FCogAbilityTweakProfile& TweakProfile = Asset->TweakProfiles[TweakProfileIndex];
bool IsSelected = TweakProfileIndex == CurrentTweakProfileIndex;
const bool IsSelected = TweakProfileIndex == CurrentTweakProfileIndex;
if (ImGui::Selectable(TCHAR_TO_ANSI(*TweakProfile.Name.ToString()), IsSelected))
{
@@ -2,7 +2,6 @@
#include "CoreMinimal.h"
#include "ActiveGameplayEffectHandle.h"
#include "GameplayTagContainer.h"
#include "CogWindow.h"
#include "CogWindowConfig.h"
#include "imgui.h"