newproject.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 " Ex. foobar"
  33. echo
  34. read -p "Project Name: " projName
  35. if [[ "$projName" == "" ]]; then
  36. echo
  37. echo "ERROR: No project name specified."
  38. echo
  39. exit -1;
  40. fi
  41. echo
  42. echo
  43. echo "2. Enter a game title."
  44. echo
  45. echo " On some platforms, this title is used to"
  46. echo " identify the game during installation and"
  47. echo " on shortcuts/icons."
  48. echo " Ex. Foo Bar"
  49. echo
  50. read -p "Title: " title
  51. if [[ "$title" == "" ]]; then
  52. echo
  53. echo "ERROR: No game title specified."
  54. echo
  55. exit -1;
  56. fi
  57. echo
  58. echo
  59. echo "3. Enter a unique identifier for your project."
  60. echo
  61. echo " This should be a human readable package name,"
  62. echo " containing at least two words separated by a"
  63. echo " period."
  64. echo " Ex. com.example.foobar"
  65. echo
  66. read -p "Unique ID: " uuid
  67. if [[ "$uuid" == "" ]]; then
  68. echo
  69. echo "ERROR: No uuid specified."
  70. echo
  71. exit -1;
  72. fi
  73. echo
  74. echo
  75. echo "4. Enter your game's main class name."
  76. echo
  77. echo " Your initial game header and source file"
  78. echo " will be given this name and a class with"
  79. echo " this name will be created in these files."
  80. echo " Ex. FooBarGame"
  81. echo
  82. read -p "Class name: " className
  83. if [[ "$className" == "" ]]; then
  84. echo
  85. echo "ERROR: No class name specified."
  86. echo
  87. exit -1;
  88. fi
  89. echo
  90. echo
  91. echo "5. Enter the project path."
  92. echo
  93. echo " This can be a relative path, absolute path,"
  94. echo " or empty for the current folder. Note that"
  95. echo " a project folder named $projName will also"
  96. echo " be created inside this folder."
  97. echo " Ex. ./samples"
  98. echo
  99. read -p "Path: " location
  100. if [[ "$location" == "" ]]; then
  101. projPath=$projName
  102. else
  103. projPath="$location/$projName"
  104. fi
  105. echo
  106. # Verify Path and eliminate double '//'
  107. projPath=`echo "$projPath" | sed 's_//_/_g'`
  108. if [ -e $projPath ]; then
  109. echo
  110. echo "ERROR: Path '$projPath' already exists, aborting."
  111. echo
  112. exit -2
  113. fi
  114. # Make required source folder directories
  115. mkdir -p "$projPath"
  116. mkdir -p "$projPath/src"
  117. mkdir -p "$projPath/res"
  118. if [[ ${projPath:0:1} != "/" ]]; then
  119. currPwd=`pwd`
  120. projPath=`cd $projPath; pwd`
  121. `cd $currPwd`
  122. fi
  123. # Generate relative path from project folder to gameplay folder
  124. gpPathAbs=`pwd`
  125. common_path=$projPath
  126. back=
  127. while [ "${gpPathAbs#$common_path}" = "${gpPathAbs}" ]; do
  128. common_path=$(dirname "$common_path")
  129. if [ -z "$back" ]; then
  130. back=".."
  131. else
  132. back="../${back}"
  133. fi
  134. done
  135. gpPath=${back}/${gpPathAbs#$common_path/}
  136. if [[ ${gpPathAbs} == ${common_path} ]]; then
  137. gpPath=${back}
  138. fi
  139. #############################################
  140. # Copy Microsoft Visual Studio project files
  141. #############################################
  142. gpPathWin=$(echo $gpPath | sed 's*/*\\\\*g')
  143. cp "template/template.vcxproj" "$projPath/$projName.vcxproj"
  144. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/$projName.vcxproj"
  145. aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj"
  146. aliassedinplace "s*GAMEPLAY_PATH*$gpPathWin*g" "$projPath/$projName.vcxproj"
  147. cp "template/template.vcxproj.filters" "$projPath/$projName.vcxproj.filters"
  148. aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj.filters"
  149. #############################################
  150. # Copy Apple Xcode project files
  151. #############################################
  152. mkdir -p "$projPath/$projName.xcodeproj"
  153. cp "template/template.xcodeproj/project.pbxproj" "$projPath/$projName.xcodeproj/project.pbxproj"
  154. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  155. aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  156. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  157. cp "template/TEMPLATE_PROJECT-macosx.plist" "$projPath/$projName-macosx.plist"
  158. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/$projName-macosx.plist"
  159. cp "template/TEMPLATE_PROJECT-ios.plist" "$projPath/$projName-ios.plist"
  160. cp "template/[email protected]" "$projPath/[email protected]"
  161. aliassedinplace "s*TEMPLATE_TITLE*$title*g" "$projPath/$projName-ios.plist"
  162. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/$projName-ios.plist"
  163. #############################################
  164. # Copy Android NDK project files
  165. #############################################
  166. mkdir -p "$projPath/android"
  167. mkdir -p "$projPath/android/jni"
  168. mkdir -p "$projPath/android/res/values"
  169. mkdir -p "$projPath/android/res/drawable"
  170. cp "template/android/AndroidManifest.xml" "$projPath/android/AndroidManifest.xml"
  171. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/AndroidManifest.xml"
  172. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/android/AndroidManifest.xml"
  173. cp "template/android/build.xml" "$projPath/android/build.xml"
  174. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/build.xml"
  175. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/android/build.xml"
  176. cp "template/android/project.properties" "$projPath/android/project.properties"
  177. cp "template/android/jni/Application.mk" "$projPath/android/jni/Application.mk"
  178. cp "template/android/jni/Android.mk" "$projPath/android/jni/Android.mk"
  179. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/jni/Android.mk"
  180. aliassedinplace "s*TemplateGame*$className*g" "$projPath/android/jni/Android.mk"
  181. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/android/jni/Android.mk"
  182. cp "template/icon.png" "$projPath/android/res/drawable/icon.png"
  183. cp "template/android/res/values/template.strings.xml" "$projPath/android/res/values/strings.xml"
  184. aliassedinplace "s*TEMPLATE_TITLE*$title*g" "$projPath/android/res/values/strings.xml"
  185. #############################################
  186. # Copy Eclipse files for Android
  187. #############################################
  188. cp "template/android/.cproject" "$projPath/android/.cproject"
  189. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/.cproject"
  190. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/android/.cproject"
  191. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/android/.cproject"
  192. cp "template/android/.project" "$projPath/android/.project"
  193. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/.project"
  194. cp "template/android/.classpath" "$projPath/android/.classpath"
  195. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/.classpath"
  196. #############################################
  197. # Copy Eclipse files for Linux
  198. #############################################
  199. cp "template/.cproject" "$projPath/.cproject"
  200. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/.cproject"
  201. aliassedinplace "s*TEMPLATE_UUID*$uuid*g" "$projPath/.cproject"
  202. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/.cproject"
  203. cp "template/.project" "$projPath/.project"
  204. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/.project"
  205. #############################################
  206. # Copy QtCreator files
  207. #############################################
  208. cp "template/TEMPLATE_PROJECT.pro" "$projPath/$projName.pro"
  209. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/$projName.pro"
  210. aliassedinplace "s*TemplateGame*$className*g" "$projPath/$projName.pro"
  211. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.pro"
  212. #############################################
  213. # Copy CMake files
  214. #############################################
  215. cp "template/template-CMakeLists.txt" "$projPath/CMakeLists.txt"
  216. aliassedinplace "s*TEMPLATE_PROJECT*$projName*g" "$projPath/CMakeLists.txt"
  217. aliassedinplace "s*TemplateGame*$className*g" "$projPath/CMakeLists.txt"
  218. aliassedinplace "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/CMakeLists.txt"
  219. #############################################
  220. # Copy source files
  221. #############################################
  222. cp "template/src/TemplateGame.h" "$projPath/src/$className.h"
  223. cp "template/src/TemplateGame.cpp" "$projPath/src/$className.cpp"
  224. aliassedinplace "s*TemplateGame*$className*g" "$projPath/src/$className.h"
  225. aliassedinplace "s*TemplateGame*$className*g" "$projPath/src/$className.cpp"
  226. # Copy resource files
  227. cp "template/res/"* "$projPath/res/"
  228. # Copy icon
  229. cp "template/icon.png" "$projPath/icon.png"
  230. # Copy config
  231. cp "template/game.config" "$projPath/game.config"
  232. aliassedinplace "s*TEMPLATE_TITLE*$title*g" "$projPath/game.config"
  233. # Open the new project folder, use xdg-open on Linux
  234. if [[ "$unamestr" == "Linux" ]]; then
  235. xdg-open "$projPath"
  236. else
  237. open "$projPath"
  238. fi
  239. exit 0