Bước này tạo ra 2 file batch-script để build data tự động. Các file này nằm trong thư mục FifteenPuzzle, cùng cấp với các thư mục source, data ...
File này chứa các thông tin cần thiết về cấu hình, cấu trúc, và đặt biệt là đường dẫn đến các thư mục cần thiết. Các thư mục này có thể khác nhau khi build cho từng máy, và người dùng chỉ cần sửa đổi thông tin cấu hình cho phù hợp từng máy trước khi build
config.bat
@echo off
REM =======================================
REM == USER DEFINED ==
REM =======================================
set JDK=C:\jdk1.6.0_10\bin
REM =======================================
REM == DO NOT MODIFY THE FOLLOWING ==
REM =======================================
set CUR_DIR=%CD%
set ROOT_DIR=%~dp0
set TOOLPACK=%ROOT_DIR%\external\gametutor\tools\ToolPack.jar
set SOURCE_DIR=%ROOT_DIR%\source\
set DATA_DIR=%ROOT_DIR%\data\
Trong file này, tham số duy nhất cần hiệu chỉnh khi build trên máy khác là đường dẫn JDK
Ta tiến hành qua các công đoạn sau
@echo off
cls
cd %ROOT_DIR%
if not exist "config.bat" (
echo ERROR: config.bat not found
goto END
)
call config.bat
:CHECKING
echo ::Checking
if not exist %JDK% (
echo ERROR: JDK [%JDK%] not found
goto END
)
if not exist %DATA_DIR% (
echo ERROR: JDK [%DATA_DIR%] not found
goto END
)
if not exist %SOURCE_DIR% (
echo ERROR: JDK [%DATA_DIR%] not found
goto END
)
if not exist %TOOLPACK% (
echo ERROR: JDK [%TOOLPACK%] not found
goto END
)
:BEGIN
cd %DATA_DIR%
if exist #build (rd /s /q #build)
if exist #temp (rd /s /q #temp)
:CLONE_RES
echo ========CLONE RESOURCE========
dir /B/S *.* > #raw_files.txt
md #temp
md #build
for /F %%i in (#raw_files.txt) do (
copy %%i #temp>nul
)
copy %TOOLPACK% #temp>nul
cd .\#temp
SET TOOLPACK_JAR=%TOOLPACK%
for /F "tokens=2 delims==" %%i in ('set TOOLPACK_JAR') do (
set TOOLPACK_JAR=%%~nxi
)
:CONVERT_IMAGE
echo ========CONVERT IMAGE TO TGA========
dir /B/S *.jpg, *.png, *.bmp > #raw_files.txt
for /F %%i in (#raw_files.txt) do (
%JDK%\java -jar -Xmx512M %TOOLPACK_JAR% tga %%i %%~ni.tga
)
:BUILD_TEXT
echo ========BUILD TEXT========
%JDK%\java -jar -Xmx512M %TOOLPACK_JAR% le text.xls
copy /y .\*.ff ..\#build>nul
copy /y .\*.lang ..\#build>nul
copy /y .\*.h %SOURCE_DIR%>nul
:COPY_RES
echo ========COPY RESOURCE========
dir /B/S *.wav, *.ogg, *.spr, *.tga > #raw_files.txt
for /F %%i in (#raw_files.txt) do (
copy /y %%i ..\#build\%%~nxi>nul
)
:END
echo ========DONE========
cd %CUR_DIR%
if exist %DATA_DIR%\#temp (rd /s /q %DATA_DIR%\#temp)
if exist %DATA_DIR%\#raw_files.txt (del %DATA_DIR%\#raw_files.txt>nul)
Tổng hợp các quá trình trên, ta có file makedata.bat
makedata.bat
@echo off cls cd %ROOT_DIR% if not exist "config.bat" ( echo ERROR: config.bat not found goto END ) call config.bat :CHECKING echo ::Checking if not exist %JDK% ( echo ERROR: JDK [%JDK%] not found goto END ) if not exist %DATA_DIR% ( echo ERROR: JDK [%DATA_DIR%] not found goto END ) if not exist %SOURCE_DIR% ( echo ERROR: JDK [%DATA_DIR%] not found goto END ) if not exist %TOOLPACK% ( echo ERROR: JDK [%TOOLPACK%] not found goto END ) :BEGIN cd %DATA_DIR% if exist #build (rd /s /q #build) if exist #temp (rd /s /q #temp) :CLONE_RES echo ========CLONE RESOURCE======== dir /B/S *.* > #raw_files.txt md #temp md #build for /F %%i in (#raw_files.txt) do ( copy %%i #temp>nul ) copy %TOOLPACK% #temp>nul cd .\#temp SET TOOLPACK_JAR=%TOOLPACK% for /F "tokens=2 delims==" %%i in ('set TOOLPACK_JAR') do ( set TOOLPACK_JAR=%%~nxi ) :CONVERT_IMAGE echo ========CONVERT IMAGE TO TGA======== dir /B/S *.jpg, *.png, *.bmp > #raw_files.txt for /F %%i in (#raw_files.txt) do ( %JDK%\java -jar -Xmx512M %TOOLPACK_JAR% tga %%i %%~ni.tga ) :BUILD_TEXT echo ========BUILD TEXT======== %JDK%\java -jar -Xmx512M %TOOLPACK_JAR% le text.xls copy /y .\*.ff ..\#build>nul copy /y .\*.lang ..\#build>nul copy /y .\*.h %SOURCE_DIR%>nul :COPY_RES echo ========COPY RESOURCE======== dir /B/S *.wav, *.ogg, *.spr, *.tga > #raw_files.txt for /F %%i in (#raw_files.txt) do ( copy /y %%i ..\#build\%%~nxi>nul ) :END echo ========DONE======== cd %CUR_DIR% if exist %DATA_DIR%\#temp (rd /s /q %DATA_DIR%\#temp) if exist %DATA_DIR%\#raw_files.txt (del %DATA_DIR%\#raw_files.txt>nul)
Kết quả sau khi thực thi makedata.bat (ví dụ minh họa)
Để có thể run được game với thư mục data là #build, ta cần thiết lập đường dẫn Working Directory cho project game là $(SolutionDir)..\..\data\#build