General Blueprint utilities Functions + First Implementation of Pursuit Logic

This commit is contained in:
2025-07-04 15:17:22 +02:00
parent 801e946a89
commit a2be97cfe4
20 changed files with 503 additions and 109 deletions

View File

@ -9,7 +9,7 @@ public class DTFluxCoreSubsystem : ModuleRules
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"Core", "DTFluxCore",
}
);

View File

@ -207,6 +207,16 @@ void UDTFluxCoreSubsystem::RequestAllSplitRankingOfContest(int InContestId, int
// TODO Implement this
}
FDTFluxStageRankings UDTFluxCoreSubsystem::GetStageRankings(FDTFluxStageKey StageKey)
{
if(DataStorage->StageRankings.Contains(StageKey))
{
return DataStorage->StageRankings[StageKey];
}
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Cannot find StageRankings for key [%s]"), *StageKey.GetDisplayName());
return FDTFluxStageRankings();
}
void UDTFluxCoreSubsystem::RequestAllSplitRankingOfStage(int InContestId, int InStageId, int InSplitId)
{
// TODO Implement this
@ -216,3 +226,42 @@ void UDTFluxCoreSubsystem::RefreshStorage()
{
// TODO Implement this
}
TArray<int> UDTFluxCoreSubsystem::GetCurrentContestsId()
{
return GetContestsIdForTime(FDateTime::Now());
}
TArray<FDTFluxContest> UDTFluxCoreSubsystem::GetCurrentContests()
{
return GetContestsForTime(FDateTime::Now());
}
TArray<int> UDTFluxCoreSubsystem::GetContestsIdForTime(const FDateTime Time)
{
TArray<int> Contests;
for(const auto& Pair : DataStorage->Contests)
{
FDTFluxContest Contest = Pair.Value;
int ContestId = Contest.ContestId;
if(Contest.Date < Time && Contest.EndTime > Time)
{
Contests.Add(ContestId);
}
}
return Contests;
}
TArray<FDTFluxContest> UDTFluxCoreSubsystem::GetContestsForTime(const FDateTime Time)
{
TArray<FDTFluxContest> Contests;
for(const auto& Pair : DataStorage->Contests)
{
FDTFluxContest Contest = Pair.Value;
int ContestId = Contest.ContestId;
if(Contest.Date < Time && Contest.EndTime > Time)
{
Contests.Add(Contest);
}
}
return Contests;
}

View File

@ -0,0 +1,103 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "DTFluxCoreSubsystemTools.h"
void UDTFluxCoreSubsystemTools::FilterContestRankings(FDTFluxContestRankings& ContestRankings,
const EDTFluxSortingRankingType RankingType, TArray<FDTFluxContestRanking>& OutContestRankings, bool bAscendant)
{
// On fait une copie locale des Rankings
TArray<FDTFluxContestRanking> ContestArray = ContestRankings.Rankings;
// Tri par type + direction
ContestArray.Sort([RankingType, bAscendant](const FDTFluxContestRanking& A, const FDTFluxContestRanking& B)
{
switch (RankingType)
{
case EDTFluxSortingRankingType::Rank:
return bAscendant ? A.Rank < B.Rank : A.Rank > B.Rank;
case EDTFluxSortingRankingType::Bib:
return bAscendant ? A.Bib < B.Bib : A.Bib > B.Bib;
case EDTFluxSortingRankingType::Gap:
return CompareTimeString(A.Gap, B.Gap, bAscendant);
case EDTFluxSortingRankingType::SwimSpeed:
return CompareSpeed(A.SpeedSwimAverage, B.SpeedSwimAverage, bAscendant);
case EDTFluxSortingRankingType::RunningSpeed:
return CompareSpeed(A.SpeedRunningAverage, B.SpeedRunningAverage, bAscendant);
case EDTFluxSortingRankingType::TotalSpeed:
return CompareSpeed(A.SpeedTotalAverage, B.SpeedTotalAverage, bAscendant);
default:
return CompareTimeString(A.Time, B.Time, bAscendant);
}
});
// Réaffecte les données triées
ContestRankings.Rankings = ContestArray;
OutContestRankings = ContestArray;
}
void UDTFluxCoreSubsystemTools::FilterStageRankings(FDTFluxStageRankings& InStageRankings,
const EDTFluxSortingRankingType RankingType, FDTFluxStageRankings& OutStageRankings, bool bAscendant)
{
// TArray<FDTFluxDetailedRankings> StageArray = static_cast<TDF>()InStageRankings.Rankings;
}
void UDTFluxCoreSubsystemTools::FilterSplitRankings(FDTFluxSplitRankings& SplitRankings,
const EDTFluxSortingRankingType RankinType, FDTFluxSplitRankings& OutSplitRankings, bool bAscendant)
{
}
float UDTFluxCoreSubsystemTools::ConvertTimeStringToSeconds(const FString& TimeString)
{
// Format attendu : "HH:MM:SS"
TArray<FString> Parts;
TimeString.ParseIntoArray(Parts, TEXT(":"), true);
if (Parts.Num() == 3)
{
const int32 Hours = FCString::Atoi(*Parts[0]);
const int32 Minutes = FCString::Atoi(*Parts[1]);
const int32 Seconds = FCString::Atoi(*Parts[2]);
return Hours * 3600 + Minutes * 60 + Seconds;
}
if (Parts.Num() == 2)
{
const int32 Minutes = FCString::Atoi(*Parts[0]);
const int32 Seconds = FCString::Atoi(*Parts[1]);
return 3600 + Minutes * 60 + Seconds;
}
if (Parts.Num() == 1)
{
return FCString::Atoi(*Parts[0]);
}
return -1.0f;
}
bool UDTFluxCoreSubsystemTools::CompareTimeString(const FString& A_TimeStr, const FString& B_TimeStr, bool bAscendant)
{
const float A_Time = ConvertTimeStringToSeconds(A_TimeStr);
const float B_Time = ConvertTimeStringToSeconds(B_TimeStr);
return bAscendant ? A_Time < B_Time : A_Time > B_Time;
}
bool UDTFluxCoreSubsystemTools::CompareSpeed(const FString& A_SpeedStr, const FString& B_SpeedStr, bool bAscendant)
{
float A_Speed = FCString::Atof(*A_SpeedStr);
float B_Speed = FCString::Atof(*B_SpeedStr);
if (bAscendant)
{
return A_Speed < B_Speed;
}
return A_Speed > B_Speed;
}

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "DTFluxPursuitSystem/Public/Types/Objects/DTFluxPursuitManager.h"
#include "Subsystems/EngineSubsystem.h"
#include "Types/Enum/DTfluxCoreEnum.h"
#include "Types/Struct/DTFluxRaceDataStructs.h"
@ -29,32 +30,30 @@ class DTFLUXCORESUBSYSTEM_API UDTFluxCoreSubsystem : public UEngineSubsystem
public:
// TSharedPtr<FDTFluxParser> Parser;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSplitRankings, FDateTime, ReceivedAt, TArray<FDTFluxStageRanking>, SplitRankings);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnSplitRankings, FDTFluxSplitRankings&, SplitRankings);
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
FOnSplitRankings OnSplitRankings;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnStageRankings, FDateTime, ReceivedAt, TArray<FDTFluxStageRanking>, StageRankings);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnStageRankings, FDTFluxStageRankings&, StageRankings);
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
FOnStageRankings OnStageRankings;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnContestRankings, FDateTime, ReceivedAt, TArray<FDTFluxContestRanking>, ContestRankings);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnContestRankings, FDTFluxContestRankings&, ContestRankings);
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
FOnContestRankings OnContestRankings;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTeamList, FDateTime, ReceivedAt, TArray<FDTFluxParticipant>, TeamList);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnTeamList);
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
FOnTeamList OnTeamList;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTeamUpdate, FDateTime, ReceivedAt, FDTFluxParticipant, TeamUpdatedList);
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
FOnTeamUpdate OnTeamUpdate;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTeamStatusUpdate, FDateTime, ReceivedAt, FDTFluxParticipant, TeamUpdated);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTeamStatusUpdate, FDTFluxParticipant, TeamUpdated);
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
FOnTeamStatusUpdate OnTeamStatusUpdate;
//
// DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTeamUpdate, FDateTime, ReceivedAt, FDTFluxParticipant, TeamUpdatedList);
// UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
// FOnTeamUpdate OnTeamUpdate;
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
void SendTeamListRequest();
@ -77,12 +76,25 @@ public:
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
void RequestAllSplitRankingOfContest(int InContestId, int InStageId);
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
FDTFluxStageRankings GetStageRankings(FDTFluxStageKey StageKey);
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
void RequestAllSplitRankingOfStage(int InContestId, int InStageId, int InSplitId);
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
void RefreshStorage();
UFUNCTION()
TArray<int> GetCurrentContestsId();
UFUNCTION()
TArray<FDTFluxContest> GetCurrentContests();
UFUNCTION()
TArray<int> GetContestsIdForTime(const FDateTime Time);
UFUNCTION()
TArray<FDTFluxContest> GetContestsForTime(const FDateTime Time);
protected:
// ~Subsystem Interface
virtual void Initialize(FSubsystemCollectionBase& Collection) override;

View File

@ -0,0 +1,37 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Types/Enum/DTFluxModelEnums.h"
#include "Types/Struct/DTFluxRankingStructs.h"
#include "DTFluxCoreSubsystemTools.generated.h"
/**
*
*/
UCLASS()
class DTFLUXCORESUBSYSTEM_API UDTFluxCoreSubsystemTools : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(Blueprintable, Category="DTFlux|Core Subsystem|Tools")
static void FilterContestRankings(FDTFluxContestRankings& ContestRankings,
const EDTFluxSortingRankingType RankingType, TArray<FDTFluxContestRanking>& OutContestRankings, bool bAscendant);
UFUNCTION(Blueprintable, Category="DTFlux|Core Subsystem|Tools")
static void FilterStageRankings(FDTFluxStageRankings& InStageRankings, const EDTFluxSortingRankingType RankingType, FDTFluxStageRankings& OutStageRankings, bool bAscendant = true);
UFUNCTION(Blueprintable, Category="DTFlux|Core Subsystem|Tools")
static void FilterSplitRankings(FDTFluxSplitRankings& SplitRankings, const EDTFluxSortingRankingType RankinType, FDTFluxSplitRankings& OutSplitRankings, bool bAscendant = true);
UFUNCTION(Blueprintable, Category="DTFlux|Core Subsystem|Tools")
static float ConvertTimeStringToSeconds(const FString& TimeString);
UFUNCTION(Blueprintable, Category="DTFlux|Core Subsystem|Tools")
static bool CompareTimeString(const FString& A_TimeStr, const FString& B_TimeStr, bool bAscendant = true);
UFUNCTION(Blueprintable, Category="DTFlux|Core Subsystem|Tools")
static bool CompareSpeed(const FString& A_SpeedStr, const FString& B_SpeedStr, bool bAscendant=true);
};