Adding Status and Last server response handled but not tested
This commit is contained in:
@ -6,8 +6,10 @@
|
||||
|
||||
#include "DTFluxCoreSubsystemModule.h"
|
||||
#include "DTFluxGeneralSettings.h"
|
||||
#include "FileHelpers.h"
|
||||
#include "Assets/DTFluxModelAsset.h"
|
||||
#include "Subsystems/DTFluxNetworkSubsystem.h"
|
||||
#include "UObject/SavePackage.h"
|
||||
|
||||
void UDTFluxCoreSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
{
|
||||
@ -17,22 +19,26 @@ void UDTFluxCoreSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
{
|
||||
const UDTFluxGeneralSettings* GeneralSettings = GetDefault<UDTFluxGeneralSettings>();
|
||||
TSoftObjectPtr<UDTFluxModelAsset> ModelAsset = GeneralSettings->ModelAsset;
|
||||
DataStorage = ModelAsset.LoadSynchronous();
|
||||
// UE_LOG(logDTFluxCore, Log, TEXT("GeneralSettings is nullptr -> %s"), GeneralSettings == nullptr ? TEXT("TRUE") : TEXT("FALSE"));
|
||||
// UE_LOG(logDTFluxCore, Log, TEXT("ModelAsset isNull() -> %s"), ModelAsset.IsNull() ? TEXT("TRUE") : TEXT("FALSE"));
|
||||
// UE_LOG(logDTFluxCore, Log, TEXT("ModelAsset IsValid() -> %s"), ModelAsset.IsValid() ? TEXT("TRUE") : TEXT("FALSE"));
|
||||
// UE_LOG(logDTFluxCore, Log, TEXT("DataStorage is nullptr -> %s"), DataStorage == nullptr ? TEXT("TRUE") : TEXT("FALSE"));
|
||||
// if(ModelAsset.IsValid())
|
||||
// {
|
||||
// }
|
||||
// UE_LOG(logDTFluxCore, Error, TEXT("ModelAsset Not Valid"));
|
||||
DataStorage = DataStorage = Cast<UDTFluxModelAsset>(ModelAsset.LoadSynchronous());
|
||||
if(!DataStorage)
|
||||
{
|
||||
UE_LOG(logDTFluxCore, Error, TEXT("DataStorage Not Valid"));
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// MakeStorageEditable(DataStorage);
|
||||
// }
|
||||
}
|
||||
|
||||
//TODO REMOVE This as it's only for testing purpose
|
||||
NetworkSubsystem = GEngine->GetEngineSubsystem<UFDTFluxNetworkSubsystem>();
|
||||
NetworkSubsystem = GEngine->GetEngineSubsystem<UDTFluxNetworkSubsystem>();
|
||||
if(NetworkSubsystem->WsStatus != EDTFluxConnectionStatus::Connected)
|
||||
{
|
||||
RegisterDelegates();
|
||||
NetworkSubsystem->Connect();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::Deinitialize()
|
||||
@ -40,18 +46,66 @@ void UDTFluxCoreSubsystem::Deinitialize()
|
||||
Super::Deinitialize();
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::SaveDataStorage()
|
||||
{
|
||||
if(DataStorage)
|
||||
{
|
||||
DataStorage->MarkPackageDirty();
|
||||
UPackage* Package = DataStorage->GetPackage();
|
||||
if(Package->IsDirty())
|
||||
{
|
||||
FString PackageName = Package->GetName();
|
||||
FString FileExtension = FPackageName::GetAssetPackageExtension();
|
||||
FString FilePath = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir() / PackageName.Replace(TEXT("/"), TEXT("/")) + FileExtension);
|
||||
FString LongPackageName = DataStorage->GetOutermost()->GetName();
|
||||
FString RealAssetPath;
|
||||
bool bExists = FPackageName::DoesPackageExist(PackageName);
|
||||
if (!bExists)
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Error, TEXT("Le package n'existe pas ou est un redirecteur"));
|
||||
}
|
||||
bool bSuccess = FPackageName::SearchForPackageOnDisk(LongPackageName, &RealAssetPath);
|
||||
|
||||
if (bSuccess && !RealAssetPath.IsEmpty())
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Log, TEXT("Vrai path trouvé : %s"), *RealAssetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Aucun path valide trouvé pour sauvegarder l'asset"));
|
||||
}
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Saving DataAsset to %s"), *FilePath);
|
||||
TSoftObjectPtr<UDTFluxModelAsset> ModelAsset = GetDefault<UDTFluxGeneralSettings>()->ModelAsset;
|
||||
FString RealPath = ModelAsset->GetPathName();
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("SoftObjectPath to %s"), *RealPath);
|
||||
|
||||
FSavePackageArgs Args;
|
||||
Args.TopLevelFlags = RF_Public | RF_Standalone;
|
||||
Args.bSlowTask = false;
|
||||
Args.SaveFlags = SAVE_None;
|
||||
GEditor->SavePackage(Package, DataStorage, *FilePath, Args);
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("DataAsset Saved"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::RegisterDelegates()
|
||||
{
|
||||
if(NetworkSubsystem)
|
||||
{
|
||||
NetworkSubsystem->OnReceivedRaceData().AddDynamic(this, &UDTFluxCoreSubsystem::ParseRaceData);
|
||||
NetworkSubsystem->OnReceivedTeamList().AddDynamic(this, &UDTFluxCoreSubsystem::ParseTeamList);
|
||||
NetworkSubsystem->OnReceivedContestRanking().AddDynamic(this, &UDTFluxCoreSubsystem::ParseContestRanking);
|
||||
NetworkSubsystem->OnReceivedStageRanking().BindUFunction(this, "ParseStageOrSplitRanking");
|
||||
NetworkSubsystem->OnReceivedRaceData().BindUFunction(this, "ProcessRaceData");
|
||||
NetworkSubsystem->OnReceivedTeamList().BindUFunction(this, "ProcessTeamList");
|
||||
NetworkSubsystem->OnReceivedContestRanking().BindUFunction(this, "ProcessContestRanking");
|
||||
NetworkSubsystem->OnReceivedStageRanking().BindUFunction(this, "ProcessStageRanking");
|
||||
NetworkSubsystem->OnReceivedSplitRanking().BindUFunction(this, "ProcessSplitRanking");
|
||||
NetworkSubsystem->OnReceivedTeamUpdate().BindUFunction(this, "ProcessTeamList");
|
||||
NetworkSubsystem->OnReceivedTeamStatusUpdate().BindUFunction(this, "ProcessTeamStatusUpdate");
|
||||
NetworkSubsystem->OnReceivedSplitSensor().BindUFunction(this, "ProcessSplitSensor");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::ParseRaceData(const FDTFluxRaceData& RaceDataDefinition)
|
||||
void UDTFluxCoreSubsystem::ProcessRaceData(const FDTFluxRaceData& RaceDataDefinition)
|
||||
{
|
||||
|
||||
if( RaceDataDefinition.Datas.Num() > 0 )
|
||||
@ -69,66 +123,65 @@ void UDTFluxCoreSubsystem::ParseRaceData(const FDTFluxRaceData& RaceDataDefiniti
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Error, TEXT("DataStorage is null"));
|
||||
}
|
||||
SaveDataStorage();
|
||||
return;
|
||||
}
|
||||
UE_LOG(logDTFluxCoreSubsystem, Error, TEXT("RaceDataDefinition is empty !!!"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::ParseTeamList(const FDTFluxTeamListDefinition& TeamListDefinition)
|
||||
void UDTFluxCoreSubsystem::ProcessTeamList(const FDTFluxTeamListDefinition& TeamListDefinition)
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received TeamList with %i Items"), TeamListDefinition.Datas.Num());
|
||||
for(auto InParticipantDefinition : TeamListDefinition.Datas)
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received TeamList with %i Items"), TeamListDefinition.Participants.Num());
|
||||
for(const auto& Participant : TeamListDefinition.Participants)
|
||||
{
|
||||
FDTFluxParticipant NewParticipant;
|
||||
NewParticipant.Person1.Gender = InParticipantDefinition.Gender;
|
||||
NewParticipant.Person1.FirstName = InParticipantDefinition.FirstName;
|
||||
NewParticipant.Person1.LastName = InParticipantDefinition.LastName;
|
||||
if(InParticipantDefinition.Team != "")
|
||||
{
|
||||
NewParticipant.Person2.Gender = InParticipantDefinition.Gender2;
|
||||
NewParticipant.Person2.FirstName = InParticipantDefinition.FirstName2;
|
||||
NewParticipant.Person2.LastName = InParticipantDefinition.LastName2;
|
||||
}
|
||||
NewParticipant.Bib = InParticipantDefinition.Bib;
|
||||
NewParticipant.Category = InParticipantDefinition.Category;
|
||||
NewParticipant.Club = InParticipantDefinition.Club;
|
||||
NewParticipant.Status = static_cast<EDTFluxParticipantStatusType>(InParticipantDefinition.Status);
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Add Participant %s %s in %i ContestId"),
|
||||
*NewParticipant.Person1.FirstName, *NewParticipant.Person1.LastName, InParticipantDefinition.ContestId );
|
||||
DataStorage->AddParticipant(NewParticipant, InParticipantDefinition.ContestId);
|
||||
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Add Participant %i in %i ContestId"),
|
||||
Participant.Bib, Participant.ContestId );
|
||||
|
||||
DataStorage->AddParticipant(Participant, Participant.ContestId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::ParseContestRanking(const FDTFluxContestRankings& ContestRankings)
|
||||
void UDTFluxCoreSubsystem::ProcessContestRanking(const FDTFluxContestRankings& ContestRankings)
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received ContestRankings with %i Items"), ContestRankings.Rankings.Num());
|
||||
FDTFluxContestRankings NewContestRankings = ContestRankings;
|
||||
NewContestRankings.SetName( DataStorage->GetContestNameForId(ContestRankings.ContestId));
|
||||
DataStorage->AddContestRanking(NewContestRankings);
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("ContestRankings added for Contest %s"), *NewContestRankings.ContestName);
|
||||
DataStorage->MarkPackageDirty();
|
||||
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::ParseStageOrSplitRanking(const FDTFluxStageRankings& StageOrSplitRankings)
|
||||
void UDTFluxCoreSubsystem::ProcessStageRanking(const FDTFluxStageRankings& StageRankings)
|
||||
{
|
||||
if(StageOrSplitRankings.SplitId == -1)
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received StageRankings with %i Items"), StageOrSplitRankings.Rankings.Num());
|
||||
if(!DataStorage->UpdateStageRanking(StageOrSplitRankings))
|
||||
{
|
||||
DataStorage->StageRankings.Add(StageOrSplitRankings);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received SplitRankings with %i Items"), StageOrSplitRankings.Rankings.Num());
|
||||
}
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received StageRankings with %i Items"), StageRankings.Rankings.Num());
|
||||
DataStorage->UpdateOrCreateStageRanking(StageRankings);
|
||||
DataStorage->MarkPackageDirty();
|
||||
}
|
||||
void UDTFluxCoreSubsystem::ProcessSplitRanking(const FDTFluxSplitRankings& SplitRankings)
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received SplitRanking with %i Items"), SplitRankings.Rankings.Num());
|
||||
DataStorage->UpdateOrCreateSplitRanking(SplitRankings);
|
||||
DataStorage->MarkPackageDirty();
|
||||
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::OnDataReceived()
|
||||
void UDTFluxCoreSubsystem::ProcessTeamStatusUpdate()
|
||||
{
|
||||
//TODO IMPLEMENT ME !!!!
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::ProcessSplitSensor()
|
||||
{
|
||||
//TODO IMPLEMENT ME !!!!
|
||||
}
|
||||
|
||||
|
||||
void UDTFluxCoreSubsystem::SendRequest(const FString& Message)
|
||||
{
|
||||
if(NetworkSubsystem)
|
||||
@ -191,5 +244,3 @@ void UDTFluxCoreSubsystem::RefreshStorage()
|
||||
{
|
||||
// TODO Implement this
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user