Core Structure cleaning
This commit is contained in:
@ -1,3 +1,67 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "Types/Struct/DTFluxRaceDataStructs.h"
|
||||
|
||||
bool FDTFluxContest::IsFinished() const
|
||||
{
|
||||
return EndTime <= FDateTime::Now();
|
||||
}
|
||||
|
||||
void FDTFluxContest::UpdateEndTime()
|
||||
{
|
||||
TArray<FDTFluxStage> TempStages = Stages;
|
||||
TempStages.Sort([](const FDTFluxStage& A, const FDTFluxStage& B)
|
||||
{
|
||||
return A.EndTime < B.EndTime;
|
||||
});
|
||||
EndTime = TempStages.Last().EndTime;
|
||||
}
|
||||
|
||||
int FDTFluxContest::GetLastStageId()
|
||||
{
|
||||
if (LastStageId <= 0)
|
||||
{
|
||||
UpdateLastStageId();
|
||||
}
|
||||
return LastStageId;
|
||||
}
|
||||
|
||||
void FDTFluxContest::UpdateLastStageId()
|
||||
{
|
||||
TArray<FDTFluxStage> TempStages = Stages;
|
||||
TempStages.Sort([](const FDTFluxStage& A, const FDTFluxStage& B)
|
||||
{
|
||||
return A.StageId < B.StageId;
|
||||
});
|
||||
LastStageId = TempStages.Last().StageId;
|
||||
}
|
||||
|
||||
FDTFluxStage& FDTFluxContest::GetLastStage() const
|
||||
{
|
||||
TArray<FDTFluxStage> TempStages = Stages;
|
||||
TempStages.Sort([](const FDTFluxStage& A, const FDTFluxStage& B)
|
||||
{
|
||||
return A.StageId < B.StageId;
|
||||
});
|
||||
return TempStages.Last();
|
||||
}
|
||||
|
||||
bool FDTFluxContest::GetStage(const int StageID, FDTFluxStage& OutStage) const
|
||||
{
|
||||
if (Stages.Num() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (const FDTFluxStage& Stage : Stages)
|
||||
{
|
||||
if (Stage.StageId == StageID)
|
||||
{
|
||||
OutStage = Stage;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,140 +1,145 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Types/Struct/DTFluxTeamListStruct.h"
|
||||
|
||||
#include "DTFluxCoreModule.h"
|
||||
#include "Dom/JsonObject.h"
|
||||
|
||||
// ===================================
|
||||
// FDTFluxPerson Implementation
|
||||
// ===================================
|
||||
|
||||
void FDTFluxParticipant::AddTeammate(const FDTFluxPerson& Person)
|
||||
bool FDTFluxPerson::operator==(const FDTFluxPerson& Right) const
|
||||
{
|
||||
Teammate.Add(Person);
|
||||
return GetNormalizedString() == Right.GetNormalizedString();
|
||||
}
|
||||
|
||||
void FDTFluxParticipant::AddTeammate(const FString LastName, const FString FirstName, const FString Gender)
|
||||
bool FDTFluxPerson::operator!=(const FDTFluxPerson& Right) const
|
||||
{
|
||||
return !(*this == Right);
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetFormattedName(const int MaxChar, const FString Separator,
|
||||
const FString OverflowChars) const
|
||||
bool FDTFluxPerson::operator==(const int Length) const
|
||||
{
|
||||
{
|
||||
if (MaxChar <= 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
FString FirstName;
|
||||
FString LastName;
|
||||
if (IsTeam())
|
||||
{
|
||||
LastName = Team;
|
||||
}
|
||||
else
|
||||
{
|
||||
FirstName = Teammate[0].FirstName;
|
||||
LastName = Teammate[0].LastName;
|
||||
}
|
||||
FString Initial;
|
||||
if (!FirstName.IsEmpty())
|
||||
{
|
||||
Initial = FirstName.Left(1).ToUpper() + Separator;
|
||||
}
|
||||
|
||||
FString FormattedLastName = LastName.ToUpper();
|
||||
|
||||
FString FullName = Initial + FormattedLastName;
|
||||
UE_LOG(logDTFluxCore, VeryVerbose, TEXT("FullName for Bib %i is %s"), Bib, *FullName);
|
||||
|
||||
if (FullName.Len() <= MaxChar)
|
||||
{
|
||||
return FullName;
|
||||
}
|
||||
|
||||
const int32 OverflowLength = OverflowChars.Len();
|
||||
|
||||
if (OverflowLength > MaxChar)
|
||||
{
|
||||
return FullName.Left(MaxChar);
|
||||
}
|
||||
|
||||
if (Initial.Len() + OverflowLength > MaxChar)
|
||||
{
|
||||
return FullName.Left(MaxChar);
|
||||
}
|
||||
|
||||
const int32 AvailableForLastName = MaxChar - Initial.Len() - OverflowLength;
|
||||
|
||||
if (AvailableForLastName <= 0)
|
||||
{
|
||||
return FullName.Left(MaxChar);
|
||||
}
|
||||
|
||||
FString TruncatedName = Initial + FormattedLastName.Left(AvailableForLastName) + OverflowChars;
|
||||
|
||||
if (TruncatedName.Len() > MaxChar)
|
||||
{
|
||||
return TruncatedName.Left(MaxChar);
|
||||
}
|
||||
|
||||
return TruncatedName;
|
||||
}
|
||||
return GetNormalizedString().Len() == Length;
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetConcatFormattedName(const int MaxChar, const FString Separator,
|
||||
const FString OverflowChar, const FString BibSeparator) const
|
||||
bool FDTFluxPerson::operator!=(const int Length) const
|
||||
{
|
||||
FString BibText = FString::FromInt(Bib) + BibSeparator;
|
||||
FString FormattedName = GetFormattedName(MaxChar - BibText.Len(), Separator, OverflowChar);
|
||||
return BibText + FormattedName;
|
||||
return !(*this == Length);
|
||||
}
|
||||
|
||||
FString FDTFluxPerson::GetNormalizedString() const
|
||||
{
|
||||
return FirstName.ToLower() + LastName.ToLower() + Gender.ToLower();
|
||||
}
|
||||
|
||||
bool FDTFluxPerson::IsValid() const
|
||||
{
|
||||
return !FirstName.TrimStartAndEnd().IsEmpty() &&
|
||||
!LastName.TrimStartAndEnd().IsEmpty() &&
|
||||
!Gender.TrimStartAndEnd().IsEmpty();
|
||||
}
|
||||
|
||||
FDTFluxParticipant::FDTFluxParticipant()
|
||||
: Bib(-1)
|
||||
, ContestId(-1)
|
||||
, Elite(false)
|
||||
, Status(static_cast<EDTFluxParticipantStatusType>(0))
|
||||
, bIsMassStartParticipant(false)
|
||||
, CurrentSplit(-1)
|
||||
{
|
||||
Teammate.Reset();
|
||||
}
|
||||
|
||||
// Constructeur privé depuis JSON
|
||||
FDTFluxParticipant::FDTFluxParticipant(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
: Bib(JsonObject->GetIntegerField(TEXT("bib")))
|
||||
, ContestId(JsonObject->GetIntegerField(TEXT("contestId")))
|
||||
, Category(JsonObject->GetStringField(TEXT("category")))
|
||||
, Club(JsonObject->GetStringField(TEXT("club")))
|
||||
, Elite(JsonObject->GetBoolField(TEXT("elite")))
|
||||
, Status(static_cast<EDTFluxParticipantStatusType>(JsonObject->GetIntegerField(TEXT("status"))))
|
||||
, Team(JsonObject->GetStringField(TEXT("team")))
|
||||
, bIsMassStartParticipant(false)
|
||||
, CurrentSplit(-1)
|
||||
, ContestId(JsonObject->GetIntegerField(TEXT("contestId")))
|
||||
, Category(JsonObject->GetStringField(TEXT("category")))
|
||||
, Club(JsonObject->GetStringField(TEXT("club")))
|
||||
, Elite(JsonObject->GetBoolField(TEXT("elite")))
|
||||
, Status(static_cast<EDTFluxParticipantStatusType>(JsonObject->GetIntegerField(TEXT("status"))))
|
||||
, Team(JsonObject->GetStringField(TEXT("team")))
|
||||
, CurrentSplit(-1)
|
||||
{
|
||||
UE_LOG(logDTFluxCore, Error, TEXT("Ctor with JSON Object"))
|
||||
for (uint8 Index = 1; ; Index++)
|
||||
UE_LOG(logDTFluxCore, Log, TEXT("Creating participant from JSON - Bib: %d, Contest: %d"), Bib, ContestId);
|
||||
|
||||
for (uint8 Index = 1; Index <= 10; Index++)
|
||||
{
|
||||
FString FirstNameKey = Index == 1 ? "firstName" : FString::Printf(TEXT("firstName%i"), Index);
|
||||
FString LastNameKey = Index == 1 ? "lastName" : FString::Printf(TEXT("lastName%i"), Index);
|
||||
FString GenderKey = Index == 1 ? "gender" : FString::Printf(TEXT("gender%i"), Index);
|
||||
// max 10 Persons
|
||||
if (Index >= 10)
|
||||
FString FirstNameKey = Index == 1 ? TEXT("firstName") : FString::Printf(TEXT("firstName%d"), Index);
|
||||
FString LastNameKey = Index == 1 ? TEXT("lastName") : FString::Printf(TEXT("lastName%d"), Index);
|
||||
FString GenderKey = Index == 1 ? TEXT("gender") : FString::Printf(TEXT("gender%d"), Index);
|
||||
|
||||
// Vérifie si au moins un des champs existe
|
||||
if (!JsonObject->HasField(FirstNameKey) && !JsonObject->HasField(LastNameKey) && !JsonObject->HasField(GenderKey))
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (!JsonObject->HasField(FirstNameKey) && !JsonObject->HasField(LastNameKey)
|
||||
&& !JsonObject->HasField(GenderKey))
|
||||
{
|
||||
UE_LOG(logDTFluxCore, Error, TEXT("No Corresponding Field!!!"))
|
||||
break;
|
||||
}
|
||||
|
||||
const FString FirstName = JsonObject->GetStringField(FirstNameKey);
|
||||
const FString LastName = JsonObject->GetStringField(LastNameKey);
|
||||
const FString Gender = JsonObject->GetStringField(GenderKey);
|
||||
if (FirstName.IsEmpty() && LastName.IsEmpty())
|
||||
|
||||
if (FirstName.TrimStartAndEnd().IsEmpty() && LastName.TrimStartAndEnd().IsEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FDTFluxPerson Person;
|
||||
Person.FirstName = FirstName;
|
||||
Person.LastName = LastName;
|
||||
Person.Gender = Gender;
|
||||
Teammate.Add(Person);
|
||||
Person.FirstName = FirstName.TrimStartAndEnd();
|
||||
Person.LastName = LastName.TrimStartAndEnd();
|
||||
Person.Gender = Gender.TrimStartAndEnd();
|
||||
|
||||
if (Person.IsValid())
|
||||
{
|
||||
Teammate.Add(Person);
|
||||
UE_LOG(logDTFluxCore, Verbose, TEXT("Added person %d: %s %s (%s)"),
|
||||
Index, *Person.FirstName, *Person.LastName, *Person.Gender);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxCore, Warning, TEXT("Invalid person data at index %d: '%s' '%s' '%s'"),
|
||||
Index, *FirstName, *LastName, *Gender);
|
||||
}
|
||||
}
|
||||
UE_LOG(logDTFluxCore, Error, TEXT("Ctor with JSON Object Teammate is now %i long"), Teammate.Num());
|
||||
|
||||
UE_LOG(logDTFluxCore, Log, TEXT("Participant created with %d teammates"), Teammate.Num());
|
||||
}
|
||||
|
||||
FDTFluxParticipant FDTFluxParticipant::CreateFromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
bool FDTFluxParticipant::IsDefault() const
|
||||
{
|
||||
return FDTFluxParticipant(JsonObject);
|
||||
return Bib == -1
|
||||
&& ContestId == -1
|
||||
&& Category.IsEmpty()
|
||||
&& Club.IsEmpty()
|
||||
&& !Elite
|
||||
&& Status == static_cast<EDTFluxParticipantStatusType>(0)
|
||||
&& Team.IsEmpty()
|
||||
&& !bIsMassStartParticipant
|
||||
&& CurrentSplit == -1
|
||||
&& Teammate.IsEmpty();
|
||||
}
|
||||
|
||||
void FDTFluxParticipant::AddTeammate(const FDTFluxPerson& Person)
|
||||
{
|
||||
if (Person.IsValid())
|
||||
{
|
||||
Teammate.Add(Person);
|
||||
UE_LOG(logDTFluxCore, Verbose, TEXT("Added teammate: %s %s"), *Person.FirstName, *Person.LastName);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxCore, Warning, TEXT("Cannot add invalid teammate: %s %s"), *Person.FirstName, *Person.LastName);
|
||||
}
|
||||
}
|
||||
|
||||
void FDTFluxParticipant::AddTeammate(const FString& LastName, const FString& FirstName, const FString& Gender)
|
||||
{
|
||||
FDTFluxPerson Person;
|
||||
Person.FirstName = FirstName.TrimStartAndEnd();
|
||||
Person.LastName = LastName.TrimStartAndEnd();
|
||||
Person.Gender = Gender.TrimStartAndEnd();
|
||||
|
||||
AddTeammate(Person);
|
||||
}
|
||||
|
||||
int FDTFluxParticipant::GetTeammateNum() const
|
||||
@ -144,5 +149,157 @@ int FDTFluxParticipant::GetTeammateNum() const
|
||||
|
||||
bool FDTFluxParticipant::IsTeam() const
|
||||
{
|
||||
return Teammate.Num() < 1;
|
||||
return Teammate.Num() > 1;
|
||||
}
|
||||
|
||||
const TArray<FDTFluxPerson>& FDTFluxParticipant::GetTeammate() const
|
||||
{
|
||||
return Teammate;
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetFormattedName(const int MaxChar, const FString& Separator, const FString& OverflowChar) const
|
||||
{
|
||||
if (MaxChar <= 0)
|
||||
{
|
||||
return TEXT("");
|
||||
}
|
||||
|
||||
FString FirstName;
|
||||
FString LastName;
|
||||
|
||||
if (IsTeam())
|
||||
{
|
||||
if (!Team.IsEmpty())
|
||||
{
|
||||
LastName = Team;
|
||||
}
|
||||
else
|
||||
{
|
||||
TArray<FString> Names;
|
||||
for (const FDTFluxPerson& Person : Teammate)
|
||||
{
|
||||
Names.Add(Person.LastName);
|
||||
}
|
||||
LastName = FString::Join(Names, TEXT("/"));
|
||||
}
|
||||
}
|
||||
else if (Teammate.Num() > 0)
|
||||
{
|
||||
FirstName = Teammate[0].FirstName;
|
||||
LastName = Teammate[0].LastName;
|
||||
}
|
||||
else
|
||||
{
|
||||
LastName = TEXT("Unknown");
|
||||
}
|
||||
FString Initial;
|
||||
if (!FirstName.IsEmpty())
|
||||
{
|
||||
Initial = FirstName.Left(1).ToUpper() + Separator;
|
||||
}
|
||||
|
||||
FString FormattedLastName = LastName.ToUpper();
|
||||
FString FullName = Initial + FormattedLastName;
|
||||
|
||||
if (FullName.Len() <= MaxChar)
|
||||
{
|
||||
return FullName;
|
||||
}
|
||||
|
||||
const int32 OverflowLength = OverflowChar.Len();
|
||||
|
||||
if (OverflowLength > MaxChar)
|
||||
{
|
||||
return FullName.Left(MaxChar);
|
||||
}
|
||||
|
||||
if (Initial.Len() + OverflowLength > MaxChar)
|
||||
{
|
||||
return FullName.Left(MaxChar);
|
||||
}
|
||||
|
||||
const int32 AvailableForLastName = MaxChar - Initial.Len() - OverflowLength;
|
||||
|
||||
if (AvailableForLastName <= 0)
|
||||
{
|
||||
return FullName.Left(MaxChar);
|
||||
}
|
||||
|
||||
FString TruncatedName = Initial + FormattedLastName.Left(AvailableForLastName) + OverflowChar;
|
||||
|
||||
if (TruncatedName.Len() > MaxChar)
|
||||
{
|
||||
return TruncatedName.Left(MaxChar);
|
||||
}
|
||||
|
||||
return TruncatedName;
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetConcatFormattedName(const int MaxChar, const FString& Separator,
|
||||
const FString& OverflowChar, const FString& BibSeparator) const
|
||||
{
|
||||
FString BibText = FString::FromInt(Bib) + BibSeparator;
|
||||
int32 RemainingChars = MaxChar - BibText.Len();
|
||||
|
||||
if (RemainingChars <= 0)
|
||||
{
|
||||
return BibText.Left(MaxChar);
|
||||
}
|
||||
|
||||
FString FormattedName = GetFormattedName(RemainingChars, Separator, OverflowChar);
|
||||
return BibText + FormattedName;
|
||||
}
|
||||
|
||||
FText FDTFluxParticipant::GetFormattedNameText(const int MaxChar, const FString& Separator, const FString& OverflowChar) const
|
||||
{
|
||||
return FText::FromString(GetFormattedName(MaxChar, Separator, OverflowChar));
|
||||
}
|
||||
|
||||
FText FDTFluxParticipant::GetConcatFormattedNameText(const int MaxChar, const FString& Separator,
|
||||
const FString& OverflowChar, const FString& BibSeparator) const
|
||||
{
|
||||
return FText::FromString(GetConcatFormattedName(MaxChar, Separator, OverflowChar, BibSeparator));
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetFormattedName(const FDTFluxParticipant& Participant, const int MaxChar,
|
||||
const FString& Separator, const FString& OverflowChar)
|
||||
{
|
||||
return Participant.GetFormattedName(MaxChar, Separator, OverflowChar);
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetConcatFormattedName(const FDTFluxParticipant& Participant, const int MaxChar,
|
||||
const FString& Separator, const FString& OverflowChar,
|
||||
const FString& BibSeparator)
|
||||
{
|
||||
return Participant.GetConcatFormattedName(MaxChar, Separator, OverflowChar, BibSeparator);
|
||||
}
|
||||
|
||||
FText FDTFluxParticipant::GetFormattedNameText(const FDTFluxParticipant& Participant, const int MaxChar,
|
||||
const FString& Separator, const FString& OverflowChar)
|
||||
{
|
||||
return Participant.GetFormattedNameText(MaxChar, Separator, OverflowChar);
|
||||
}
|
||||
|
||||
FText FDTFluxParticipant::GetConcatFormattedNameText(const FDTFluxParticipant& Participant, const int MaxChar,
|
||||
const FString& Separator, const FString& OverflowChar,
|
||||
const FString& BibSeparator)
|
||||
{
|
||||
return Participant.GetConcatFormattedNameText(MaxChar, Separator, OverflowChar, BibSeparator);
|
||||
}
|
||||
|
||||
FDTFluxParticipant FDTFluxParticipant::CreateFromJson(const TSharedPtr<FJsonObject>& JsonObject)
|
||||
{
|
||||
if (!JsonObject.IsValid())
|
||||
{
|
||||
UE_LOG(logDTFluxCore, Error, TEXT("Cannot create participant from invalid JSON object"));
|
||||
return FDTFluxParticipant();
|
||||
}
|
||||
|
||||
return FDTFluxParticipant(JsonObject);
|
||||
}
|
||||
|
||||
FDTFluxTeamStatusUpdate::FDTFluxTeamStatusUpdate(const int InBib, const int InStatus)
|
||||
: Bib(InBib)
|
||||
, Status(static_cast<EDTFluxParticipantStatusType>(InStatus))
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user