Optimizing gameinstance

This commit is contained in:
martinluckyrobots 2025-04-09 15:18:16 +08:00
parent b3b61b6415
commit 17dc39a612
12 changed files with 76 additions and 4 deletions

View File

@ -9,6 +9,8 @@
#include "GameFramework/GameUserSettings.h" #include "GameFramework/GameUserSettings.h"
#include "Kismet/KismetMathLibrary.h" #include "Kismet/KismetMathLibrary.h"
#include "FunctionLibraries/LuckyRobotsFunctionLibrary.h" #include "FunctionLibraries/LuckyRobotsFunctionLibrary.h"
#include "VaRestSubsystem.h"
#include "Subsystems/SubsystemBlueprintLibrary.h"
void ULuckyRobotsGameInstance::DoSendMessage(const FString& SendValue) void ULuckyRobotsGameInstance::DoSendMessage(const FString& SendValue)
{ {
@ -284,6 +286,64 @@ TArray<FSelectableItemData> ULuckyRobotsGameInstance::GetSelectableItemList(EIte
return SelectableItemList; return SelectableItemList;
} }
void ULuckyRobotsGameInstance::GetMessageParse(FString Json)
{
auto VaRestSubsystem = CastChecked<UVaRestSubsystem>(USubsystemBlueprintLibrary::GetEngineSubsystem(UVaRestSubsystem::StaticClass()), ECastCheckedType::NullChecked);
if (VaRestSubsystem)
{
UVaRestJsonObject* VaRestJsonObject = VaRestSubsystem->ConstructVaRestJsonObject();
if (VaRestJsonObject)
{
if (VaRestJsonObject->DecodeJson(Json, true))
{
TArray<UVaRestJsonValue*> VaRestJsonValueList = VaRestJsonObject->GetArrayField("LuckyCode");
if (VaRestJsonValueList.Num() > 0)
{
LuckyCodeList.Empty();
for (auto VaRestJsonValue : VaRestJsonValueList)
{
if (VaRestJsonValue)
{
UVaRestJsonObject* TempObject = VaRestJsonValue->AsObject();
if (TempObject)
{
FLuckyCode TempLuckyCode;
TempLuckyCode.ID = FCString::Atoi(*(TempObject->GetStringField("ID")));
TempLuckyCode.Code = TempObject->GetStringField("code");
TempLuckyCode.Time = FCString::Atof(*(TempObject->GetStringField("time")));
TempLuckyCode.bCallback = (TempObject->GetStringField("callback") == "on");
LuckyCodeList.Add(TempLuckyCode);
}
}
}
}
else
{
UVaRestJsonValue* VaRestJsonValue = VaRestJsonObject->GetField("LuckyCapture");
if (VaRestJsonValue)
{
UVaRestJsonObject* TempObject = VaRestJsonValue->AsObject();
if (TempObject)
{
bIsCapture = (TempObject->GetStringField("capture") == "on");
bIsCaptureHand = (TempObject->GetStringField("is_capture_hand") == "on");
bIsCaptureHead = (TempObject->GetStringField("is_capture_head") == "on");
bScenarioCapture = (TempObject->GetStringField("scenario_capture") == "on");
TargetPosition = FTransform();
SetCurrentFileName(TempObject->GetStringField("file_name"));
SetCurrentFolderName(TempObject->GetStringField("folder_name"));
SetCurrentCaptureNumber(FCString::Atoi(*TempObject->GetStringField("capture_name")));
SetCurrentIsInfiniteCapture(TempObject->GetStringField("infinite_capture") == "on");
SetCurrentWritesPerSec(FCString::Atoi(*TempObject->GetStringField("per_second")));
SetCurrentIsRandomPeople(TempObject->GetStringField("random_people") == "on");
}
}
}
}
}
}
}
void ULuckyRobotsGameInstance::SetCurrentFolderName(const FString& FolderName) void ULuckyRobotsGameInstance::SetCurrentFolderName(const FString& FolderName)
{ {
CurrentCaptureSettingsData.FolderName = FText::FromString(FolderName); CurrentCaptureSettingsData.FolderName = FText::FromString(FolderName);

View File

@ -5,6 +5,7 @@
#include "SocketIOClientComponent.h" #include "SocketIOClientComponent.h"
#include "FunctionLibraries/LuckyRobotsFunctionLibrary.h" #include "FunctionLibraries/LuckyRobotsFunctionLibrary.h"
#include "Core/LuckyRobotsGameInstance.h" #include "Core/LuckyRobotsGameInstance.h"
#include "SIOJLibrary.h"
ALuckyRobotsGameState::ALuckyRobotsGameState() ALuckyRobotsGameState::ALuckyRobotsGameState()
{ {
@ -41,6 +42,7 @@ void ALuckyRobotsGameState::DoSocketOnGenericEvent(FString EventName, USIOJsonVa
{ {
if (ULuckyRobotsGameInstance* GameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this)) if (ULuckyRobotsGameInstance* GameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this))
{ {
GameInstance->DoGetDispatch(EventName, EventData); GameInstance->OnMessageDispatched.Broadcast(EventName);
GameInstance->GetMessageParse(USIOJLibrary::Conv_SIOJsonValueToString(EventData));
} }
} }

View File

@ -7,6 +7,9 @@
#include "SharedDef.h" #include "SharedDef.h"
#include "LuckyRobotsGameInstance.generated.h" #include "LuckyRobotsGameInstance.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMessageDispatched, const FString&, Message);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnRandomMeshesUpdated);
class USIOJsonValue; class USIOJsonValue;
class UGameUserWidget; class UGameUserWidget;
/** /**
@ -128,6 +131,13 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FLuckyCode> LuckyCodeList; TArray<FLuckyCode> LuckyCodeList;
public:
UPROPERTY(BlueprintCallable, BlueprintAssignable, Category = "Event")
FOnMessageDispatched OnMessageDispatched;
UPROPERTY(BlueprintCallable, BlueprintAssignable, Category = "Event")
FOnRandomMeshesUpdated OnRandomMeshesUpdated;
public: public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void DoSendMessage(const FString& SendValue); void DoSendMessage(const FString& SendValue);
@ -190,6 +200,9 @@ public:
UFUNCTION(BlueprintPure, Category = "Selectable Items") UFUNCTION(BlueprintPure, Category = "Selectable Items")
TArray<FSelectableItemData> GetSelectableItemList(EItemCategory ItemCategory); TArray<FSelectableItemData> GetSelectableItemList(EItemCategory ItemCategory);
UFUNCTION(BlueprintCallable)
void GetMessageParse(FString Json);
public: public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void SetCurrentFolderName(const FString& FolderName); void SetCurrentFolderName(const FString& FolderName);
@ -295,7 +308,4 @@ public:
UFUNCTION(BlueprintPure) UFUNCTION(BlueprintPure)
int32 GetWidgetTotalHit() const; int32 GetWidgetTotalHit() const;
public:
UFUNCTION(BlueprintImplementableEvent)
void DoGetDispatch(const FString& EventName, USIOJsonValue* EventData);
}; };