Optimize code to unreal style

This commit is contained in:
martinluckyrobots
2025-04-07 11:32:45 +08:00
parent 5d8e225db5
commit 4d4026d9ad
19 changed files with 306 additions and 315 deletions

View File

@ -14,7 +14,6 @@ ALuckyRobotsGameState::ALuckyRobotsGameState()
void ALuckyRobotsGameState::BeginPlay()
{
Super::BeginPlay();
if (SocketIOClientComponent)
{
SocketIOClientComponent->Connect(L"http://localhost:3000/");
@ -23,33 +22,25 @@ void ALuckyRobotsGameState::BeginPlay()
void ALuckyRobotsGameState::DoSendMessage(FString SendValue)
{
if (SocketIOClientComponent)
if (SocketIOClientComponent && SocketIOClientComponent->bIsConnected)
{
if (SocketIOClientComponent->bIsConnected)
{
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
SocketIOClientComponent->Emit("message", SIOJsonValue);
}
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
SocketIOClientComponent->Emit(TEXT("message"), SIOJsonValue);
}
}
void ALuckyRobotsGameState::DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection)
{
if (SocketIOClientComponent)
if (SocketIOClientComponent && SocketIOClientComponent->bIsConnected)
{
if (SocketIOClientComponent->bIsConnected)
{
SocketIOClientComponent->BindEventToGenericEvent("response");
}
SocketIOClientComponent->BindEventToGenericEvent(TEXT("response"));
}
}
void ALuckyRobotsGameState::DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData)
{
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this);
if (LuckyRobotsGameInstance)
if (ULuckyRobotsGameInstance* GameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this))
{
LuckyRobotsGameInstance->DoGetDispatch(EventName, EventData);
GameInstance->DoGetDispatch(EventName, EventData);
}
}
}