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

@ -8,7 +8,6 @@
void ALuckyRobotsGameMode::BeginPlay()
{
Super::BeginPlay();
ULuckyRobotsFunctionLibrary::UpdateQualitySettings(this);
}
@ -17,24 +16,21 @@ UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AC
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
ERobotsName CurrentRobot = ERobotsName::None;
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
if (LuckyRobotsGameInstance)
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
{
CurrentRobot = LuckyRobotsGameInstance->CurrentSelectRobot;
CurrentRobot = GameInstance->CurrentSelectRobot;
}
if (CurrentRobot != ERobotsName::None)
{
TArray<FRobotData> ActiveRobotDataList = ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(this);
for (auto ActiveRobotData : ActiveRobotDataList)
for (const FRobotData& RobotData : ActiveRobotDataList)
{
if (ActiveRobotData.Name == CurrentRobot)
if (RobotData.Name == CurrentRobot)
{
RobotClass = ActiveRobotData.RobotClass;
RobotClass = RobotData.RobotClass;
break;
}
}
}
return RobotClass;
}

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);
}
}
}