chore: upgrade ts2lua-unreal to v0.3.1 with lowercase lib/module.lua & lib/class.lua and commit framework refactor
This commit is contained in:
1 parent
783dccf53d
commit
3572f2da43
206 files changed
+14442
-13186
No files matched your search
@@ -0,0 +1,223 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "RunLuaFrameworkTestsCommandlet.h"
|
||||
#include "UnrealLuaDemoEditor.h"
|
||||
#include "Core/LuaGameInstance.h"
|
||||
#include "Async/TaskGraphInterfaces.h"
|
||||
#include "Containers/Ticker.h"
|
||||
#include "Engine/Engine.h"
|
||||
#include "Engine/World.h"
|
||||
#include "GameFramework/WorldSettings.h"
|
||||
#include "Tickable.h"
|
||||
#include "UObject/UObjectGlobals.h"
|
||||
#include "UnLua.h"
|
||||
#include "UnLuaModule.h"
|
||||
#include "LuaEnv.h"
|
||||
#include "lua.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
UWorld* GFrameworkTestWorld = nullptr;
|
||||
|
||||
int LuaFrameworkTestTick(lua_State* L)
|
||||
{
|
||||
const float DeltaSeconds = lua_gettop(L) >= 1 ? static_cast<float>(luaL_checknumber(L, 1)) : 0.016f;
|
||||
++GFrameCounter;
|
||||
if (IsAsyncLoading())
|
||||
{
|
||||
FPlatformProcess::Sleep(0.005f);
|
||||
}
|
||||
FTaskGraphInterface::Get().ProcessThreadUntilIdle(ENamedThreads::GameThread);
|
||||
ProcessAsyncLoading(false, false, 0.0f);
|
||||
FTSTicker::GetCoreTicker().Tick(DeltaSeconds);
|
||||
FTickableGameObject::TickObjects(nullptr, LEVELTICK_All, false, DeltaSeconds);
|
||||
if (GFrameworkTestWorld && IsValid(GFrameworkTestWorld))
|
||||
{
|
||||
GFrameworkTestWorld->Tick(LEVELTICK_All, DeltaSeconds);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaFrameworkTestCollectGarbage(lua_State* L)
|
||||
{
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
CollectGarbage(GARBAGE_COLLECTION_KEEPFLAGS, true);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
URunLuaFrameworkTestsCommandlet::URunLuaFrameworkTestsCommandlet()
|
||||
{
|
||||
IsClient = true;
|
||||
IsEditor = true;
|
||||
IsServer = false;
|
||||
LogToConsole = true;
|
||||
ShowErrorCount = true;
|
||||
}
|
||||
|
||||
int32 URunLuaFrameworkTestsCommandlet::Main(const FString& Params)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[RunLuaFrameworkTests] Starting UE 5.8 + UnLua framework test runner..."));
|
||||
|
||||
IUnLuaModule& UnLuaModule = IUnLuaModule::Get();
|
||||
const bool bWasActive = UnLuaModule.IsActive();
|
||||
if (!bWasActive)
|
||||
{
|
||||
UnLuaModule.SetActive(true);
|
||||
}
|
||||
|
||||
UWorld* TestWorld = UWorld::CreateWorld(EWorldType::Game, false, TEXT("LuaFrameworkTestWorld"));
|
||||
if (!TestWorld)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[RunLuaFrameworkTests] Failed to create UWorld."));
|
||||
if (!bWasActive)
|
||||
{
|
||||
UnLuaModule.SetActive(false);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ULuaGameInstance* TestGameInstance = NewObject<ULuaGameInstance>(GEngine);
|
||||
TestGameInstance->AddToRoot();
|
||||
|
||||
FWorldContext& WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game);
|
||||
WorldContext.OwningGameInstance = TestGameInstance;
|
||||
WorldContext.SetCurrentWorld(TestWorld);
|
||||
TestWorld->SetGameInstance(TestGameInstance);
|
||||
|
||||
TestGameInstance->Init();
|
||||
|
||||
TestWorld->InitializeActorsForPlay(FURL());
|
||||
if (AWorldSettings* WorldSettings = TestWorld->GetWorldSettings())
|
||||
{
|
||||
WorldSettings->NotifyBeginPlay();
|
||||
WorldSettings->NotifyMatchStarted();
|
||||
}
|
||||
TestWorld->BeginPlay();
|
||||
|
||||
GFrameworkTestWorld = TestWorld;
|
||||
|
||||
int32 ExitCode = 1;
|
||||
UnLua::FLuaEnv* Env = UnLuaModule.GetEnv(TestGameInstance);
|
||||
if (!Env)
|
||||
{
|
||||
Env = UnLuaModule.GetEnv(TestWorld);
|
||||
}
|
||||
if (!Env)
|
||||
{
|
||||
TMap<lua_State*, UnLua::FLuaEnv*>& AllEnvs = UnLua::FLuaEnv::GetAll();
|
||||
for (const TPair<lua_State*, UnLua::FLuaEnv*>& Pair : AllEnvs)
|
||||
{
|
||||
if (Pair.Value)
|
||||
{
|
||||
Env = Pair.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Env)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[RunLuaFrameworkTests] Failed to obtain UnLua FLuaEnv."));
|
||||
}
|
||||
else if (lua_State* L = Env->GetMainState())
|
||||
{
|
||||
UnLua::PushUObject(L, TestGameInstance);
|
||||
lua_setglobal(L, "__UE_TEST_GAME_INSTANCE");
|
||||
|
||||
UnLua::PushUObject(L, TestWorld);
|
||||
lua_setglobal(L, "__UE_TEST_WORLD");
|
||||
|
||||
lua_pushcfunction(L, &LuaFrameworkTestTick);
|
||||
lua_setglobal(L, "__UE_TEST_TICK");
|
||||
|
||||
lua_pushcfunction(L, &LuaFrameworkTestCollectGarbage);
|
||||
lua_setglobal(L, "__UE_TEST_GC");
|
||||
|
||||
const FString RunChunk = TEXT(
|
||||
"local suite = __MODULE__.Import('tests.ue.run_ue_tests')\n"
|
||||
"local runner = __MODULE__.Import('tests.harness.test_runner')\n"
|
||||
"local summary = suite.RunAllUETests(_G.__UE_TEST_GAME_INSTANCE, _G.__UE_TEST_WORLD)\n"
|
||||
"_G.__UE_TEST_TOTAL = summary.total or 0\n"
|
||||
"_G.__UE_TEST_PASSED = summary.passed or 0\n"
|
||||
"_G.__UE_TEST_FAILED = summary.failed or 0\n"
|
||||
"_G.__UE_TEST_REPORT = runner.FormatReport(summary)\n"
|
||||
);
|
||||
|
||||
const bool bExecOk = Env->DoString(RunChunk, TEXT("RunLuaFrameworkTestsCommandlet"));
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_REPORT");
|
||||
const char* ReportUtf8 = lua_tostring(L, -1);
|
||||
const FString ReportText = ReportUtf8 ? UTF8_TO_TCHAR(ReportUtf8) : FString();
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (!ReportText.IsEmpty())
|
||||
{
|
||||
TArray<FString> Lines;
|
||||
ReportText.ParseIntoArrayLines(Lines, false);
|
||||
for (const FString& Line : Lines)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("%s"), *Line);
|
||||
}
|
||||
}
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_TOTAL");
|
||||
const int32 Total = static_cast<int32>(lua_tointeger(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_PASSED");
|
||||
const int32 Passed = static_cast<int32>(lua_tointeger(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_FAILED");
|
||||
const int32 Failed = static_cast<int32>(lua_tointeger(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_GAME_INSTANCE");
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_WORLD");
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_TICK");
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_GC");
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_REPORT");
|
||||
|
||||
if (!bExecOk)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[RunLuaFrameworkTests] Lua execution error in tests.ue.run_ue_tests."));
|
||||
ExitCode = 1;
|
||||
}
|
||||
else if (Total <= 0 || Failed > 0)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error,
|
||||
TEXT("[RunLuaFrameworkTests] FAILED (Total=%d, Passed=%d, Failed=%d)."),
|
||||
Total, Passed, Failed);
|
||||
ExitCode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display,
|
||||
TEXT("[RunLuaFrameworkTests] PASSED (Total=%d, Passed=%d, Failed=%d)."),
|
||||
Total, Passed, Failed);
|
||||
ExitCode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GFrameworkTestWorld = nullptr;
|
||||
|
||||
TestWorld->EndPlay(EEndPlayReason::Quit);
|
||||
TestGameInstance->Shutdown();
|
||||
TestGameInstance->RemoveFromRoot();
|
||||
|
||||
GEngine->DestroyWorldContext(TestWorld);
|
||||
TestWorld->DestroyWorld(false);
|
||||
|
||||
if (!bWasActive)
|
||||
{
|
||||
UnLuaModule.SetActive(false);
|
||||
}
|
||||
|
||||
return ExitCode;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Commandlets/Commandlet.h"
|
||||
#include "RunLuaFrameworkTestsCommandlet.generated.h"
|
||||
|
||||
/**
|
||||
* Headless UE 5.8 + UnLua framework test runner commandlet.
|
||||
* Boots a real ULuaGameInstance + UWorld + UnLua FLuaEnv and executes `tests.ue.run_ue_tests`.
|
||||
*
|
||||
* Usage:
|
||||
* UnrealEditor-Cmd <Project.uproject> -run=RunLuaFrameworkTests -unattended -nop4 -nosplash -NullRHI
|
||||
* (Optional: pass -UseLuaBundle to run tests directly from /Game/Generated/DA_LuaBundle)
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMOEDITOR_API URunLuaFrameworkTestsCommandlet : public UCommandlet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
URunLuaFrameworkTestsCommandlet();
|
||||
|
||||
virtual int32 Main(const FString& Params) override;
|
||||
};
|
||||
@@ -1,172 +0,0 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "RunLuaTestsCommandlet.h"
|
||||
#include "UnrealLuaDemoEditor.h"
|
||||
#include "Engine/Engine.h"
|
||||
#include "Engine/World.h"
|
||||
#include "GameFramework/WorldSettings.h"
|
||||
#include "UnLua.h"
|
||||
#include "UnLuaModule.h"
|
||||
#include "LuaEnv.h"
|
||||
#include "lua.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
UWorld* GCurrentLuaTestWorld = nullptr;
|
||||
|
||||
int LuaTestWorldTick(lua_State* L)
|
||||
{
|
||||
const float DeltaSeconds = lua_gettop(L) >= 1 ? static_cast<float>(luaL_checknumber(L, 1)) : 0.016f;
|
||||
if (GCurrentLuaTestWorld && IsValid(GCurrentLuaTestWorld))
|
||||
{
|
||||
// Advance GFrameCounter so FTimerManager::HasBeenTickedThisFrame() treats each call as a new engine frame.
|
||||
++GFrameCounter;
|
||||
GCurrentLuaTestWorld->Tick(LEVELTICK_All, DeltaSeconds);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
URunLuaTestsCommandlet::URunLuaTestsCommandlet()
|
||||
{
|
||||
IsClient = true;
|
||||
IsEditor = true;
|
||||
IsServer = false;
|
||||
LogToConsole = true;
|
||||
ShowErrorCount = true;
|
||||
}
|
||||
|
||||
int32 URunLuaTestsCommandlet::Main(const FString& Params)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[RunLuaTestsCommandlet] Starting real UE + UnLua test runner..."));
|
||||
|
||||
IUnLuaModule& UnLuaModule = IUnLuaModule::Get();
|
||||
const bool bWasActive = UnLuaModule.IsActive();
|
||||
if (!bWasActive)
|
||||
{
|
||||
UnLuaModule.SetActive(true);
|
||||
}
|
||||
|
||||
UWorld* TestWorld = UWorld::CreateWorld(EWorldType::Game, false, TEXT("LuaTestWorld"));
|
||||
if (!TestWorld)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[RunLuaTestsCommandlet] Failed to create UWorld."));
|
||||
if (!bWasActive)
|
||||
{
|
||||
UnLuaModule.SetActive(false);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
FWorldContext& WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game);
|
||||
WorldContext.SetCurrentWorld(TestWorld);
|
||||
|
||||
TestWorld->InitializeActorsForPlay(FURL());
|
||||
if (AWorldSettings* WorldSettings = TestWorld->GetWorldSettings())
|
||||
{
|
||||
WorldSettings->NotifyBeginPlay();
|
||||
WorldSettings->NotifyMatchStarted();
|
||||
}
|
||||
TestWorld->BeginPlay();
|
||||
|
||||
GCurrentLuaTestWorld = TestWorld;
|
||||
|
||||
int32 ExitCode = 1;
|
||||
UnLua::FLuaEnv* Env = UnLuaModule.GetEnv(TestWorld);
|
||||
if (!Env)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[RunLuaTestsCommandlet] Failed to obtain UnLua FLuaEnv."));
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_State* L = Env->GetMainState();
|
||||
if (L)
|
||||
{
|
||||
UnLua::PushUObject(L, TestWorld);
|
||||
lua_setglobal(L, "__UE_TEST_WORLD");
|
||||
|
||||
lua_pushcfunction(L, &LuaTestWorldTick);
|
||||
lua_setglobal(L, "__UE_TEST_TICK");
|
||||
|
||||
const FString RunChunk = TEXT(
|
||||
"local suite = __MODULE__.Import('Tests.UE.UERuntimeSuite')\n"
|
||||
"local runner = __MODULE__.Import('Tests.Harness.TestRunner')\n"
|
||||
"local summary = suite.RunAllInUE(_G.__UE_TEST_WORLD)\n"
|
||||
"_G.__UE_TEST_TOTAL = summary.total or 0\n"
|
||||
"_G.__UE_TEST_PASSED = summary.passed or 0\n"
|
||||
"_G.__UE_TEST_FAILED = summary.failed or 0\n"
|
||||
"_G.__UE_TEST_REPORT = runner.FormatReport(summary)\n"
|
||||
);
|
||||
|
||||
const bool bExecOk = Env->DoString(RunChunk, TEXT("RunLuaTestsCommandlet"));
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_REPORT");
|
||||
const char* ReportUtf8 = lua_tostring(L, -1);
|
||||
const FString ReportText = ReportUtf8 ? UTF8_TO_TCHAR(ReportUtf8) : FString();
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (!ReportText.IsEmpty())
|
||||
{
|
||||
TArray<FString> Lines;
|
||||
ReportText.ParseIntoArrayLines(Lines, false);
|
||||
for (const FString& Line : Lines)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("%s"), *Line);
|
||||
}
|
||||
}
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_TOTAL");
|
||||
const int32 Total = static_cast<int32>(lua_tointeger(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_PASSED");
|
||||
const int32 Passed = static_cast<int32>(lua_tointeger(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getglobal(L, "__UE_TEST_FAILED");
|
||||
const int32 Failed = static_cast<int32>(lua_tointeger(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Clear test globals before teardown
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_WORLD");
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_TICK");
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, "__UE_TEST_REPORT");
|
||||
|
||||
if (!bExecOk)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[RunLuaTestsCommandlet] Lua execution error while running Tests.UE.UERuntimeSuite."));
|
||||
ExitCode = 1;
|
||||
}
|
||||
else if (Total <= 0 || Failed > 0)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error,
|
||||
TEXT("[RunLuaTestsCommandlet] UE Lua tests FAILED (Total=%d, Passed=%d, Failed=%d)."),
|
||||
Total, Passed, Failed);
|
||||
ExitCode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display,
|
||||
TEXT("[RunLuaTestsCommandlet] All UE Lua tests PASSED (Total=%d, Passed=%d, Failed=%d)."),
|
||||
Total, Passed, Failed);
|
||||
ExitCode = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GCurrentLuaTestWorld = nullptr;
|
||||
|
||||
TestWorld->EndPlay(EEndPlayReason::Quit);
|
||||
GEngine->DestroyWorldContext(TestWorld);
|
||||
TestWorld->DestroyWorld(false);
|
||||
|
||||
if (!bWasActive)
|
||||
{
|
||||
UnLuaModule.SetActive(false);
|
||||
}
|
||||
|
||||
return ExitCode;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Commandlets/Commandlet.h"
|
||||
#include "RunLuaTestsCommandlet.generated.h"
|
||||
|
||||
/**
|
||||
* Headless commandlet that boots a real UWorld + UnLua 2.3.6 Lua 5.4 runtime
|
||||
* and executes the compiled TypeScript -> UnLua test suite (`Tests.UE.UERuntimeSuite`).
|
||||
*
|
||||
* Usage:
|
||||
* UnrealEditor-Cmd <Project.uproject> -run=RunLuaTests -unattended -nop4 -nosplash -NullRHI
|
||||
* (Optional: pass -UseLuaBundle to run tests directly from /Game/Generated/DA_LuaBundle)
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMOEDITOR_API URunLuaTestsCommandlet : public UCommandlet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
URunLuaTestsCommandlet();
|
||||
|
||||
virtual int32 Main(const FString& Params) override;
|
||||
};
|
||||
@@ -0,0 +1,278 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "SetupFrameworkAssetsCommandlet.h"
|
||||
#include "UnrealLuaDemoEditor.h"
|
||||
#include "Core/LuaGameModeBase.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "Blueprint/WidgetTree.h"
|
||||
#include "Components/Border.h"
|
||||
#include "Components/Button.h"
|
||||
#include "Components/CanvasPanel.h"
|
||||
#include "Components/CanvasPanelSlot.h"
|
||||
#include "Components/Image.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Components/VerticalBox.h"
|
||||
#include "Components/VerticalBoxSlot.h"
|
||||
#include "Engine/Texture2D.h"
|
||||
#include "Engine/World.h"
|
||||
#include "GameFramework/WorldSettings.h"
|
||||
#include "HAL/FileManager.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "Kismet2/KismetEditorUtilities.h"
|
||||
#include "Misc/PackageName.h"
|
||||
#include "Misc/Paths.h"
|
||||
#include "UObject/Package.h"
|
||||
#include "UObject/SavePackage.h"
|
||||
#include "WidgetBlueprint.h"
|
||||
#include "WidgetBlueprintFactory.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
bool SaveAssetPackage(UPackage* Package, UObject* Asset, const FString& LongPackageName)
|
||||
{
|
||||
if (!Package || !Asset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const FString Extension = Asset->IsA<UWorld>()
|
||||
? FPackageName::GetMapPackageExtension()
|
||||
: FPackageName::GetAssetPackageExtension();
|
||||
const FString Filename = FPackageName::LongPackageNameToFilename(LongPackageName, Extension);
|
||||
|
||||
IFileManager::Get().MakeDirectory(*FPaths::GetPath(Filename), /*Tree=*/true);
|
||||
|
||||
FSavePackageArgs SaveArgs;
|
||||
SaveArgs.TopLevelFlags = RF_Public | RF_Standalone;
|
||||
SaveArgs.Error = GError;
|
||||
SaveArgs.bWarnOfLongFilename = false;
|
||||
|
||||
return UPackage::SavePackage(Package, Asset, *Filename, SaveArgs);
|
||||
}
|
||||
}
|
||||
|
||||
USetupFrameworkAssetsCommandlet::USetupFrameworkAssetsCommandlet()
|
||||
{
|
||||
IsClient = true;
|
||||
IsEditor = true;
|
||||
IsServer = false;
|
||||
LogToConsole = true;
|
||||
}
|
||||
|
||||
int32 USetupFrameworkAssetsCommandlet::Main(const FString& Params)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[SetupFrameworkAssets] Creating Phase-0 baseline assets..."));
|
||||
|
||||
if (!CreateBootstrapMap())
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupFrameworkAssets] Failed to create /Game/Maps/L_Bootstrap."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CreateMiniSettingsTexture())
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupFrameworkAssets] Failed to create /Game/UI/Textures/T_MiniSettingsIcon."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CreateMiniSettingsWidgetBlueprint())
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupFrameworkAssets] Failed to create /Game/UI/WBP_MiniSettings."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[SetupFrameworkAssets] All Phase-0 baseline assets created successfully."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool USetupFrameworkAssetsCommandlet::CreateBootstrapMap() const
|
||||
{
|
||||
const FString PackageName = TEXT("/Game/Maps/L_Bootstrap");
|
||||
UPackage* Package = CreatePackage(*PackageName);
|
||||
if (!Package)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UWorld* NewWorld = UWorld::CreateWorld(EWorldType::Inactive, false, TEXT("L_Bootstrap"), Package, true, ERHIFeatureLevel::Num);
|
||||
if (!NewWorld)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NewWorld->SetFlags(RF_Public | RF_Standalone);
|
||||
if (AWorldSettings* WS = NewWorld->GetWorldSettings())
|
||||
{
|
||||
WS->DefaultGameMode = ALuaGameModeBase::StaticClass();
|
||||
}
|
||||
|
||||
FAssetRegistryModule::AssetCreated(NewWorld);
|
||||
Package->MarkPackageDirty();
|
||||
|
||||
const bool bSaved = SaveAssetPackage(Package, NewWorld, PackageName);
|
||||
NewWorld->DestroyWorld(false);
|
||||
return bSaved;
|
||||
}
|
||||
|
||||
bool USetupFrameworkAssetsCommandlet::CreateMiniSettingsTexture() const
|
||||
{
|
||||
const FString PackageName = TEXT("/Game/UI/Textures/T_MiniSettingsIcon");
|
||||
const FString AssetName = TEXT("T_MiniSettingsIcon");
|
||||
|
||||
UPackage* Package = CreatePackage(*PackageName);
|
||||
if (!Package)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr int32 Size = 128;
|
||||
UTexture2D* Texture = NewObject<UTexture2D>(Package, *AssetName, RF_Public | RF_Standalone);
|
||||
if (!Texture)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TArray<uint8> Pixels;
|
||||
Pixels.SetNumUninitialized(Size * Size * 4);
|
||||
for (int32 Y = 0; Y < Size; ++Y)
|
||||
{
|
||||
for (int32 X = 0; X < Size; ++X)
|
||||
{
|
||||
const int32 Idx = (Y * Size + X) * 4;
|
||||
const float Dx = (X - Size * 0.5f) / (Size * 0.5f);
|
||||
const float Dy = (Y - Size * 0.5f) / (Size * 0.5f);
|
||||
const float Dist = FMath::Sqrt(Dx * Dx + Dy * Dy);
|
||||
|
||||
const bool bRing = (Dist >= 0.45f && Dist <= 0.78f);
|
||||
const bool bCore = (Dist <= 0.28f);
|
||||
|
||||
// BGRA8
|
||||
if (bCore)
|
||||
{
|
||||
Pixels[Idx + 0] = 255;
|
||||
Pixels[Idx + 1] = 220;
|
||||
Pixels[Idx + 2] = 60;
|
||||
Pixels[Idx + 3] = 255;
|
||||
}
|
||||
else if (bRing)
|
||||
{
|
||||
Pixels[Idx + 0] = 240;
|
||||
Pixels[Idx + 1] = 170;
|
||||
Pixels[Idx + 2] = 40;
|
||||
Pixels[Idx + 3] = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
Pixels[Idx + 0] = 48;
|
||||
Pixels[Idx + 1] = 36;
|
||||
Pixels[Idx + 2] = 28;
|
||||
Pixels[Idx + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Texture->Source.Init(Size, Size, 1, 1, TSF_BGRA8, Pixels.GetData());
|
||||
Texture->LODGroup = TEXTUREGROUP_UI;
|
||||
Texture->CompressionSettings = TC_EditorIcon;
|
||||
Texture->MipGenSettings = TMGS_NoMipmaps;
|
||||
Texture->SRGB = true;
|
||||
Texture->UpdateResource();
|
||||
Texture->PostEditChange();
|
||||
|
||||
FAssetRegistryModule::AssetCreated(Texture);
|
||||
Package->MarkPackageDirty();
|
||||
|
||||
return SaveAssetPackage(Package, Texture, PackageName);
|
||||
}
|
||||
|
||||
bool USetupFrameworkAssetsCommandlet::CreateMiniSettingsWidgetBlueprint() const
|
||||
{
|
||||
const FString PackageName = TEXT("/Game/UI/WBP_MiniSettings");
|
||||
const FString AssetName = TEXT("WBP_MiniSettings");
|
||||
|
||||
UPackage* Package = CreatePackage(*PackageName);
|
||||
if (!Package)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UWidgetBlueprintFactory* Factory = NewObject<UWidgetBlueprintFactory>();
|
||||
Factory->ParentClass = UUserWidget::StaticClass();
|
||||
|
||||
UWidgetBlueprint* WidgetBP = Cast<UWidgetBlueprint>(
|
||||
Factory->FactoryCreateNew(UWidgetBlueprint::StaticClass(), Package, *AssetName, RF_Public | RF_Standalone, nullptr, GWarn));
|
||||
if (!WidgetBP || !WidgetBP->WidgetTree)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UWidgetTree* Tree = WidgetBP->WidgetTree;
|
||||
|
||||
UCanvasPanel* RootCanvas = Tree->ConstructWidget<UCanvasPanel>(UCanvasPanel::StaticClass(), TEXT("RootCanvas"));
|
||||
Tree->RootWidget = RootCanvas;
|
||||
|
||||
UBorder* PanelBorder = Tree->ConstructWidget<UBorder>(UBorder::StaticClass(), TEXT("PanelBorder"));
|
||||
PanelBorder->SetBrushColor(FLinearColor(0.08f, 0.10f, 0.14f, 0.92f));
|
||||
PanelBorder->SetPadding(FMargin(24.0f));
|
||||
if (UCanvasPanelSlot* BorderSlot = RootCanvas->AddChildToCanvas(PanelBorder))
|
||||
{
|
||||
BorderSlot->SetAnchors(FAnchors(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
BorderSlot->SetAlignment(FVector2D(0.5f, 0.5f));
|
||||
BorderSlot->SetSize(FVector2D(420.0f, 360.0f));
|
||||
}
|
||||
|
||||
UVerticalBox* LayoutBox = Tree->ConstructWidget<UVerticalBox>(UVerticalBox::StaticClass(), TEXT("LayoutBox"));
|
||||
PanelBorder->SetContent(LayoutBox);
|
||||
|
||||
// 1. Named Image: ImgIcon
|
||||
UImage* ImgIcon = Tree->ConstructWidget<UImage>(UImage::StaticClass(), TEXT("ImgIcon"));
|
||||
ImgIcon->bIsVariable = true;
|
||||
ImgIcon->SetDesiredSizeOverride(FVector2D(96.0f, 96.0f));
|
||||
if (UVerticalBoxSlot* IconSlot = LayoutBox->AddChildToVerticalBox(ImgIcon))
|
||||
{
|
||||
IconSlot->SetHorizontalAlignment(HAlign_Center);
|
||||
IconSlot->SetPadding(FMargin(0.0f, 8.0f, 0.0f, 16.0f));
|
||||
}
|
||||
|
||||
// 2. Named TextBlock: TxtStatus
|
||||
UTextBlock* TxtStatus = Tree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TxtStatus"));
|
||||
TxtStatus->bIsVariable = true;
|
||||
TxtStatus->SetText(FText::FromString(TEXT("Mini Settings")));
|
||||
if (UVerticalBoxSlot* StatusSlot = LayoutBox->AddChildToVerticalBox(TxtStatus))
|
||||
{
|
||||
StatusSlot->SetHorizontalAlignment(HAlign_Center);
|
||||
StatusSlot->SetPadding(FMargin(0.0f, 0.0f, 0.0f, 16.0f));
|
||||
}
|
||||
|
||||
// 3. Named Button: BtnToggle (+ TxtToggleLabel)
|
||||
UButton* BtnToggle = Tree->ConstructWidget<UButton>(UButton::StaticClass(), TEXT("BtnToggle"));
|
||||
BtnToggle->bIsVariable = true;
|
||||
UTextBlock* TxtToggleLabel = Tree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TxtToggleLabel"));
|
||||
TxtToggleLabel->bIsVariable = true;
|
||||
TxtToggleLabel->SetText(FText::FromString(TEXT("Toggle Sound")));
|
||||
BtnToggle->AddChild(TxtToggleLabel);
|
||||
if (UVerticalBoxSlot* ToggleSlot = LayoutBox->AddChildToVerticalBox(BtnToggle))
|
||||
{
|
||||
ToggleSlot->SetHorizontalAlignment(HAlign_Fill);
|
||||
ToggleSlot->SetPadding(FMargin(0.0f, 0.0f, 0.0f, 12.0f));
|
||||
}
|
||||
|
||||
// 4. Named Button: BtnClose
|
||||
UButton* BtnClose = Tree->ConstructWidget<UButton>(UButton::StaticClass(), TEXT("BtnClose"));
|
||||
BtnClose->bIsVariable = true;
|
||||
UTextBlock* TxtCloseLabel = Tree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TxtCloseLabel"));
|
||||
TxtCloseLabel->SetText(FText::FromString(TEXT("Close")));
|
||||
BtnClose->AddChild(TxtCloseLabel);
|
||||
if (UVerticalBoxSlot* CloseSlot = LayoutBox->AddChildToVerticalBox(BtnClose))
|
||||
{
|
||||
CloseSlot->SetHorizontalAlignment(HAlign_Fill);
|
||||
}
|
||||
|
||||
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(WidgetBP);
|
||||
FKismetEditorUtilities::CompileBlueprint(WidgetBP);
|
||||
|
||||
FAssetRegistryModule::AssetCreated(WidgetBP);
|
||||
Package->MarkPackageDirty();
|
||||
|
||||
return SaveAssetPackage(Package, WidgetBP, PackageName);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Commandlets/Commandlet.h"
|
||||
#include "SetupFrameworkAssetsCommandlet.generated.h"
|
||||
|
||||
/**
|
||||
* Generates deterministic Phase-0 baseline assets:
|
||||
* 1. /Game/Maps/L_Bootstrap
|
||||
* 2. /Game/UI/Textures/T_MiniSettingsIcon (128x128 UTexture2D)
|
||||
* 3. /Game/UI/WBP_MiniSettings (UWidgetBlueprint with ImgIcon, TxtStatus, BtnToggle, TxtToggleLabel, BtnClose)
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALLUADEMOEDITOR_API USetupFrameworkAssetsCommandlet : public UCommandlet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
USetupFrameworkAssetsCommandlet();
|
||||
|
||||
virtual int32 Main(const FString& Params) override;
|
||||
|
||||
private:
|
||||
bool CreateBootstrapMap() const;
|
||||
bool CreateMiniSettingsTexture() const;
|
||||
bool CreateMiniSettingsWidgetBlueprint() const;
|
||||
};
|
||||
@@ -22,11 +22,15 @@ public class UnrealLuaDemoEditor : ModuleRules
|
||||
{
|
||||
"UnrealEd",
|
||||
"AssetRegistry",
|
||||
"BlueprintGraph",
|
||||
"DeveloperSettings",
|
||||
"KismetCompiler",
|
||||
"Projects",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"ToolMenus",
|
||||
"UMG",
|
||||
"UMGEditor",
|
||||
"UnLua",
|
||||
"Lua"
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user