Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Settings.py 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #from bge import logic
  2. import GameLogic
  3. #from os.path import dirname, realpath, join
  4. #BASE_DIR = os.path.join( os.path.dirname( __file__ ), '..' )
  5. mainDir = GameLogic.expandPath("//")
  6. fileName = mainDir + "Settings.dat"
  7. resx = 1280
  8. resy = 720
  9. def readSettings():
  10. import GameLogic
  11. import bge
  12. cont = GameLogic.getCurrentController()
  13. own = cont.owner
  14. scenes = bge.logic.getSceneList()
  15. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  16. own = main_scene.objects['Empty']
  17. with open(fileName) as reading:
  18. #data = [line.split()[0] for line in reading]
  19. data = reading.readlines()
  20. #print lines[25]
  21. #print lines[29]
  22. reading.close()
  23. own["val"] = int(data[1])
  24. own["bright"] = int(data[1])
  25. own["playerName"] = data[4]
  26. #own["audio"] = int(data[3])
  27. own["level"] = data[5]
  28. #data6 = data[6]
  29. #data6.split(None, 1)[0]
  30. #data5 = data5.strip('\n')
  31. #print(data6)
  32. own["resx"] = int(data[7])
  33. own["resy"] = int(data[8])
  34. own["framerate"] = int(data[10])
  35. own["profile"] = int(data[12])
  36. dict = bge.logic.globalDict #Get the global dictionary
  37. dict['resx'] = own["resx"]
  38. dict['resy'] = own["resy"]
  39. level = data[5]
  40. level = level.split(None, 1)[0]
  41. level = str(level)
  42. own["level"] = level
  43. dict["level"] = level
  44. print("reading. settings")
  45. print("Level: ", level)
  46. recorder_on = int(data[14])
  47. print("Game play recorder on: ", recorder_on)
  48. #dict = bge.logic.globalDict
  49. dict['recorder_on'] = recorder_on
  50. own['recorder_on'] = recorder_on
  51. dict['recorder_on'] = recorder_on
  52. dict["shirt_color_r"] = float(data[16])
  53. dict["shirt_color_g"] = float(data[17])
  54. dict["shirt_color_b"] = float(data[18])
  55. dict["shoe_color_r"] = float(data[20])
  56. dict["shoe_color_g"] = float(data[21])
  57. dict["shoe_color_b"] = float(data[22])
  58. dict["deck_color_r"] = float(data[24])
  59. dict["deck_color_g"] = float(data[25])
  60. dict["deck_color_b"] = float(data[26])
  61. dict["shirt_logo"] = int(data[28])
  62. dict["bc"] = int(data[30])
  63. dict["BC_BRIGHTNESS"] = float(data[31])
  64. dict["BC_CONTRAST"] = float(data[32])
  65. dict['hdr'] = int(data[34])
  66. dict['avgL'] = float(data[35])
  67. dict['HDRamount'] = float(data[36])
  68. dict['ao'] = int(data[38])
  69. dict['onlyAO'] = int(data[39])
  70. dict['aowidth'] = float(data[40])
  71. dict['aoradius'] = float(data[41])
  72. dict['dof_on'] = float(data[43])
  73. dict['sun_strength'] = float(data[45])
  74. dict['sun_rot_x'] = float(data[46])
  75. dict['sun_rot_y'] = float(data[47])
  76. dict['shadow_on'] = int(data[48])
  77. dict['ambient_strength'] = float(data[49])
  78. dict['fullscreen_on'] = int(data[51])
  79. dict['bloom_on'] = int(data[53])
  80. dict['cam_height'] = float(data[55])
  81. dict['focal_length'] = int(data[56])
  82. dict['cam_min'] = float(data[57])
  83. dict['cam_max'] = float(data[58])
  84. #print('bc = ', dict['bc'])
  85. #dict['music_player_on'] = int(data[16])
  86. def writeSettings():
  87. import GameLogic
  88. import bge
  89. cont = GameLogic.getCurrentController()
  90. own = cont.owner
  91. scenes = bge.logic.getSceneList()
  92. dict = bge.logic.globalDict
  93. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  94. own = main_scene.objects['Empty']
  95. print("writing called")
  96. with open(fileName, 'w') as writing:
  97. writing.write(str("//settings.dat")+"\n")
  98. writing.write(str(own["val"])+"\n")
  99. writing.write(str(own["bright"])+"\n")
  100. writing.write(str("-\n"))
  101. writing.write(str("//level (e.g. spine, city, city2)")+"\n")
  102. writing.write(str(own["level"])+"\n")
  103. writing.write(str("//resolution")+"\n")
  104. writing.write(str(dict["resx"])+"\n")
  105. writing.write(str(dict["resy"])+"\n")
  106. writing.write(str("//show framerate")+"\n")
  107. writing.write(str(own["framerate"])+"\n")
  108. writing.write(str("//show profile")+"\n")
  109. writing.write(str(own["profile"])+"\n")
  110. writing.write(str("//Game play recorder off/on (0,1)")+"\n")
  111. writing.write(str(own["recorder_on"])+"\n")
  112. writing.write(str("//Shirt color [r,g,b]")+"\n")
  113. writing.write(str(dict["shirt_color_r"])+"\n") #16
  114. writing.write(str(dict["shirt_color_g"])+"\n")
  115. writing.write(str(dict["shirt_color_b"])+"\n") #
  116. writing.write(str("//Shoe color [r,g,b]")+"\n")
  117. writing.write(str(dict["shoe_color_r"])+"\n") #16
  118. writing.write(str(dict["shoe_color_g"])+"\n")
  119. writing.write(str(dict["shoe_color_b"])+"\n") #
  120. writing.write(str("//Deck color [r,g,b]")+"\n")
  121. writing.write(str(dict["deck_color_r"])+"\n") #24
  122. writing.write(str(dict["deck_color_g"])+"\n")
  123. writing.write(str(dict["deck_color_b"])+"\n") #
  124. writing.write(str("//Shirt Logo")+"\n")
  125. writing.write(str(dict["shirt_logo"])+"\n") #24
  126. writing.write(str("//Brightness/Contrast: On, brightness, contrast")+"\n")
  127. writing.write(str(dict["bc"])+"\n")
  128. writing.write(str(dict["BC_BRIGHTNESS"])+"\n")
  129. writing.write(str(dict["BC_CONTRAST"])+"\n")
  130. writing.write(str("//HDR: On, avgL, amount")+"\n")
  131. writing.write(str(dict["hdr"])+"\n")
  132. writing.write(str(dict["avgL"])+"\n")
  133. writing.write(str(dict["HDRamount"])+"\n")
  134. writing.write(str("//AO: On, only, width, radius")+"\n")
  135. writing.write(str(dict["ao"])+"\n")
  136. writing.write(str(dict["onlyAO"])+"\n")
  137. writing.write(str(dict["aowidth"])+"\n")
  138. writing.write(str(dict["aoradius"])+"\n")
  139. writing.write(str("//dof on")+"\n")
  140. writing.write(str(dict["dof_on"])+"\n")
  141. writing.write(str("//sun settings: strength, rotx, roty, shadow on, ambient strength")+"\n")
  142. writing.write(str(dict["sun_strength"])+"\n")
  143. writing.write(str(dict["sun_rot_x"])+"\n")
  144. writing.write(str(dict["sun_rot_y"])+"\n")
  145. writing.write(str(dict["shadow_on"])+"\n")
  146. writing.write(str(dict["ambient_strength"])+"\n")
  147. writing.write(str("//fullscreen on (0,1)")+"\n")
  148. writing.write(str(dict["fullscreen_on"])+"\n")
  149. writing.write(str("//bloom on (0,1)")+"\n")
  150. writing.write(str(dict["bloom_on"])+"\n")
  151. writing.write(str("//cam")+"\n")
  152. writing.write(str(dict["cam_height"])+"\n")
  153. writing.write(str(dict["focal_length"])+"\n")
  154. writing.write(str(dict["cam_min"])+"\n")
  155. writing.write(str(dict["cam_max"])+"\n")
  156. #writing.write(str(own["framerate"])+"\n")
  157. print("writing settings")
  158. writing.close()
  159. def setres():
  160. import GameLogic
  161. import bge
  162. scenes = bge.logic.getSceneList()
  163. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  164. own = main_scene.objects['Empty']
  165. cont = GameLogic.getCurrentController()
  166. own2 = cont.owner
  167. dict = bge.logic.globalDict
  168. resx = dict["resx"]
  169. resy = dict["resy"]
  170. fullscreen = bge.render.getFullScreen()
  171. print("fullscreen = ", fullscreen)
  172. if fullscreen != True:
  173. if dict['fullscreen_on'] == 1:
  174. bge.render.setFullScreen(True)
  175. if fullscreen == True:
  176. if dict['fullscreen_on'] == 0:
  177. bge.render.setFullScreen(False)
  178. bge.render.setWindowSize(resx, resy)
  179. print("resolution = ", resx, resy)
  180. def loadlevel():
  181. import GameLogic
  182. import bge
  183. scenes = bge.logic.getSceneList()
  184. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  185. own = main_scene.objects['Empty']
  186. cont = GameLogic.getCurrentController()
  187. own2 = cont.owner
  188. #readSettings()
  189. dict = bge.logic.globalDict #Get the global dictionary
  190. # resx = dict["resx"]
  191. # resy = dict["resy"]
  192. # #dict['resx'] = resx
  193. # #dict['resy'] = resy
  194. #
  195. # fullscreen = bge.render.getFullScreen()
  196. # print("fullscreen = ", fullscreen)
  197. # if fullscreen != True:
  198. # if dict['fullscreen_on'] == 1:
  199. # bge.render.setFullScreen(True)
  200. # if fullscreen == True:
  201. # if dict['fullscreen_on'] == 0:
  202. # bge.render.setFullScreen(False)
  203. #
  204. # bge.render.setWindowSize(resx, resy)
  205. # print("resolution = ", resx, resy)
  206. #objList = scene.objects
  207. if own["framerate"] == 1:
  208. bge.render.showFramerate(1)
  209. if own["profile"] ==1:
  210. bge.render.showProfile(1)
  211. #cont = GameLogic.getCurrentController()
  212. #own = cont.owner
  213. #cont = own2.controllers['loadLevel']
  214. act = own2.actuators["level"]
  215. #cont.activate(own.actuators["loading"])
  216. #level = own["level"]
  217. dict = bge.logic.globalDict
  218. level = dict['level']
  219. #dict['level'] = level
  220. act.scene = level
  221. cont.activate(own2.actuators["level"])
  222. #cont.activate(own2.actuators["stance"])
  223. dict['npause'] = False
  224. def timer():
  225. import GameLogic
  226. import bge
  227. dict = bge.logic.globalDict
  228. if dict['reload_timer'] == 1:
  229. #restart
  230. # get current scene
  231. scene = bge.logic.getCurrentScene()
  232. # restart the current scene
  233. #scene.restart()
  234. if dict['reload_timer'] > 0:
  235. dict['reload_timer'] -= 1
  236. #print(dict['reload_timer'])
  237. #own['reload_timer'] = dict['reload_timer']