Update FormatedName functionality now just truncates and adds OverflowChar + fixing getter Split, Stage, Contest
This commit is contained in:
@ -35,73 +35,74 @@ FString FDTFluxPerson::GetNormalizedString() const
|
||||
|
||||
bool FDTFluxPerson::IsValid() const
|
||||
{
|
||||
return !FirstName.TrimStartAndEnd().IsEmpty() &&
|
||||
!LastName.TrimStartAndEnd().IsEmpty() &&
|
||||
!Gender.TrimStartAndEnd().IsEmpty();
|
||||
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)
|
||||
, ContestId(-1)
|
||||
, Elite(false)
|
||||
, Status(static_cast<EDTFluxParticipantStatusType>(0))
|
||||
, bIsMassStartParticipant(false)
|
||||
, CurrentSplit(-1)
|
||||
{
|
||||
Teammate.Reset();
|
||||
}
|
||||
|
||||
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")))
|
||||
, 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, Log, TEXT("Creating participant from JSON - Bib: %d, Contest: %d"), Bib, ContestId);
|
||||
|
||||
|
||||
for (uint8 Index = 1; Index <= 10; Index++)
|
||||
{
|
||||
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))
|
||||
if (!JsonObject->HasField(FirstNameKey) && !JsonObject->HasField(LastNameKey) && !JsonObject->
|
||||
HasField(GenderKey))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
const FString FirstName = JsonObject->GetStringField(FirstNameKey);
|
||||
const FString LastName = JsonObject->GetStringField(LastNameKey);
|
||||
const FString Gender = JsonObject->GetStringField(GenderKey);
|
||||
|
||||
|
||||
if (FirstName.TrimStartAndEnd().IsEmpty() && LastName.TrimStartAndEnd().IsEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
FDTFluxPerson 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)"),
|
||||
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'"),
|
||||
UE_LOG(logDTFluxCore, Warning, TEXT("Invalid person data at index %d: '%s' '%s' '%s'"),
|
||||
Index, *FirstName, *LastName, *Gender);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UE_LOG(logDTFluxCore, Log, TEXT("Participant created with %d teammates"), Teammate.Num());
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@ void FDTFluxParticipant::AddTeammate(const FString& LastName, const FString& Fir
|
||||
Person.FirstName = FirstName.TrimStartAndEnd();
|
||||
Person.LastName = LastName.TrimStartAndEnd();
|
||||
Person.Gender = Gender.TrimStartAndEnd();
|
||||
|
||||
|
||||
AddTeammate(Person);
|
||||
}
|
||||
|
||||
@ -157,16 +158,15 @@ const TArray<FDTFluxPerson>& FDTFluxParticipant::GetTeammate() const
|
||||
return Teammate;
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetFormattedName(const int MaxChar, const FString& Separator, const FString& OverflowChar) const
|
||||
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())
|
||||
@ -197,92 +197,64 @@ FString FDTFluxParticipant::GetFormattedName(const int MaxChar, const FString& S
|
||||
{
|
||||
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;
|
||||
return FullName.Left(MaxChar) + OverflowChar;
|
||||
}
|
||||
|
||||
FString FDTFluxParticipant::GetConcatFormattedName(const int MaxChar, const FString& Separator,
|
||||
const FString& OverflowChar, const FString& BibSeparator) const
|
||||
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
|
||||
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
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
const FString& Separator, const FString& OverflowChar,
|
||||
const FString& BibSeparator)
|
||||
{
|
||||
return Participant.GetConcatFormattedNameText(MaxChar, Separator, OverflowChar, BibSeparator);
|
||||
}
|
||||
@ -294,12 +266,12 @@ FDTFluxParticipant FDTFluxParticipant::CreateFromJson(const TSharedPtr<FJsonObje
|
||||
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))
|
||||
, Status(static_cast<EDTFluxParticipantStatusType>(InStatus))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,10 +129,13 @@ public:
|
||||
FDTFluxContest ContestDefinition;
|
||||
if (GetContestForId(ContestId, ContestDefinition))
|
||||
{
|
||||
if (ContestDefinition.Stages.IsValidIndex(StageId))
|
||||
for (auto& Stage : ContestDefinition.Stages)
|
||||
{
|
||||
OutStageDefinition = ContestDefinition.Stages[StageId];
|
||||
return true;
|
||||
if (Stage.StageId == StageId)
|
||||
{
|
||||
OutStageDefinition = Stage;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
OutStageDefinition = FDTFluxStage();
|
||||
@ -149,10 +152,13 @@ public:
|
||||
FDTFluxContest ContestDefinition;
|
||||
if (GetContestForId(ContestId, ContestDefinition))
|
||||
{
|
||||
if (ContestDefinition.Splits.IsValidIndex(SplitId))
|
||||
for (auto& Split : ContestDefinition.Splits)
|
||||
{
|
||||
OutSplitDefinition = ContestDefinition.Splits[SplitId];
|
||||
return true;
|
||||
if (Split.SplitId == SplitId)
|
||||
{
|
||||
OutSplitDefinition = Split;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
OutSplitDefinition = FDTFluxSplit();
|
||||
|
||||
Reference in New Issue
Block a user