newproject.bat 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. @echo off
  2. REM ********************************************************************
  3. REM
  4. REM generate-project.bat
  5. REM
  6. REM This windows batch script generates a set of gameplay project files.
  7. REM The new project will be based of the template project and
  8. REM it will be generated with the name and location that is specified
  9. REM as input parameters.
  10. REM
  11. REM IMPORTANT: This script must be run from the root of the gameplay
  12. REM source tree.
  13. REM
  14. REM ********************************************************************
  15. echo.
  16. echo 1. Enter a name for the new project.
  17. echo.
  18. echo This name will be given to the project
  19. echo executable and a folder with this name
  20. echo will be created to store all project files.
  21. echo.
  22. set /p projName=Project name:
  23. if "%projName%" == "" (
  24. echo.
  25. echo ERROR: No project name specified.
  26. echo.
  27. pause
  28. goto done
  29. )
  30. echo.
  31. echo.
  32. echo 2. Enter a game title.
  33. echo.
  34. echo On some platforms, this title is used to
  35. echo identify the game during installation and
  36. echo on shortcuts/icons.
  37. echo.
  38. set /p title=Title:
  39. if "%title%" == "" (
  40. echo.
  41. echo ERROR: No game title specified.
  42. echo.
  43. pause
  44. goto done
  45. )
  46. echo.
  47. echo.
  48. echo 3. Enter a short game description.
  49. echo.
  50. set /p desc=Description:
  51. if "%desc%" == "" (
  52. set desc=%title%
  53. )
  54. echo.
  55. echo.
  56. echo 4. Enter a unique identifier for your project.
  57. echo.
  58. echo This should be a human readable package name,
  59. echo containing at least two words separated by a
  60. echo period (eg. com.surname.gamename).
  61. echo.
  62. set /p uuid=Unique ID:
  63. if "%uuid%" == "" (
  64. echo.
  65. echo ERROR: No uuid specified.
  66. echo.
  67. pause
  68. goto done
  69. )
  70. echo.
  71. echo.
  72. echo 5. Enter author name.
  73. echo.
  74. echo On BlackBerry targets, this is used for
  75. echo signing and must match the developer name
  76. echo of your development certificate.
  77. echo.
  78. set /p author=Author:
  79. if "%author%" == "" (
  80. echo.
  81. echo ERROR: No author specified.
  82. echo.
  83. pause
  84. goto done
  85. )
  86. echo.
  87. echo.
  88. echo 6. Enter your game's main class name.
  89. echo.
  90. echo Your initial game header and source file
  91. echo will be given this name and a class with
  92. echo this name will be created in these files.
  93. echo.
  94. set /p className=Class name:
  95. if "%className%" == "" (
  96. echo.
  97. echo ERROR: No class name specified.
  98. echo.
  99. pause
  100. goto done
  101. )
  102. echo.
  103. echo.
  104. echo 7. Enter the project path.
  105. echo.
  106. echo This can be a relative path, absolute path,
  107. echo or empty for the current folder. Note that
  108. echo a project folder named %projName% will also
  109. echo be created inside this folder.
  110. echo.
  111. set /p location=Path:
  112. if "%location%" == "" (
  113. set projPath=%projName%
  114. ) else (
  115. set projPath=%location%\%projName%
  116. )
  117. echo.
  118. call:replacevar projPath "/" "\"
  119. REM Does this path already exist?
  120. if exist "%projPath%" (
  121. echo.
  122. echo ERROR: Path '%projPath%' already exists, aborting.
  123. echo.
  124. pause
  125. goto done
  126. REM Disabling following code which prompts to overwrite existing path,
  127. REM since this could be potentially damaging if the user specifies
  128. REM an important path and then types 'y', without thinking.
  129. REM
  130. REM set /p owd=Directory '%projPath%' exists, overwrite [Y,N]?
  131. REM if not "!owd!" == "Y" (
  132. REM if not "!owd!" == "y" (
  133. REM echo Aborting.
  134. REM pause
  135. REM goto done
  136. REM )
  137. REM )
  138. REM rmdir /S /Q %projPath%
  139. )
  140. REM Generate relative path from project folder to GamePlay folder
  141. set gpPath=%cd%
  142. call:makerelative gpPath "%projPath%\"
  143. mkdir "%projPath%"
  144. mkdir "%projPath%\src"
  145. mkdir "%projPath%\res"
  146. REM Copy Microsoft Visual Studio project files
  147. copy template\template.vcxproj "%projPath%\%projName%.vcxproj"
  148. call:replace "%projPath%\%projName%.vcxproj" TEMPLATE_PROJECT "%projName%"
  149. call:replace "%projPath%\%projName%.vcxproj" TemplateGame "%className%"
  150. call:replace "%projPath%\%projName%.vcxproj" GAMEPLAY_PATH "%gpPath%"
  151. copy template\template.vcxproj.filters "%projPath%\%projName%.vcxproj.filters"
  152. call:replace "%projPath%\%projName%.vcxproj.filters" TemplateGame "%className%"
  153. copy template\template.vcxproj.user "%projPath%\%projName%.vcxproj.user"
  154. call:replace "%projPath%\%projName%.vcxproj.user" GAMEPLAY_PATH "%gpPath%"
  155. call:replacevar gpPath "\" "/"
  156. REM Copy Apple XCode project files
  157. mkdir "%projPath%\%projName%.xcodeproj"
  158. copy template\template.xcodeproj\project.pbxproj "%projPath%\%projName%.xcodeproj\project.pbxproj"
  159. call:replace "%projPath%\%projName%.xcodeproj\project.pbxproj" GAMEPLAY_PATH "%gpPath%"
  160. call:replace "%projPath%\%projName%.xcodeproj\project.pbxproj" TemplateGame "%className%"
  161. call:replace "%projPath%\%projName%.xcodeproj\project.pbxproj" TEMPLATE_PROJECT "%projName%"
  162. copy template\TEMPLATE_PROJECT-macosx.plist "%projPath%\%projName%-macosx.plist"
  163. call:replace "%projPath%\%projName%-macosx.plist" TEMPLATE_UUID "%uuid%"
  164. call:replace "%projPath%\%projName%-macosx.plist" TEMPLATE_AUTHOR "%author%"
  165. copy template\TEMPLATE_PROJECT-ios.plist "%projPath%\%projName%-ios.plist"
  166. copy template\[email protected] "%projPath%\[email protected]"
  167. call:replace "%projPath%\%projName%-ios.plist" TEMPLATE_TITLE "%title%"
  168. call:replace "%projPath%\%projName%-ios.plist" TEMPLATE_UUID "%uuid%"
  169. call:replace "%projPath%\%projName%-ios.plist" TEMPLATE_AUTHOR "%author%"
  170. REM Copy BlackBerry NDK project files
  171. copy template\template.cproject "%projPath%\.cproject"
  172. call:replace "%projPath%\.cproject" TEMPLATE_PROJECT "%projName%"
  173. call:replace "%projPath%\.cproject" TEMPLATE_UUID "%uuid%"
  174. call:replace "%projPath%\.cproject" GAMEPLAY_PATH "%gpPath%"
  175. copy template\template.project "%projPath%\.project"
  176. call:replace "%projPath%\.project" TEMPLATE_PROJECT "%projName%"
  177. copy template\template.bar-descriptor.xml "%projPath%\bar-descriptor.xml"
  178. call:replace "%projPath%\bar-descriptor.xml" TEMPLATE_PROJECT "%projName%"
  179. call:replace "%projPath%\bar-descriptor.xml" TEMPLATE_TITLE "%title%"
  180. call:replace "%projPath%\bar-descriptor.xml" TEMPLATE_UUID "%uuid%"
  181. call:replace "%projPath%\bar-descriptor.xml" TEMPLATE_AUTHOR "%author%"
  182. call:replace "%projPath%\bar-descriptor.xml" TEMPLATE_DESCRIPTION "%desc%"
  183. call:replace "%projPath%\bar-descriptor.xml" GAMEPLAY_PATH "%gpPath%"
  184. REM Copy Android NDK project files
  185. mkdir "%projPath%\android"
  186. copy template\android\template.AndroidManifest.xml "%projPath%\android\AndroidManifest.xml"
  187. call:replace "%projPath%\android\AndroidManifest.xml" TEMPLATE_PROJECT "%projName%"
  188. call:replace "%projPath%\android\AndroidManifest.xml" TEMPLATE_UUID "%uuid%"
  189. copy template\android\template.build.xml "%projPath%\android\build.xml"
  190. call:replace "%projPath%\android\build.xml" TEMPLATE_PROJECT "%projName%"
  191. call:replace "%projPath%\android\build.xml" GAMEPLAY_PATH "%gpPath%"
  192. mkdir "%projPath%\android\jni"
  193. copy template\android\jni\Application.mk "%projPath%\android\jni\Application.mk"
  194. copy template\android\jni\template.Android.mk "%projPath%\android\jni\Android.mk"
  195. call:replace "%projPath%\android\jni\Android.mk" TemplateGame "%className%"
  196. call:replace "%projPath%\android\jni\Android.mk" TEMPLATE_PROJECT "%projName%"
  197. call:replace "%projPath%\android\jni\Android.mk" GAMEPLAY_PATH "%gpPath%"
  198. mkdir "%projPath%\android\res\drawable"
  199. copy template\icon.png "%projPath%\android\res\drawable\icon.png"
  200. mkdir "%projPath%\android\res\values"
  201. copy template\android\res\values\template.strings.xml "%projPath%\android\res\values\strings.xml"
  202. call:replace "%projPath%\android\res\values\strings.xml" TEMPLATE_TITLE "%title%"
  203. mkdir "%projPath%\build"
  204. copy "template\template-CMakeLists.txt" "%projPath%\CMakeLists.txt"
  205. call:replace "%projPath%\CMakeLists.txt" TEMPLATE_PROJECT %projName%
  206. call:replace "%projPath%\CMakeLists.txt" TemplateGame %className%
  207. call:replace "%projPath%\CMakeLists.txt" GAMEPLAY_PATH %gpPath%
  208. REM Copy source files
  209. copy template\src\TemplateGame.h "%projPath%\src\%className%.h"
  210. copy template\src\TemplateGame.cpp "%projPath%\src\%className%.cpp"
  211. call:replace "%projPath%\src\%className%.h" TemplateGame "%className%"
  212. call:replace "%projPath%\src\%className%.cpp" TemplateGame "%className%"
  213. REM Copy resource files
  214. copy template\res\* "%projPath%\res\"
  215. REM Copy icon
  216. copy template\icon.png "%projPath%\icon.png"
  217. REM Copy config
  218. copy template\game.config "%projPath%\game.config"
  219. call:replace "%projPath%\game.config" TEMPLATE_TITLE "%title%"
  220. REM Open new project folder
  221. start "" "%projPath%"
  222. goto done
  223. :replace
  224. set rtemp=%~1.rtemp
  225. if exist "%rtemp%" del /Q "%rtemp%"
  226. for /f "tokens=1* eol=€ delims=€]" %%j in ('type "%~1" ^| find /V /N ""') do (
  227. set line=%%k
  228. setlocal EnableDelayedExpansion
  229. if "!line!" == "" (
  230. echo.>>"%rtemp%"
  231. ) else (
  232. set linput=!line!
  233. set loutput=!linput:%~2=%~3!
  234. echo.!loutput!>>"%rtemp%"
  235. )
  236. endlocal
  237. )
  238. copy /Y "%rtemp%" "%~1"
  239. del /Q "%rtemp%"
  240. exit /b
  241. goto done
  242. :replacevar
  243. setlocal EnableDelayedExpansion
  244. echo !%~1!>.replacevar.tmp
  245. endlocal
  246. call:replace .replacevar.tmp "%~2" "%~3"
  247. set /p replaced=<.replacevar.tmp
  248. set %~1=%replaced%
  249. del /Q .replacevar.tmp
  250. exit /b
  251. goto done
  252. :makerelative
  253. setlocal EnableDelayedExpansion
  254. set src=%~1
  255. if defined %1 set src=!%~1!
  256. set bas=%~2
  257. if not defined bas set bas=%cd%
  258. for /f "tokens=*" %%a in ("%src%") do set src=%%~fa
  259. for /f "tokens=*" %%a in ("%bas%") do set bas=%%~fa
  260. set mat=&rem variable to store matching part of the name
  261. set upp=&rem variable to reference a parent
  262. for /f "tokens=*" %%a in ('echo.%bas:\=^&echo.%') do (
  263. set sub=!sub!%%a\
  264. call set tmp=%%src:!sub!=%%
  265. if "!tmp!" NEQ "!src!" (set mat=!sub!)ELSE (set upp=!upp!..\)
  266. )
  267. set src=%upp%!src:%mat%=!
  268. ( endlocal & REM RETURN VALUES
  269. IF defined %1 (SET %~1=%src%) ELSE ECHO.%src%
  270. )
  271. exit /b
  272. goto done
  273. :done