gameplay-newproject.sh 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #/bin/bash
  2. # ********************************************************************
  3. #
  4. # generate-project.sh
  5. #
  6. # This script generates a set of gameplay project files.
  7. # The new project will be based of the gameplay-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. 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. read -p "Project Name: " projName
  23. if [[ "$projName" == "" ]]; then
  24. echo
  25. echo "ERROR: No project name specified."
  26. echo
  27. exit -1;
  28. fi
  29. echo
  30. echo
  31. echo "2. Enter a game title."
  32. echo
  33. echo " On some platforms, this title is used to"
  34. echo " identify the game during installation and"
  35. echo " on shortcuts/icons."
  36. echo
  37. read -p "Title: " title
  38. if [[ "$title" == "" ]]; then
  39. echo
  40. echo "ERROR: No game title specified."
  41. echo
  42. exit -1;
  43. fi
  44. echo
  45. echo
  46. echo "3. Enter a short game description."
  47. echo
  48. read -p "Description: " desc
  49. if [[ "$desc" == "" ]]; then
  50. desc=$title
  51. fi
  52. echo
  53. echo
  54. echo "4. Enter a unique identifier for your project."
  55. echo
  56. echo " This should be a human readable package name,"
  57. echo " containing at least two words separated by a"
  58. echo " period (eg. com.surname.gamename)."
  59. echo
  60. read -p "Unique ID: " uuid
  61. if [[ "$uuid" == "" ]]; then
  62. echo
  63. echo "ERROR: No uuid specified."
  64. echo
  65. exit -1;
  66. fi
  67. echo
  68. echo
  69. echo "5. Enter author name."
  70. echo
  71. echo " On BlackBerry targets, this is used for"
  72. echo " signing and must match the developer name"
  73. echo " of your development certificate."
  74. echo
  75. read -p "Author: " author
  76. if [[ "$author" == "" ]]; then
  77. echo
  78. echo "ERROR: No author specified."
  79. echo
  80. exit -1;
  81. fi
  82. echo
  83. echo
  84. echo "6. Enter your game's main class name."
  85. echo
  86. echo " Your initial game header and source file"
  87. echo " will be given this name and a class with"
  88. echo " this name will be created in these files."
  89. echo
  90. read -p "Class name: " className
  91. if [[ "$className" == "" ]]; then
  92. echo
  93. echo "ERROR: No class name specified."
  94. echo
  95. exit -1;
  96. fi
  97. echo
  98. echo
  99. echo "7. Enter the project path."
  100. echo
  101. echo " This can be a relative path, absolute path,"
  102. echo " or empty for the current folder. Note that"
  103. echo " a project folder named $projName will also"
  104. echo " be created inside this folder."
  105. echo
  106. read -p "Path: " location
  107. if [[ "$location" == "" ]]; then
  108. projPath=$projName
  109. else
  110. projPath="$location/$projName"
  111. fi
  112. echo
  113. # Verify Path and eliminate double '//'
  114. projPath=`echo "$projPath" | sed 's_//_/_g'`
  115. if [ -e $projPath ]; then
  116. echo
  117. echo "ERROR: Path '$projPath' already exists, aborting."
  118. echo
  119. exit -2
  120. fi
  121. # Make required source folder directories
  122. mkdir -p "$projPath"
  123. mkdir -p "$projPath/src"
  124. mkdir -p "$projPath/res"
  125. if [[ ${projPath:0:1} != "/" ]]; then
  126. currPwd=`pwd`
  127. projPath=`cd $projPath; pwd`
  128. `cd $currPwd`
  129. fi
  130. # Generate relative path from project folder to gameplay folder
  131. gpPathAbs=`pwd`
  132. common_path=$projPath
  133. back=
  134. while [ "${gpPathAbs#$common_path}" = "${gpPathAbs}" ]; do
  135. common_path=$(dirname $common_path)
  136. back="../${back}"
  137. done
  138. gpPath=${back}${gpPathAbs#$common_path/}
  139. if [[ ${gpPathAbs} == ${common_path} ]]; then
  140. gpPath=${back}
  141. fi
  142. #############################################
  143. # Copy Microsoft Visual Studio project files
  144. #############################################
  145. cp "gameplay-template/gameplay-template.vcxproj" "$projPath/$projName.vcxproj"
  146. sed -i "" "s*TEMPLATE_PROJECT*$projectName*g" "$projPath/$projName.vcxproj"
  147. sed -i "" "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj"
  148. sed -i "" "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.vcxproj"
  149. cp "gameplay-template/gameplay-template.vcxproj.filters" "$projPath/$projName.vcxproj.filters"
  150. sed -i "" "s*TemplateGame*$className*g" "$projPath/$projName.vcxproj.filters"
  151. cp "gameplay-template/gameplay-template.vcxproj.user" "$projPath/$projName.vcxproj.user"
  152. sed -i "" "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.vcxproj.user"
  153. #############################################
  154. # Copy Apple Xcode project files
  155. #############################################
  156. mkdir -p "$projPath/$projName.xcodeproj"
  157. cp "gameplay-template/gameplay-template.xcodeproj/project.pbxproj" "$projPath/$projName.xcodeproj/project.pbxproj"
  158. sed -i "" "s*TEMPLATE_PROJECT*$projName*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  159. sed -i "" "s*TemplateGame*$className*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  160. sed -i "" "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/$projName.xcodeproj/project.pbxproj"
  161. cp "gameplay-template/TEMPLATE_PROJECT-macosx.plist" "$projPath/$projName-macosx.plist"
  162. sed -i "" "s*TEMPLATE_UUID*$uuid*g" "$projPath/$projName-macosx.plist"
  163. sed -i "" "s*TEMPLATE_AUTHOR*$author*g" "$projPath/$projName-macosx.plist"
  164. cp "gameplay-template/TEMPLATE_PROJECT-ios.plist" "$projPath/$projName-ios.plist"
  165. sed -i "" "s*TEMPLATE_TITLE*$title*g" "$projPath/$projName-ios.plist"
  166. sed -i "" "s*TEMPLATE_UUID*$uuid*g" "$projPath/$projName-ios.plist"
  167. sed -i "" "s*TEMPLATE_AUTHOR*$author*g" "$projPath/$projName-ios.plist"
  168. #############################################
  169. # Copy BlackBerry NDK project files
  170. #############################################
  171. cp "gameplay-template/template.cproject" "$projPath/.cproject"
  172. sed -i "" "s*TEMPLATE_PROJECT*$projName*g" "$projPath/.cproject"
  173. sed -i "" "s*TEMPLATE_UUID*$uuid*g" "$projPath/.cproject"
  174. sed -i "" "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/.cproject"
  175. cp "gameplay-template/template.project" "$projPath/.project"
  176. sed -i "" "s*TEMPLATE_PROJECT*$projName*g" "$projPath/.project"
  177. cp "gameplay-template/template.bar-descriptor.xml" "$projPath/bar-descriptor.xml"
  178. sed -i "" "s*TEMPLATE_PROJECT*$projName*g" "$projPath/bar-descriptor.xml"
  179. sed -i "" "s*TEMPLATE_TITLE*$title*g" "$projPath/bar-descriptor.xml"
  180. sed -i "" "s*TEMPLATE_UUID*$uuid*g" "$projPath/bar-descriptor.xml"
  181. sed -i "" "s*TEMPLATE_AUTHOR*$author*g" "$projPath/bar-descriptor.xml"
  182. sed -i "" "s*TEMPLATE_DESCRIPTION*$desc*g" "$projPath/bar-descriptor.xml"
  183. #############################################
  184. # Copy Android NDK project files
  185. #############################################
  186. mkdir -p "$projPath/android"
  187. mkdir -p "$projPath/android/jni"
  188. mkdir -p "$projPath/android/res/values"
  189. mkdir -p "$projPath/android/res/drawable"
  190. cp "gameplay-template/android/template.AndroidManifest.xml" "$projPath/android/AndroidManifest.xml"
  191. sed -i "" "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/AndroidManifest.xml"
  192. sed -i "" "s*TEMPLATE_UUID*$uuid*g" "$projPath/android/AndroidManifest.xml"
  193. cp "gameplay-template/android/template.build.xml" "$projPath/android/build.xml"
  194. sed -i "" "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/build.xml"
  195. cp "gameplay-template/android/jni/Application.mk" "$projPath/android/jni/Application.mk"
  196. cp "gameplay-template/android/jni/template.Android.mk" "$projPath/android/jni/Android.mk"
  197. sed -i "" "s*TEMPLATE_PROJECT*$projName*g" "$projPath/android/jni/Android.mk"
  198. sed -i "" "s*TemplateGame*$className*g" "$projPath/android/jni/Android.mk"
  199. sed -i "" "s*GAMEPLAY_PATH*$gpPath*g" "$projPath/android/jni/Android.mk"
  200. cp "gameplay-template/icon.png" "$projPath/android/res/drawable/icon.png"
  201. cp "gameplay-template/android/res/values/template.strings.xml" "$projPath/android/res/values/strings.xml"
  202. sed -i "" "s*TEMPLATE_TITLE*$title*g" "$projPath/android/res/values/strings.xml"
  203. #############################################
  204. # Copy source files
  205. #############################################
  206. cp "gameplay-template/src/TemplateGame.h" "$projPath/src/$className.h"
  207. cp "gameplay-template/src/TemplateGame.cpp" "$projPath/src/$className.cpp"
  208. sed -i "" "s*TemplateGame*$className*g" "$projPath/src/$className.h"
  209. sed -i "" "s*TemplateGame*$className*g" "$projPath/src/$className.cpp"
  210. # Copy resource files
  211. cp "gameplay-template/res/"* "$projPath/res/"
  212. # Copy icon
  213. cp "gameplay-template/icon.png" "$projPath/icon.png"
  214. # Open the new project folder
  215. open $projPath
  216. exit 0