From f41360ba1172d2dfca8fb713d6b3ebc4669123ba Mon Sep 17 00:00:00 2001 From: Ange-Marie MAURIN Date: Fri, 19 Jul 2024 08:18:35 +0200 Subject: [PATCH] adding Helpers GetCurrentStage GetCurrentContest GetCurrentStageName --- .../Private/DTFluxUtils/DTFluxUtils.cpp | 57 +++++++++++++++++++ .../Public/DTFluxUtils/DTFluxUtils.h | 10 ++++ 2 files changed, 67 insertions(+) diff --git a/Source/DTFluxAPI/Private/DTFluxUtils/DTFluxUtils.cpp b/Source/DTFluxAPI/Private/DTFluxUtils/DTFluxUtils.cpp index d4209c6..fb651e5 100644 --- a/Source/DTFluxAPI/Private/DTFluxUtils/DTFluxUtils.cpp +++ b/Source/DTFluxAPI/Private/DTFluxUtils/DTFluxUtils.cpp @@ -26,3 +26,60 @@ EDTFluxStageStatusType UDTFluxModelHelper::GetStatusType(const int ContestID, co } return StageStatus; } + +int UDTFluxModelHelper::GetCurrentContest(UDTFluxDataStorage* DataStorage) +{ + int ContestId = -1; + FDateTime Now = FDateTime::Now(); + for(const auto& Contest : DataStorage->Contests) + { + for(const auto& Stage : Contest.Stages) + { + // Stage has begun + if(Stage.StartTime <= Now) + { + return Contest.Id; + } + } + } + return ContestId; +} + +TArray UDTFluxModelHelper::GetCurrentStage(UDTFluxDataStorage* DataStorage) +{ + TArray ContestAndStageId; + FDateTime Now = FDateTime::Now(); + for(const auto& Contest : DataStorage->Contests) + { + for(const auto& Stage : Contest.Stages) + { + // Stage has begun + if(Stage.StartTime <= Now) + { + ContestAndStageId.Add(Contest.Id); + ContestAndStageId.Add(Stage.Id); + return ContestAndStageId; + } + } + } + return ContestAndStageId; +} + +FString UDTFluxModelHelper::GetCurrentStageName(UDTFluxDataStorage* DataStorage) +{ + FString Name; + FDateTime Now = FDateTime::Now(); + for(const auto& Contest : DataStorage->Contests) + { + for(const auto& Stage : Contest.Stages) + { + // Stage has begun + if(Stage.StartTime <= Now) + { + Name = FString::Printf(TEXT("Contest %s Stage %s"), *Contest.Name, *Stage.Name); + return Name; + } + } + } + return Name; +} diff --git a/Source/DTFluxAPI/Public/DTFluxUtils/DTFluxUtils.h b/Source/DTFluxAPI/Public/DTFluxUtils/DTFluxUtils.h index c94e589..a10790b 100644 --- a/Source/DTFluxAPI/Public/DTFluxUtils/DTFluxUtils.h +++ b/Source/DTFluxAPI/Public/DTFluxUtils/DTFluxUtils.h @@ -120,5 +120,15 @@ public: UFUNCTION(BlueprintCallable, Category="DTFlux|Model|Helpers") static EDTFluxStageStatusType GetStatusType(const int ContestID, const int StageID, UDTFluxDataStorage* DataStorage); + + UFUNCTION(BlueprintCallable, Category="DTFlux|Model|Helpers") + static int GetCurrentContest(UDTFluxDataStorage* DataStorage); + + UFUNCTION(BlueprintCallable, Category="DTFlux|Model|Helpers") + static TArray GetCurrentStage(UDTFluxDataStorage* DataStorage); + + UFUNCTION(BlueprintCallable, Category="DTFlux|Model|Helpers") + static FString GetCurrentStageName(UDTFluxDataStorage* DataStorage); + };