newproject.bat 9.3 KB

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