newproject.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. #!/bin/bash
  2. # ********************************************************************
  3. #
  4. # newproject.sh
  5. #
  6. # This script generates a set of gameplay project files.
  7. # The new project will be based of the template project and
  8. # it will be generated with the name and location that is specified
  9. # as input parameters.
  10. #
  11. # IMPORTANT: This script must be run from the root of the gameplay
  12. # source tree.
  13. #
  14. # ********************************************************************
  15. #Find out which OS we're on.
  16. unamestr=$(uname)
  17. # Switch-on alias expansion within the script
  18. shopt -s expand_aliases
  19. #Alias the sed in-place command for OSX and Linux - incompatibilities between BSD and Linux sed args
  20. if [[ "$unamestr" == "Darwin" ]]; then
  21. alias aliassedinplace='sed -i ""'
  22. else
  23. #For Linux, notice no space after the '-i'
  24. alias aliassedinplace='sed -i""'
  25. fi
  26. echo
  27. echo "1. Enter a name for the new project."
  28. echo
  29. echo " This name will be given to the project"
  30. echo " executable and a folder with this name"
  31. echo " will be created to store all project files."
  32. echo
  33. read -p "Project Name: " projName
  34. if [[ "$projName" == "" ]]; then
  35. echo
  36. echo "ERROR: No project name specified."
  37. echo
  38. exit -1;
  39. fi
  40. echo
  41. echo
  42. echo "2. Enter a game title."
  43. echo
  44. echo " On some platforms, this title is used to"
  45. echo " identify the game during installation and"
  46. echo " on shortcuts/icons."
  47. echo
  48. read -p "Title: " title
  49. if [[ "$title" == "" ]]; then
  50. echo
  51. echo "ERROR: No game title specified."
  52. echo
  53. exit -1;
  54. fi
  55. echo
  56. echo
  57. echo "3. Enter a short game description."
  58. echo
  59. read -p "Description: " desc
  60. if [[ "$desc" == "" ]]; then
  61. desc=$title
  62. fi
  63. echo
  64. echo
  65. echo "4. Enter a unique identifier for your project."
  66. echo
  67. echo " This should be a human readable package name,"
  68. echo " containing at least two words separated by a"
  69. echo " period (eg. com.surname.gamename)."
  70. echo
  71. read -p "Unique ID: " uuid
  72. if [[ "$uuid" == "" ]]; then
  73. echo
  74. echo "ERROR: No uuid specified."
  75. echo
  76. exit -1;
  77. fi
  78. echo
  79. echo
  80. echo "5. Enter author name."
  81. echo
  82. echo " On BlackBerry targets, this is used for"
  83. echo " signing and must match the developer name"
  84. echo " of your development certificate."
  85. echo
  86. read -p "Author: " author
  87. if [[ "$author" == "" ]]; then
  88. echo
  89. echo "ERROR: No author specified."
  90. echo
  91. exit -1;
  92. fi
  93. echo
  94. echo
  95. echo "6. Enter your game's main class name."
  96. echo
  97. echo " Your initial game header and source file"
  98. echo " will be given this name and a class with"
  99. echo " this name will be created in these files."
  100. echo
  101. read -p "Class name: " className
  102. if [[ "$className" == "" ]]; then
  103. echo
  104. echo "ERROR: No class name specified."
  105. echo
  106. exit -1;
  107. fi
  108. echo
  109. echo
  110. echo "7. Enter the project path."
  111. echo
  112. echo " This can be a relative path, absolute path,"
  113. echo " or empty for the current folder. Note that"
  114. echo " a project folder named $projName will also"
  115. echo " be created inside this folder."
  116. echo
  117. read -p "Path: " location
  118. if [[ "$location" == "" ]]; then
  119. projPath=$projName
  120. else
  121. projPath="$location/$projName"
  122. fi
  123. echo
  124. # Verify Path and eliminate double '//'
  125. projPath=`echo "$projPath" | sed 's_//_/_g'`
  126. if [ -e $projPath ]; then
  127. echo
  128. echo "ERROR: Path '$projPath' already exists, aborting."
  129. echo
  130. exit -2
  131. fi
  132. # Make required source folder directories
  133. mkdir -p "$projPath"
  134. mkdir -p "$projPath/src"
  135. mkdir -p "$projPath/res"
  136. if [[ ${projPath:0:1} != "/" ]]; then
  137. currPwd=`pwd`
  138. projPath=`cd $projPath; pwd`
  139. `cd $currPwd`
  140. fi
  141. # Generate relative path from project folder to gameplay folder
  142. gpPathAbs=`pwd`
  143. common_path=$projPath
  144. back=
  145. while [ "${gpPathAbs#$common_path}" = "${gpPathAbs}" ]; do
  146. common_path=$(dirname "$common_path")
  147. if [ -z "$back" ]; then
  148. back=".."
  149. else
  150. back="../${back}"
  151. fi
  152. done
  153. gpPath=${back}/${gpPathAbs#$common_path/}
  154. if [[ ${gpPathAbs} == ${common_path} ]]; then
  155. gpPath=${back}
  156. fi
  157. #############################################
  158. # Copy Microsoft Visual Studio project files
  159. #############################################
  160. cp "template/template.vcxproj" "$projPath/$projName.vcxproj"
  161. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/$projName.vcxproj"
  162. aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj"
  163. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.vcxproj"
  164. cp "template/template.vcxproj.filters" "$projPath/$projName.vcxproj.filters"
  165. aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj.filters"
  166. cp "template/template.vcxproj.user" "$projPath/$projName.vcxproj.user"
  167. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.vcxproj.user"
  168. #############################################
  169. # Copy Apple Xcode project files
  170. #############################################
  171. mkdir -p "$projPath/$projName.xcodeproj"
  172. cp "template/template.xcodeproj/project.pbxproj" "$projPath/$projName.xcodeproj/project.pbxproj"
  173. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  174. aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  175. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  176. cp "template/TEMPLATE_PROJECT-macosx.plist" "$projPath/$projName-macosx.plist"
  177. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/$projName-macosx.plist"
  178. aliassedinplace "s*TEMPLATE_AUTHOR*$author*g" "$projPath/$projName-macosx.plist"
  179. cp "template/TEMPLATE_PROJECT-ios.plist" "$projPath/$projName-ios.plist"
  180. cp "template/[email protected]" "$projPath/[email protected]"
  181. aliassedinplace "s*TEMPLATE_TITLE*$title*g" "$projPath/$projName-ios.plist"
  182. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/$projName-ios.plist"
  183. aliassedinplace "s*TEMPLATE_AUTHOR*$author*g" "$projPath/$projName-ios.plist"
  184. #############################################
  185. # Copy BlackBerry NDK project files
  186. #############################################
  187. cp "template/template.cproject" "$projPath/.cproject"
  188. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/.cproject"
  189. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/.cproject"
  190. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/.cproject"
  191. cp "template/template.project" "$projPath/.project"
  192. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/.project"
  193. cp "template/template.bar-descriptor.xml" "$projPath/bar-descriptor.xml"
  194. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/bar-descriptor.xml"
  195. aliassedinplace "s*TEMPLATE_TITLE*$title*g" "$projPath/bar-descriptor.xml"
  196. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/bar-descriptor.xml"
  197. aliassedinplace "s*TEMPLATE_AUTHOR*$author*g" "$projPath/bar-descriptor.xml"
  198. aliassedinplace "s*TEMPLATE_DESCRIPTION*$desc*g" "$projPath/bar-descriptor.xml"
  199. #############################################
  200. # Copy Android NDK project files
  201. #############################################
  202. mkdir -p "$projPath/android"
  203. mkdir -p "$projPath/android/jni"
  204. mkdir -p "$projPath/android/res/values"
  205. mkdir -p "$projPath/android/res/drawable"
  206. cp "template/android/template.AndroidManifest.xml" "$projPath/android/AndroidManifest.xml"
  207. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/AndroidManifest.xml"
  208. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/android/AndroidManifest.xml"
  209. cp "template/android/template.build.xml" "$projPath/android/build.xml"
  210. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/build.xml"
  211. cp "template/android/jni/Application.mk" "$projPath/android/jni/Application.mk"
  212. cp "template/android/jni/template.Android.mk" "$projPath/android/jni/Android.mk"
  213. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/jni/Android.mk"
  214. aliassedinplace "s*TemplateGame*$className*g" "$projPath/android/jni/Android.mk"
  215. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/android/jni/Android.mk"
  216. cp "template/icon.png" "$projPath/android/res/drawable/icon.png"
  217. cp "template/android/res/values/template.strings.xml" "$projPath/android/res/values/strings.xml"
  218. aliassedinplace "s*TEMPLATE_TITLE*$title*g" "$projPath/android/res/values/strings.xml"
  219. #############################################
  220. # Copy CMake files
  221. #############################################
  222. mkdir -p "$projPath/build"
  223. cp "template/template-CMakeLists.txt" "$projPath/CMakeLists.txt"
  224. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/CMakeLists.txt"
  225. aliassedinplace "s*TemplateGame*$className*g" "$projPath/CMakeLists.txt"
  226. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/CMakeLists.txt"
  227. #############################################
  228. # Copy source files
  229. #############################################
  230. cp "template/src/TemplateGame.h" "$projPath/src/$className.h"
  231. cp "template/src/TemplateGame.cpp" "$projPath/src/$className.cpp"
  232. aliassedinplace "s*TemplateGame*$className*g" "$projPath/src/$className.h"
  233. aliassedinplace "s*TemplateGame*$className*g" "$projPath/src/$className.cpp"
  234. # Copy resource files
  235. cp "template/res/"* "$projPath/res/"
  236. # Copy icon
  237. cp "template/icon.png" "$projPath/icon.png"
  238. # Copy config
  239. cp "template/game.config" "$projPath/game.config"
  240. aliassedinplace "s*TEMPLATE_TITLE*$title*g" "$projPath/game.config"
  241. # Open the new project folder, use xdg-open on Linux
  242. if [[ "$unamestr" == "Linux" ]]; then
  243. xdg-open "$projPath"
  244. else
  245. open "$projPath"
  246. fi
  247. exit 0