@echo off
setlocal

set "PROJECT_DIR=%~dp0.."
set "PROJECT_FILE=%PROJECT_DIR%\AgrarianGame.uproject"
set "UE_ROOT=C:\Program Files\Epic Games\UE_5.7"
set "EDITOR_CMD=%UE_ROOT%\Engine\Binaries\Win64\UnrealEditor-Cmd.exe"

if "%~1"=="" (
  echo Usage: %~nx0 ScriptRelativeOrAbsolutePath
  exit /b 2
)

set "PYTHON_SCRIPT=%~f1"
if not exist "%PYTHON_SCRIPT%" set "PYTHON_SCRIPT=%PROJECT_DIR%\%~1"

if not exist "%EDITOR_CMD%" (
  echo UnrealEditor-Cmd.exe was not found at:
  echo %EDITOR_CMD%
  exit /b 1
)

if not exist "%PROJECT_FILE%" (
  echo Project file was not found at:
  echo %PROJECT_FILE%
  exit /b 1
)

if not exist "%PYTHON_SCRIPT%" (
  echo Python script was not found at:
  echo %PYTHON_SCRIPT%
  exit /b 1
)

call "%EDITOR_CMD%" "%PROJECT_FILE%" -ExecutePythonScript="%PYTHON_SCRIPT%" -unattended -nop4 -nosplash -NullRHI -stdout -FullStdOutLogOutput -log="%PROJECT_DIR%\Saved\Logs\CodexPython.log"
exit /b %ERRORLEVEL%
