@echo off
setlocal

REM ============================================================
REM  ship.bat - Build clang-Release and prepare Ship/ folder
REM ============================================================

set ROOT=%~dp0..
set BUILD_DIR=%ROOT%\bin\x64Clang-Release
set SHIP_DIR=%ROOT%\Ship

REM Step 0: Build Shader Compiler
echo [Ship] Building Shader Compiler...
call "%~dp0fbuild" JulietShaderCompiler-x64Clang-Release -cache
if errorlevel 1 (
    echo [Ship] SHADER COMPILER BUILD FAILED
    exit /b 1
)

REM Step 1: Compile shaders
echo [Ship] Compiling shaders...
call "%~dp0recompile_shaders.bat"
if errorlevel 1 (
    echo [Ship] SHADER COMPILATION FAILED
    exit /b 1
)

REM Step 2: Build clang-Release
echo [Ship] Building clang-Release...
call "%~dp0fbuild" clang-Release -cache
if errorlevel 1 (
    echo [Ship] BUILD FAILED
    exit /b 1
)

REM Step 3: Prepare Ship folder
echo [Ship] Preparing Ship folder: %SHIP_DIR%

if exist "%SHIP_DIR%" rd /s /q "%SHIP_DIR%"
mkdir "%SHIP_DIR%"

REM Copy only the required binaries
echo [Ship] Copying binaries...
copy "%BUILD_DIR%\JulietApp.exe" "%SHIP_DIR%\" >nul
copy "%BUILD_DIR%\Juliet.dll"    "%SHIP_DIR%\" >nul
copy "%BUILD_DIR%\Game.dll"      "%SHIP_DIR%\" >nul

REM Copy compiled shaders into Assets\Shaders\
echo [Ship] Copying shaders...
mkdir "%SHIP_DIR%\Assets\Shaders"
copy "%ROOT%\Assets\compiled\*.dxil" "%SHIP_DIR%\Assets\Shaders\" >nul
del "%SHIP_DIR%\Assets\Shaders\ImGui*.dxil" >nul 2>&1

echo.
echo [Ship] Done!
echo [Ship] Ship folder: %SHIP_DIR%
echo.
echo [Ship] Contents:
dir /b "%SHIP_DIR%"
echo.
echo [Ship] Shaders:
dir /b "%SHIP_DIR%\Assets\Shaders"
