Network total reforge. Team-List and Race-Data handled
This commit is contained in:
31
Source/DTFluxCoreSubsystem/DTFluxCoreSubsystem.Build.cs
Normal file
31
Source/DTFluxCoreSubsystem/DTFluxCoreSubsystem.Build.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class DTFluxCoreSubsystem : ModuleRules
|
||||
{
|
||||
public DTFluxCoreSubsystem(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
}
|
||||
);
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"DTFluxNetwork",
|
||||
"DTFluxProjectSettings",
|
||||
"DTFluxCore",
|
||||
"JsonUtilities",
|
||||
"Json"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
168
Source/DTFluxCoreSubsystem/Private/DTFluxCoreSubsystem.cpp
Normal file
168
Source/DTFluxCoreSubsystem/Private/DTFluxCoreSubsystem.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "DTFluxCoreSubsystem.h"
|
||||
|
||||
|
||||
#include "DTFluxCoreSubsystemModule.h"
|
||||
#include "DTFluxGeneralSettings.h"
|
||||
#include "Assets/DTFluxModelAsset.h"
|
||||
#include "Subsystems/DTFluxNetworkSubsystem.h"
|
||||
|
||||
void UDTFluxCoreSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
{
|
||||
Super::Initialize(Collection);
|
||||
UE_LOG(logDTFluxCoreSubsystem, Log, TEXT("[UDTFluxCoreSubsystem] Initializing..."));
|
||||
if(!DataStorage)
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
//TODO REMOVE This as it's only for testing purpose
|
||||
NetworkSubsystem = GEngine->GetEngineSubsystem<UFDTFluxNetworkSubsystem>();
|
||||
if(NetworkSubsystem->WsStatus != EDTFluxConnectionStatus::Connected)
|
||||
{
|
||||
RegisterDelegates();
|
||||
NetworkSubsystem->Connect();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::Deinitialize()
|
||||
{
|
||||
Super::Deinitialize();
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::RegisterDelegates()
|
||||
{
|
||||
if(NetworkSubsystem)
|
||||
{
|
||||
NetworkSubsystem->OnReceivedRaceData().AddDynamic(this, &UDTFluxCoreSubsystem::ParseRaceData);
|
||||
NetworkSubsystem->OnReceivedTeamList().AddDynamic(this, &UDTFluxCoreSubsystem::ParseTeamList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UDTFluxCoreSubsystem::ParseRaceData(const FDTFluxRaceData& RaceDataDefinition)
|
||||
{
|
||||
|
||||
if( RaceDataDefinition.Datas.Num() > 0 )
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Receiving RaceDataDefinition [%s]"), *RaceDataDefinition.Datas[0].Name);
|
||||
if(DataStorage != nullptr)
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Error, TEXT("DataStorage Name %s"), *DataStorage->EventName);
|
||||
for(auto Contest : RaceDataDefinition.Datas)
|
||||
{
|
||||
DataStorage->AddContest(Contest);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Error, TEXT("DataStorage is null"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
UE_LOG(logDTFluxCoreSubsystem, Error, TEXT("RaceDataDefinition is empty !!!"));
|
||||
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::ParseTeamList(const FDTFluxTeamListDefinition& TeamListDefinition)
|
||||
{
|
||||
UE_LOG(logDTFluxCoreSubsystem, Warning, TEXT("Received TeamList with %i Items"), TeamListDefinition.Datas.Num());
|
||||
for(auto InParticipantDefinition : TeamListDefinition.Datas)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::OnDataReceived()
|
||||
{
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::SendRequest(const FString& Message)
|
||||
{
|
||||
if(NetworkSubsystem)
|
||||
{
|
||||
NetworkSubsystem->SendMessage(Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UDTFluxCoreSubsystem::SendTeamListRequest()
|
||||
{
|
||||
if (NetworkSubsystem)
|
||||
{
|
||||
NetworkSubsystem->SendRequest(EDTFluxRequestType::TeamList);
|
||||
}
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::SendRaceDataRequest()
|
||||
{
|
||||
if (NetworkSubsystem)
|
||||
{
|
||||
NetworkSubsystem->SendRequest(EDTFluxRequestType::RaceData);
|
||||
}
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::SendContestRankingRequest(int InContestId)
|
||||
{
|
||||
if (NetworkSubsystem)
|
||||
{
|
||||
NetworkSubsystem->SendRequest(EDTFluxRequestType::ContestRanking, InContestId);
|
||||
}
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::SendStageRankingRequest(int InContestId, int InStageId, bool bShouldIncludeSplitRanking)
|
||||
{
|
||||
// TODO Implement this
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::RequestAllStageRankingOfContest(int InContestId, int InStageId,
|
||||
bool bShouldIncludeSplitRanking)
|
||||
{
|
||||
// TODO Implement this
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::SendSplitRankingRequest(int InContestId, int InStageId, int InSplitId)
|
||||
{
|
||||
// TODO Implement this
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::RequestAllSplitRankingOfContest(int InContestId, int InStageId)
|
||||
{
|
||||
// TODO Implement this
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::RequestAllSplitRankingOfStage(int InContestId, int InStageId, int InSplitId)
|
||||
{
|
||||
// TODO Implement this
|
||||
}
|
||||
|
||||
void UDTFluxCoreSubsystem::RefreshStorage()
|
||||
{
|
||||
// TODO Implement this
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
#include "DTFluxCoreSubsystemModule.h"
|
||||
|
||||
DTFLUXCORESUBSYSTEM_API DEFINE_LOG_CATEGORY(logDTFluxCoreSubsystem)
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FDTFluxCoreSubsystemModule"
|
||||
|
||||
void FDTFluxCoreSubsystemModule::StartupModule()
|
||||
{
|
||||
}
|
||||
|
||||
void FDTFluxCoreSubsystemModule::ShutdownModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FDTFluxCoreSubsystemModule, DTFluxCoreSubsystem)
|
||||
108
Source/DTFluxCoreSubsystem/Public/DTFluxCoreSubsystem.h
Normal file
108
Source/DTFluxCoreSubsystem/Public/DTFluxCoreSubsystem.h
Normal file
@ -0,0 +1,108 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Subsystems/EngineSubsystem.h"
|
||||
#include "Types/Enum/DTfluxCoreEnum.h"
|
||||
#include "Types/Struct/DTFluxRaceDataStructs.h"
|
||||
#include "Types/Struct/DTFluxTeamListStruct.h"
|
||||
#include "Types/Struct/DTFluxRankingStructs.h"
|
||||
#include "DTFluxCoreSubsystem.generated.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class UFDTFluxNetworkSubsystem;
|
||||
/** Forward Decl */
|
||||
class UDTFluxModelAsset;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class DTFLUXCORESUBSYSTEM_API UDTFluxCoreSubsystem : public UEngineSubsystem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// TSharedPtr<FDTFluxParser> Parser;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSplitRankings, FDateTime, ReceivedAt, TArray<FDTFluxSplitRanking>, SplitRankings);
|
||||
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
|
||||
FOnSplitRankings OnSplitRankings;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnStageRankings, FDateTime, ReceivedAt, TArray<FDTFluxStageRanking>, StageRankings);
|
||||
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
|
||||
FOnStageRankings OnStageRankings;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnContestRankings, FDateTime, ReceivedAt, TArray<FDTFluxContestRanking>, ContestRankings);
|
||||
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
|
||||
FOnContestRankings OnContestRankings;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTeamList, FDateTime, ReceivedAt, TArray<FDTFluxParticipant>, TeamList);
|
||||
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
|
||||
FOnTeamList OnTeamList;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTeamUpdate, FDateTime, ReceivedAt, FDTFluxParticipant, TeamUpdatedList);
|
||||
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
|
||||
FOnTeamUpdate OnTeamUpdate;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTeamStatusUpdate, FDateTime, ReceivedAt, FDTFluxParticipant, TeamUpdated);
|
||||
UPROPERTY(BlueprintAssignable, Category="DTFlux|Core Subsystem")
|
||||
FOnTeamStatusUpdate OnTeamStatusUpdate;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void SendTeamListRequest();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void SendRaceDataRequest();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void SendContestRankingRequest(int InContestId);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void SendStageRankingRequest(int InContestId, int InStageId, bool bShouldIncludeSplitRanking = true);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void RequestAllStageRankingOfContest(int InContestId, int InStageId, bool bShouldIncludeSplitRanking = true);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void SendSplitRankingRequest(int InContestId, int InStageId, int InSplitId);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void RequestAllSplitRankingOfContest(int InContestId, int InStageId);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void RequestAllSplitRankingOfStage(int InContestId, int InStageId, int InSplitId);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void RefreshStorage();
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
// ~Subsystem Interface
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
virtual void Deinitialize() override;
|
||||
// ~Subsystem Interface
|
||||
private:
|
||||
UFDTFluxNetworkSubsystem* NetworkSubsystem = nullptr;
|
||||
|
||||
UFUNCTION()
|
||||
void ParseRaceData(const FDTFluxRaceData& RaceDataDefinition);
|
||||
UFUNCTION()
|
||||
void ParseTeamList(const FDTFluxTeamListDefinition& TeamListDefinition);
|
||||
UFUNCTION()
|
||||
void OnDataReceived();
|
||||
UFUNCTION()
|
||||
void SendRequest(const FString& Message);
|
||||
UFUNCTION()
|
||||
void RegisterDelegates();
|
||||
|
||||
UPROPERTY()
|
||||
UDTFluxModelAsset* DataStorage = nullptr;
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
DTFLUXCORESUBSYSTEM_API DECLARE_LOG_CATEGORY_EXTERN(logDTFluxCoreSubsystem, All, All);
|
||||
|
||||
class DTFLUXCORESUBSYSTEM_API FDTFluxCoreSubsystemModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
Reference in New Issue
Block a user