Merge pull request 'martin' (#8) from martin into main

Reviewed-on: #8
This commit is contained in:
martinluckyrobots 2025-04-01 04:09:11 +00:00
commit 9c168f9842
25 changed files with 359 additions and 87 deletions

Binary file not shown.

Binary file not shown.

View File

@ -17,8 +17,9 @@ public class Luckyrobots : ModuleRules
"LuckyMujoco",
"LuckyTextWrite",
"SocketIOClient",
"VaRest"
});
"VaRest",
"SIOJson"
});
PrivateDependencyModuleNames.AddRange(new string[] { });

View File

@ -2,4 +2,11 @@
#include "LobbyGameMode.h"
#include "LuckyRobotsFunctionLibrary.h"
void ALobbyGameMode::BeginPlay()
{
Super::BeginPlay();
ULuckyRobotsFunctionLibrary::UpdateQualitySettings(this);
}

View File

@ -0,0 +1,79 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "LuckyRobotsFunctionLibrary.h"
#include "LuckyRobotsGameInstance.h"
#include "GameFramework/GameUserSettings.h"
ULuckyRobotsGameInstance* ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(const UObject* WorldContextObject)
{
return Cast<ULuckyRobotsGameInstance>(WorldContextObject->GetWorld()->GetGameInstance());
}
TArray<FRobotData> ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(const UObject* WorldContextObject)
{
TArray<FRobotData> RobotDataList;
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject);
if (LuckyRobotsGameInstance)
{
if (LuckyRobotsGameInstance->RobotDataDataTable)
{
FString ContextString;
TArray<FName> RowNames = LuckyRobotsGameInstance->RobotDataDataTable->GetRowNames();
for (auto RowString : RowNames)
{
FRobotData* pRow = LuckyRobotsGameInstance->RobotDataDataTable->FindRow<FRobotData>(FName(RowString), ContextString);
if (pRow)
{
if (pRow->bActive)
{
RobotDataList.Add(*pRow);
}
}
}
}
}
return RobotDataList;
}
TArray<FLevelData> ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(const UObject* WorldContextObject)
{
TArray<FLevelData> LevelDataList;
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject);
if (LuckyRobotsGameInstance)
{
if (LuckyRobotsGameInstance->LevelDataTable)
{
FString ContextString;
TArray<FName> RowNames = LuckyRobotsGameInstance->LevelDataTable->GetRowNames();
for (auto RowString : RowNames)
{
FLevelData* pRow = LuckyRobotsGameInstance->LevelDataTable->FindRow<FLevelData>(FName(RowString), ContextString);
if (pRow)
{
if (pRow->bActive)
{
LevelDataList.Add(*pRow);
}
}
}
}
}
return LevelDataList;
}
void ULuckyRobotsFunctionLibrary::UpdateQualitySettings(const UObject* WorldContextObject)
{
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject);
if (LuckyRobotsGameInstance)
{
// Load game user settings and apply
UGameUserSettings* GameUserSettings = GEngine->GetGameUserSettings();
if (GameUserSettings)
{
GameUserSettings->SetOverallScalabilityLevel(int(LuckyRobotsGameInstance->CurrentSelectQuality));
GameUserSettings->SaveSettings();
GameUserSettings->ApplySettings(true);
}
}
}

View File

@ -2,4 +2,39 @@
#include "LuckyRobotsGameMode.h"
#include "LuckyRobotsGameInstance.h"
#include "LuckyRobotsFunctionLibrary.h"
void ALuckyRobotsGameMode::BeginPlay()
{
Super::BeginPlay();
ULuckyRobotsFunctionLibrary::UpdateQualitySettings(this);
}
UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AController* InController)
{
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
ERobotsName CurrentRobot = ERobotsName::None;
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
if (LuckyRobotsGameInstance)
{
CurrentRobot = LuckyRobotsGameInstance->CurrentSelectRobot;
}
if (CurrentRobot != ERobotsName::None)
{
TArray<FRobotData> ActiveRobotDataList = ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(this);
for (auto ActiveRobotData : ActiveRobotDataList)
{
if (ActiveRobotData.Name == CurrentRobot)
{
RobotClass = ActiveRobotData.RobotClass;
break;
}
}
}
return RobotClass;
}

View File

@ -2,4 +2,54 @@
#include "LuckyRobotsGameState.h"
#include "SocketIOClientComponent.h"
#include "LuckyRobotsFunctionLibrary.h"
#include "LuckyRobotsGameInstance.h"
ALuckyRobotsGameState::ALuckyRobotsGameState()
{
SocketIOClientComponent = CreateDefaultSubobject<USocketIOClientComponent>(TEXT("SocketIOClientComponent"));
}
void ALuckyRobotsGameState::BeginPlay()
{
Super::BeginPlay();
if (SocketIOClientComponent)
{
SocketIOClientComponent->Connect(L"http://localhost:3000/");
}
}
void ALuckyRobotsGameState::DoSendMessage(FString SendValue)
{
if (SocketIOClientComponent)
{
if (SocketIOClientComponent->bIsConnected)
{
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
SocketIOClientComponent->Emit("message", SIOJsonValue);
}
}
}
void ALuckyRobotsGameState::DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection)
{
if (SocketIOClientComponent)
{
if (SocketIOClientComponent->bIsConnected)
{
SocketIOClientComponent->BindEventToGenericEvent("response");
}
}
}
void ALuckyRobotsGameState::DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData)
{
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this);
if (LuckyRobotsGameInstance)
{
LuckyRobotsGameInstance->DoGetDispatch(EventName, EventData);
}
}

View File

@ -4,6 +4,7 @@
#include "MainScreenUserWidget.h"
#include "Engine/DataTable.h"
#include "LuckyRobotsGameInstance.h"
#include "LuckyRobotsFunctionLibrary.h"
void UMainScreenUserWidget::NativeConstruct()
{
@ -20,38 +21,13 @@ void UMainScreenUserWidget::InitData()
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
if (LuckyRobotsGameInstance)
{
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
for (int32 i = 0; i < QualityEnum->NumEnums() - 1; i++)
{
if (EQualityEnum(QualityEnum->GetValueByIndex(i)) == LuckyRobotsGameInstance->CurrentSelectQuality)
{
iCurrentSelectRobot = i;
break;
}
}
iCurrentSelectQuality = int(LuckyRobotsGameInstance->CurrentSelectQuality);
}
}
void UMainScreenUserWidget::InitRobotData()
{
if (RobotDataDataTable)
{
RobotDataList.Empty();
FString ContextString;
TArray<FName> RowNames = RobotDataDataTable->GetRowNames();
for (auto RowString : RowNames)
{
FRobotData* pRow = RobotDataDataTable->FindRow<FRobotData>(FName(RowString), ContextString);
if (pRow)
{
if (pRow->bActive)
{
RobotDataList.Add(*pRow);
}
}
}
}
RobotDataList = ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(this);
iCurrentSelectRobot = 0;
UpdateSelectRobot();
@ -59,49 +35,19 @@ void UMainScreenUserWidget::InitRobotData()
void UMainScreenUserWidget::InitLevelData()
{
LevelDataList = ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(this);
FRobotData CurrentRobotData = GetCurrentRobotData();
if (CurrentRobotData.Name != ERobotsName::None)
{
if (LevelDataTable)
{
LevelDataList.Empty();
TArray<FLevelData> ActiveLevelDataList = LevelDataList;
FString ContextString;
TArray<FName> RowNames = LevelDataTable->GetRowNames();
for (auto RowString : RowNames)
{
FLevelData* pRow = LevelDataTable->FindRow<FLevelData>(FName(RowString), ContextString);
if (pRow)
{
if (pRow->bActive)
{
if (pRow->RobotTypeList.Find(CurrentRobotData.RobotType) >= 0)
{
LevelDataList.Add(*pRow);
}
}
}
}
}
}
else
{
if (LevelDataTable)
LevelDataList.Empty();
for (auto ActiveLevelData : ActiveLevelDataList)
{
LevelDataList.Empty();
FString ContextString;
TArray<FName> RowNames = LevelDataTable->GetRowNames();
for (auto RowString : RowNames)
if (ActiveLevelData.RobotTypeList.Find(CurrentRobotData.RobotType) >= 0)
{
FLevelData* pRow = LevelDataTable->FindRow<FLevelData>(FName(RowString), ContextString);
if (pRow)
{
if (pRow->bActive)
{
LevelDataList.Add(*pRow);
}
}
LevelDataList.Add(ActiveLevelData);
}
}
}
@ -158,7 +104,7 @@ void UMainScreenUserWidget::SelectNextQuality()
{
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
int QualityEnumNum = QualityEnum->NumEnums() - 1;
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality + 1, 0, QualityEnumNum - 1);
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality - 1, 0, QualityEnumNum - 1);
UpdateSelectQuality();
}
@ -167,7 +113,7 @@ void UMainScreenUserWidget::SelectPreviousQuality()
{
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
int QualityEnumNum = QualityEnum->NumEnums() - 1;
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality - 1, 0, QualityEnumNum - 1);
iCurrentSelectQuality = FMath::Clamp(iCurrentSelectQuality + 1, 0, QualityEnumNum - 1);
UpdateSelectQuality();
}
@ -197,8 +143,7 @@ void UMainScreenUserWidget::UpdateSelectQuality()
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
if (LuckyRobotsGameInstance)
{
UEnum* QualityEnum = StaticEnum<EQualityEnum>();
LuckyRobotsGameInstance->CurrentSelectQuality = EQualityEnum(QualityEnum->GetValueByIndex(iCurrentSelectQuality));
LuckyRobotsGameInstance->CurrentSelectQuality = static_cast<EQualityEnum>(iCurrentSelectQuality);
}
BPUpdateSelectQuality();
}

View File

@ -13,5 +13,7 @@ UCLASS()
class LUCKYROBOTS_API ALobbyGameMode : public AGameModeBase
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
};

View File

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "SharedDef.h"
#include "LuckyRobotsFunctionLibrary.generated.h"
class ULuckyRobotsGameInstance;
/**
*
*/
UCLASS()
class LUCKYROBOTS_API ULuckyRobotsFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
static ULuckyRobotsGameInstance* GetLuckyRobotsGameInstance(const UObject* WorldContextObject);
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
static TArray<FRobotData> GetActiveRobotDataList(const UObject* WorldContextObject);
UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
static TArray<FLevelData> GetActiveLevelDataList(const UObject* WorldContextObject);
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"))
static void UpdateQualitySettings(const UObject* WorldContextObject);
};

View File

@ -7,6 +7,7 @@
#include "SharedDef.h"
#include "LuckyRobotsGameInstance.generated.h"
class USIOJsonValue;
/**
*
*/
@ -15,13 +16,24 @@ class LUCKYROBOTS_API ULuckyRobotsGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
UDataTable* RobotDataDataTable;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
UDataTable* LevelDataTable;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ERobotsName CurrentSelectRobot;
ERobotsName CurrentSelectRobot = ERobotsName::None;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ELevelEnum CurrentSelectLevel;
ELevelEnum CurrentSelectLevel = ELevelEnum::None;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
EQualityEnum CurrentSelectQuality;
EQualityEnum CurrentSelectQuality = EQualityEnum::Epic;
public:
UFUNCTION(BlueprintImplementableEvent)
void DoGetDispatch(const FString& EventName, USIOJsonValue* EventData);
};

View File

@ -13,5 +13,9 @@ UCLASS()
class LUCKYROBOTS_API ALuckyRobotsGameMode : public AGameModeBase
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
virtual UClass* GetDefaultPawnClassForController_Implementation(AController* InController) override;
};

View File

@ -6,6 +6,8 @@
#include "GameFramework/GameStateBase.h"
#include "LuckyRobotsGameState.generated.h"
class USocketIOClientComponent;
class USIOJsonValue;
/**
*
*/
@ -13,5 +15,21 @@ UCLASS()
class LUCKYROBOTS_API ALuckyRobotsGameState : public AGameStateBase
{
GENERATED_BODY()
protected:
ALuckyRobotsGameState();
virtual void BeginPlay() override;
public:
UPROPERTY(Category = Character, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
USocketIOClientComponent* SocketIOClientComponent;
public:
UFUNCTION(BlueprintCallable)
void DoSendMessage(FString SendValue);
UFUNCTION(BlueprintCallable)
void DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection);
UFUNCTION(BlueprintCallable)
void DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData);
};

View File

@ -18,13 +18,6 @@ class LUCKYROBOTS_API UMainScreenUserWidget : public UUserWidget
protected:
virtual void NativeConstruct();
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
UDataTable* RobotDataDataTable;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Config")
UDataTable* LevelDataTable;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FRobotData> RobotDataList;

View File

@ -64,10 +64,18 @@ enum class ELevelEnum : uint8
UENUM(BlueprintType)
enum class EQualityEnum : uint8
{
Epic UMETA(DisplayName = "Epic"),
High UMETA(DisplayName = "High"),
Low UMETA(DisplayName = "Low"),
Middle UMETA(DisplayName = "Middle"),
Low UMETA(DisplayName = "Low")
High UMETA(DisplayName = "High"),
Epic UMETA(DisplayName = "Epic")
};
UENUM(BlueprintType)
enum class EGoalType : uint8
{
GrabAndPull UMETA(DisplayName = "Grab and Pull"),
GrabAndRotate UMETA(DisplayName = "Grab and Rotate"),
};
USTRUCT(BlueprintType)
@ -123,4 +131,92 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<ERobotsCategories> RobotTypeList;
};
};
USTRUCT(BlueprintType)
struct FGoalsTaskData : public FTableRowBase
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
EGoalType GoalType;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bIsStart;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FTransform TargetLocation;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
AActor* TargetActor;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bIsComplate;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector DropOffLocation;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString ObjectName;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bActive;
};
USTRUCT(BlueprintType)
struct FCaptureSettingsData : public FTableRowBase
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText FolderName;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText FileName;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText WritesPerSec;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool IsScenario;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FGoalsTaskData> TaskList;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bLight;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bMaterials;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bRobotPosition;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bPets;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText NumberOfPets;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bPeople;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText NumberOfPeople;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bObjects;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText NumberOfObjects;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<UStaticMeshComponent*> RandomMeshes;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bInfiniteCapture;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText NumberOfCaptures;
};