gameplay-newproject.bat 9.2 KB

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