// Fill out your copyright notice in the Description page of Project Settings. #include "Assets/DTFluxModelAsset.h" #include "DTFluxCoreModule.h" #include "Types/Objects/DTFluxContestStorage.h" UDTFluxModelAsset::UDTFluxModelAsset(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { } void UDTFluxModelAsset::AddContest(const FDTFluxContest &Contest) { Contests.Add(Contest.Name, Contest); } bool UDTFluxModelAsset::GetContestById(const int InContestId, FDTFluxContest& OutContest) { for(auto& ContestItem : Contests) { if(ContestItem.Value.ContestId == InContestId) { OutContest = ContestItem.Value; return true; } } return false; } void UDTFluxModelAsset::AddPerson(const FDTFluxPerson& InPerson) { Persons.Add(InPerson); } void UDTFluxModelAsset::AddParticipant(const FDTFluxParticipant& InParticipant, const int ContestId) { UE_LOG(logDTFluxCore, Error, TEXT("%i Person in Participant %i"), InParticipant.GetTeammateNum(), InParticipant.Bib); FDTFluxContest TargetContest; if(GetContestById(ContestId, TargetContest)) { TArray Teammate = InParticipant.Teammate; for(auto& Person : InParticipant.Teammate) { UE_LOG(logDTFluxCore, Error, TEXT("AddParticipant() DTFlux Person %s %s %s"), *Person.FirstName, *Person.LastName, *Person.Gender); if(!PersonExists(Person)) { UE_LOG(logDTFluxCore, Error, TEXT("AddParticipant() DTFlux Person %s %s %s doesnot exists, adding..."), *Person.FirstName, *Person.LastName, *Person.Gender); AddPerson(Person); } } Participants.Add(InParticipant.Bib, InParticipant); TargetContest.ParticipantsBib.Add(InParticipant.Bib); } } bool UDTFluxModelAsset::PersonExists(const FDTFluxPerson& InPerson) const { return Persons.ContainsByPredicate([InPerson](const FDTFluxPerson& Person) { return Person == InPerson; }); } FString UDTFluxModelAsset::GetContestNameForId(const int InContestID) { FDTFluxContest Contest; if(!GetContestById(InContestID, Contest)) { UE_LOG(logDTFluxCore, Warning, TEXT("GetContestNameForId(%i) [unable to find a contest] result will be empty !!!"), InContestID); } return Contest.Name; } void UDTFluxModelAsset::AddContestRanking(const FDTFluxContestRankings& NewContestRankings) { ContestRankings.Add(NewContestRankings.ContestId, NewContestRankings); } void UDTFluxModelAsset::UpdateParticipant(const FDTFluxParticipant& Participant) { // TODO : If update is on Bib we are totally lost as we search by bib. int Bib = Participant.Bib; if(Participants.Contains(Bib)) { TArray InTeammate = Participant.Teammate; Participants[Bib].Elite = Participant.Elite; Participants[Bib].ContestId = Participant.ContestId; Participants[Bib].Club = Participant.Club; Participants[Bib].Category = Participant.Category; Participants[Bib].Team = Participant.Team; Participants[Bib].Status = Participant.Status; //TODO : Update Person for(const auto& Person : InTeammate) { //Don't know what to do... } } } void UDTFluxModelAsset::UpdateParticipantStatus(const FDTFluxTeamStatusUpdate& NewParticipantStatus) { if(Participants.Contains(NewParticipantStatus.Bib)) { Participants[NewParticipantStatus.Bib].Status = NewParticipantStatus.Status; } } void UDTFluxModelAsset::UpdateOrCreateStageRanking(const FDTFluxStageRankings& InStageRankings) { FDTFluxStageKey StageKey = InStageRankings.GetCompositeKey(); StageRankings.FindOrAdd(StageKey) = InStageRankings; } void UDTFluxModelAsset::AddStageRanking(const FDTFluxStageRankings& InStageRankings) { StageRankings.Add(InStageRankings.GetCompositeKey(), InStageRankings); } void UDTFluxModelAsset::AddSplitRanking(const FDTFluxSplitRankings& InSplitRanking) { SplitRankings.Add(InSplitRanking.GetCompositeKey(), InSplitRanking); } void UDTFluxModelAsset::UpdateOrCreateSplitRanking(const FDTFluxSplitRankings& InSplitRankings) { FDTFluxSplitKey SplitKey = InSplitRankings.GetCompositeKey(); SplitRankings.FindOrAdd(SplitKey) = InSplitRankings; }