feat(tools): 命令行白模构建——build_level.bat 一键生成UE5关卡
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM === ChildHood Level Builder - Command Line Build ===
|
||||
REM
|
||||
REM Usage:
|
||||
REM build_level.bat (default config)
|
||||
REM build_level.bat --json output/v02.json (specify JSON)
|
||||
REM build_level.bat --map LVL_SuburbanV02 (specify map name)
|
||||
REM build_level.bat --no-quit (keep editor open)
|
||||
REM build_level.bat --no-null-rhi (show editor window)
|
||||
REM build_level.bat --dry-run (print command only)
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "PROJECT_DIR=%SCRIPT_DIR%..\.."
|
||||
for %%i in ("%PROJECT_DIR%\.") do set "PROJECT_ROOT=%%~fi"
|
||||
set "UPROJECT=%PROJECT_ROOT%\ChildHood.uproject"
|
||||
|
||||
REM ---- Defaults ----
|
||||
set "JSON_REL=tools/level-builder/output/level_v01.json"
|
||||
set "MAP_NAME=LVL_SuburbanV01"
|
||||
set "MAP_PACKAGE=/Game/Maps"
|
||||
set "NO_QUIT=0"
|
||||
set "NO_NULL_RHI=0"
|
||||
set "DRY_RUN=0"
|
||||
|
||||
REM ---- Parse Arguments ----
|
||||
:parse_args
|
||||
if "%~1"=="" goto done_args
|
||||
if /i "%~1"=="--json" (
|
||||
set "JSON_REL=%~2"
|
||||
shift
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /i "%~1"=="--map" (
|
||||
set "MAP_NAME=%~2"
|
||||
shift
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /i "%~1"=="--package" (
|
||||
set "MAP_PACKAGE=%~2"
|
||||
shift
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /i "%~1"=="--no-quit" (
|
||||
set "NO_QUIT=1"
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /i "%~1"=="--no-null-rhi" (
|
||||
set "NO_NULL_RHI=1"
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /i "%~1"=="--dry-run" (
|
||||
set "DRY_RUN=1"
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /i "%~1"=="--help" goto show_help
|
||||
if /i "%~1"=="-h" goto show_help
|
||||
echo [WARN] Unknown argument: %~1
|
||||
shift
|
||||
goto parse_args
|
||||
:done_args
|
||||
|
||||
REM ---- Find UE5 Editor ----
|
||||
set "UE_EDITOR="
|
||||
if defined UE5_ROOT (
|
||||
for %%b in (UnrealEditor.exe UE5Editor.exe) do (
|
||||
if exist "%UE5_ROOT%\Engine\Binaries\Win64\%%b" (
|
||||
set "UE_EDITOR=%UE5_ROOT%\Engine\Binaries\Win64\%%b"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if "%UE_EDITOR%"=="" (
|
||||
for %%p in (
|
||||
"C:\Program Files\Epic Games\UE_5.7"
|
||||
"C:\Program Files (x86)\Epic Games\UE_5.7"
|
||||
"D:\Program Files\Epic Games\UE_5.7"
|
||||
"E:\Program Files\Epic Games\UE_5.7"
|
||||
"C:\Program Files\Epic Games\UE_5.6"
|
||||
"C:\Program Files (x86)\Epic Games\UE_5.6"
|
||||
"D:\Program Files\Epic Games\UE_5.6"
|
||||
"E:\Program Files\Epic Games\UE_5.6"
|
||||
) do (
|
||||
if not defined UE_EDITOR (
|
||||
for %%b in (UnrealEditor.exe UE5Editor.exe) do (
|
||||
if exist "%%~p\Engine\Binaries\Win64\%%b" (
|
||||
set "UE_EDITOR=%%~p\Engine\Binaries\Win64\%%b"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if "%UE_EDITOR%"=="" (
|
||||
echo.
|
||||
echo [ERROR] UE5 Editor not found!
|
||||
echo Set UE5_ROOT to your UE5 install directory, e.g.:
|
||||
echo set UE5_ROOT=C:\Program Files\Epic Games\UE_5.7
|
||||
echo.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM ---- Path conversion (UE5 uses forward slashes) ----
|
||||
set "SCRIPT_PATH=%SCRIPT_DIR%build_cmdline.py"
|
||||
set "SCRIPT_PATH=!SCRIPT_PATH:\=/!"
|
||||
set "UPROJECT_FWD=!UPROJECT:\=/!"
|
||||
|
||||
REM ---- Build command line ----
|
||||
set "CMD_ARGS=-unattended -NoSound"
|
||||
if "!NO_NULL_RHI!"=="0" set "CMD_ARGS=!CMD_ARGS! -NullRHI"
|
||||
set "CMD_ARGS=!CMD_ARGS! -ExecutePythonScript=!SCRIPT_PATH!"
|
||||
|
||||
REM ---- Pass config to Python via env vars ----
|
||||
set "LB_PROJECT_ROOT=!PROJECT_ROOT!"
|
||||
set "LB_JSON_PATH=%JSON_REL%"
|
||||
set "LB_MAP_NAME=%MAP_NAME%"
|
||||
set "LB_MAP_PACKAGE=%MAP_PACKAGE%"
|
||||
if "!NO_QUIT!"=="1" set "LB_NO_QUIT=1"
|
||||
|
||||
REM ---- Print info ----
|
||||
echo.
|
||||
echo ============================================
|
||||
echo ChildHood Level Builder - Command Line
|
||||
echo ============================================
|
||||
echo UE5: !UE_EDITOR!
|
||||
echo Project: !UPROJECT_FWD!
|
||||
echo JSON: %JSON_REL%
|
||||
echo Map: %MAP_PACKAGE%/%MAP_NAME%
|
||||
echo NullRHI: %NO_NULL_RHI%
|
||||
echo ============================================
|
||||
echo.
|
||||
|
||||
REM ---- Dry Run ----
|
||||
if "%DRY_RUN%"=="1" (
|
||||
echo [DRY RUN] Command:
|
||||
echo.
|
||||
echo "!UE_EDITOR!" "!UPROJECT_FWD!" !CMD_ARGS!
|
||||
echo.
|
||||
exit /b 0
|
||||
)
|
||||
|
||||
REM ---- Check JSON exists ----
|
||||
set "JSON_ABS=%PROJECT_ROOT%\%JSON_REL%"
|
||||
set "JSON_ABS=!JSON_ABS:/=\!"
|
||||
if not exist "!JSON_ABS!" (
|
||||
echo [ERROR] JSON not found: !JSON_ABS!
|
||||
echo Run first: python tools/level-builder/main.py parse
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM ---- Execute ----
|
||||
echo [LevelBuilder] Launching UE5 Editor (command line mode)...
|
||||
echo [LevelBuilder] Editor will auto-save and quit after build.
|
||||
echo.
|
||||
|
||||
"!UE_EDITOR!" "!UPROJECT_FWD!" !CMD_ARGS!
|
||||
|
||||
set "EXIT_CODE=!ERRORLEVEL!"
|
||||
echo.
|
||||
if "!EXIT_CODE!"=="0" (
|
||||
echo [LevelBuilder] Build complete. Editor exited.
|
||||
) else (
|
||||
echo [LevelBuilder] Editor exit code: !EXIT_CODE!
|
||||
)
|
||||
exit /b !EXIT_CODE!
|
||||
|
||||
:show_help
|
||||
echo.
|
||||
echo ChildHood Level Builder - Command Line Build
|
||||
echo.
|
||||
echo Usage: build_level.bat [options]
|
||||
echo.
|
||||
echo Options:
|
||||
echo --json PATH JSON data file (relative to project root)
|
||||
echo --map NAME Target map asset name (default: LVL_SuburbanV01)
|
||||
echo --package PATH Map package path (default: /Game/Maps)
|
||||
echo --no-quit Keep editor open after build
|
||||
echo --no-null-rhi Show editor window (for debugging)
|
||||
echo --dry-run Print command without executing
|
||||
echo --help, -h Show this help
|
||||
echo.
|
||||
echo Environment:
|
||||
echo UE5_ROOT UE5 install directory
|
||||
echo.
|
||||
exit /b 0
|
||||
Reference in New Issue
Block a user