newproject.bat 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. call:replacevar gpPath "\" "/"
  135. REM Copy Apple XCode project files
  136. mkdir "%projPath%\%projName%.xcodeproj"
  137. copy template\template.xcodeproj\project.pbxproj "%projPath%\%projName%.xcodeproj\project.pbxproj"
  138. call:replace "%projPath%\%projName%.xcodeproj\project.pbxproj" GAMEPLAY_PATH "%gpPath%"
  139. call:replace "%projPath%\%projName%.xcodeproj\project.pbxproj" TemplateGame "%className%"
  140. call:replace "%projPath%\%projName%.xcodeproj\project.pbxproj" TEMPLATE_PROJECT "%projName%"
  141. copy template\TEMPLATE_PROJECT-macosx.plist "%projPath%\%projName%-macosx.plist"
  142. call:replace "%projPath%\%projName%-macosx.plist" TEMPLATE_UUID "%uuid%"
  143. copy template\TEMPLATE_PROJECT-ios.plist "%projPath%\%projName%-ios.plist"
  144. copy template\[email protected] "%projPath%\[email protected]"
  145. call:replace "%projPath%\%projName%-ios.plist" TEMPLATE_TITLE "%title%"
  146. call:replace "%projPath%\%projName%-ios.plist" TEMPLATE_UUID "%uuid%"
  147. REM Copy Android NDK project files
  148. mkdir "%projPath%\android"
  149. copy template\android\AndroidManifest.xml "%projPath%\android\AndroidManifest.xml"
  150. call:replace "%projPath%\android\AndroidManifest.xml" TEMPLATE_PROJECT "%projName%"
  151. call:replace "%projPath%\android\AndroidManifest.xml" TEMPLATE_UUID "%uuid%"
  152. copy template\android\build.xml "%projPath%\android\build.xml"
  153. call:replace "%projPath%\android\build.xml" TEMPLATE_PROJECT "%projName%"
  154. call:replace "%projPath%\android\build.xml" GAMEPLAY_PATH "%gpPath%"
  155. copy template\android\project.properties "%projPath%\android\project.properties"
  156. mkdir "%projPath%\android\jni"
  157. copy template\android\jni\Application.mk "%projPath%\android\jni\Application.mk"
  158. copy template\android\jni\Android.mk "%projPath%\android\jni\Android.mk"
  159. call:replace "%projPath%\android\jni\Android.mk" TemplateGame "%className%"
  160. call:replace "%projPath%\android\jni\Android.mk" TEMPLATE_PROJECT "%projName%"
  161. call:replace "%projPath%\android\jni\Android.mk" GAMEPLAY_PATH "%gpPath%"
  162. mkdir "%projPath%\android\res\drawable"
  163. copy template\icon.png "%projPath%\android\res\drawable\icon.png"
  164. mkdir "%projPath%\android\res\values"
  165. copy template\android\res\values\template.strings.xml "%projPath%\android\res\values\strings.xml"
  166. call:replace "%projPath%\android\res\values\strings.xml" TEMPLATE_TITLE "%title%"
  167. REM Copy Eclipse files for Android
  168. copy template\android\.cproject "%projPath%\android\.cproject"
  169. call:replace "%projPath%\android\.cproject" TEMPLATE_PROJECT "%projName%"
  170. call:replace "%projPath%\android\.cproject" TEMPLATE_UUID "%uuid%"
  171. call:replace "%projPath%\android\.cproject" GAMEPLAY_PATH "%gpPath%"
  172. copy template\android\.project "%projPath%\android\.project"
  173. call:replace "%projPath%\android\.project" TEMPLATE_PROJECT "%projName%"
  174. copy template\android\.classpath "%projPath%\android\.classpath"
  175. call:replace "%projPath%\android\.classpath" TEMPLATE_PROJECT "%projName%"
  176. REM Copy Eclipse files for Linux
  177. copy template\.cproject "%projPath%\.cproject"
  178. call:replace "%projPath%\.cproject" TEMPLATE_PROJECT "%projName%"
  179. call:replace "%projPath%\.cproject" TEMPLATE_UUID "%uuid%"
  180. call:replace "%projPath%\.cproject" GAMEPLAY_PATH "%gpPath%"
  181. copy template\.project "%projPath%\.project"
  182. call:replace "%projPath%\.project" TEMPLATE_PROJECT "%projName%"
  183. REM Copy QtCreator files
  184. copy template\TEMPLATE_PROJECT.pro "%projPath%\%projName%.pro"
  185. call:replace "%projPath%\%projName%.pro" TEMPLATE_PROJECT "%projName%"
  186. call:replace "%projPath%\%projName%.pro" GAMEPLAY_PATH "%gpPath%"
  187. call:replace "%projPath%\%projName%.pro" TemplateGame %className%
  188. REM Copy CMake files
  189. mkdir "%projPath%\build"
  190. copy "template\template-CMakeLists.txt" "%projPath%\CMakeLists.txt"
  191. call:replace "%projPath%\CMakeLists.txt" TEMPLATE_PROJECT %projName%
  192. call:replace "%projPath%\CMakeLists.txt" TemplateGame %className%
  193. call:replace "%projPath%\CMakeLists.txt" GAMEPLAY_PATH %gpPath%
  194. REM Copy source files
  195. copy template\src\TemplateGame.h "%projPath%\src\%className%.h"
  196. copy template\src\TemplateGame.cpp "%projPath%\src\%className%.cpp"
  197. call:replace "%projPath%\src\%className%.h" TemplateGame "%className%"
  198. call:replace "%projPath%\src\%className%.cpp" TemplateGame "%className%"
  199. REM Copy resource files
  200. copy template\res\* "%projPath%\res\"
  201. REM Copy icon
  202. copy template\icon.png "%projPath%\icon.png"
  203. REM Copy config
  204. copy template\game.config "%projPath%\game.config"
  205. call:replace "%projPath%\game.config" TEMPLATE_TITLE "%title%"
  206. REM Open new project folder
  207. start "" "%projPath%"
  208. goto done
  209. :replace
  210. set rtemp=%~1.rtemp
  211. if exist "%rtemp%" del /Q "%rtemp%"
  212. for /f "tokens=1* eol=€ delims=€]" %%j in ('type "%~1" ^| %windir%\system32\find /V /N ""') do (
  213. set line=%%k
  214. setlocal EnableDelayedExpansion
  215. if "!line!" == "" (
  216. echo.>>"%rtemp%"
  217. ) else (
  218. set linput=!line!
  219. set loutput=!linput:%~2=%~3!
  220. echo.!loutput!>>"%rtemp%"
  221. )
  222. endlocal
  223. )
  224. copy /Y "%rtemp%" "%~1"
  225. del /Q "%rtemp%"
  226. exit /b
  227. goto done
  228. :replacevar
  229. setlocal EnableDelayedExpansion
  230. echo !%~1!>.replacevar.tmp
  231. endlocal
  232. call:replace .replacevar.tmp "%~2" "%~3"
  233. set /p replaced=<.replacevar.tmp
  234. set %~1=%replaced%
  235. del /Q .replacevar.tmp
  236. exit /b
  237. goto done
  238. :makerelative
  239. setlocal EnableDelayedExpansion
  240. set src=%~1
  241. if defined %1 set src=!%~1!
  242. set bas=%~2
  243. if not defined bas set bas=%cd%
  244. for /f "tokens=*" %%a in ("%src%") do set src=%%~fa
  245. for /f "tokens=*" %%a in ("%bas%") do set bas=%%~fa
  246. set mat=&rem variable to store matching part of the name
  247. set upp=&rem variable to reference a parent
  248. for /f "tokens=*" %%a in ('echo.%bas:\=^&echo.%') do (
  249. set sub=!sub!%%a\
  250. call set tmp=%%src:!sub!=%%
  251. if "!tmp!" NEQ "!src!" (set mat=!sub!)ELSE (set upp=!upp!..\)
  252. )
  253. set src=%upp%!src:%mat%=!
  254. ( endlocal & REM RETURN VALUES
  255. IF defined %1 (SET %~1=%src%) ELSE ECHO.%src%
  256. )
  257. exit /b
  258. goto done
  259. :done