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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. dict['music_player'] = int(data[60])
  85. #print('bc = ', dict['bc'])
  86. #dict['music_player_on'] = int(data[16])
  87. def writeSettings():
  88. import GameLogic
  89. import bge
  90. cont = GameLogic.getCurrentController()
  91. own = cont.owner
  92. scenes = bge.logic.getSceneList()
  93. dict = bge.logic.globalDict
  94. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  95. own = main_scene.objects['Empty']
  96. print("writing called")
  97. with open(fileName, 'w') as writing:
  98. writing.write(str("//settings.dat")+"\n")
  99. writing.write(str(own["val"])+"\n")
  100. writing.write(str(own["bright"])+"\n")
  101. writing.write(str("-\n"))
  102. writing.write(str("//level (e.g. spine, city, city2)")+"\n")
  103. writing.write(str(own["level"])+"\n")
  104. writing.write(str("//resolution")+"\n")
  105. writing.write(str(dict["resx"])+"\n")
  106. writing.write(str(dict["resy"])+"\n")
  107. writing.write(str("//show framerate")+"\n")
  108. writing.write(str(own["framerate"])+"\n")
  109. writing.write(str("//show profile")+"\n")
  110. writing.write(str(own["profile"])+"\n")
  111. writing.write(str("//Game play recorder off/on (0,1)")+"\n")
  112. writing.write(str(own["recorder_on"])+"\n")
  113. writing.write(str("//Shirt color [r,g,b]")+"\n")
  114. writing.write(str(dict["shirt_color_r"])+"\n") #16
  115. writing.write(str(dict["shirt_color_g"])+"\n")
  116. writing.write(str(dict["shirt_color_b"])+"\n") #
  117. writing.write(str("//Shoe color [r,g,b]")+"\n")
  118. writing.write(str(dict["shoe_color_r"])+"\n") #16
  119. writing.write(str(dict["shoe_color_g"])+"\n")
  120. writing.write(str(dict["shoe_color_b"])+"\n") #
  121. writing.write(str("//Deck color [r,g,b]")+"\n")
  122. writing.write(str(dict["deck_color_r"])+"\n") #24
  123. writing.write(str(dict["deck_color_g"])+"\n")
  124. writing.write(str(dict["deck_color_b"])+"\n") #
  125. writing.write(str("//Shirt Logo")+"\n")
  126. writing.write(str(dict["shirt_logo"])+"\n") #24
  127. writing.write(str("//Brightness/Contrast: On, brightness, contrast")+"\n")
  128. writing.write(str(dict["bc"])+"\n")
  129. writing.write(str(dict["BC_BRIGHTNESS"])+"\n")
  130. writing.write(str(dict["BC_CONTRAST"])+"\n")
  131. writing.write(str("//HDR: On, avgL, amount")+"\n")
  132. writing.write(str(dict["hdr"])+"\n")
  133. writing.write(str(dict["avgL"])+"\n")
  134. writing.write(str(dict["HDRamount"])+"\n")
  135. writing.write(str("//AO: On, only, width, radius")+"\n")
  136. writing.write(str(dict["ao"])+"\n")
  137. writing.write(str(dict["onlyAO"])+"\n")
  138. writing.write(str(dict["aowidth"])+"\n")
  139. writing.write(str(dict["aoradius"])+"\n")
  140. writing.write(str("//dof on")+"\n")
  141. writing.write(str(dict["dof_on"])+"\n")
  142. writing.write(str("//sun settings: strength, rotx, roty, shadow on, ambient strength")+"\n")
  143. writing.write(str(dict["sun_strength"])+"\n")
  144. writing.write(str(dict["sun_rot_x"])+"\n")
  145. writing.write(str(dict["sun_rot_y"])+"\n")
  146. writing.write(str(dict["shadow_on"])+"\n")
  147. writing.write(str(dict["ambient_strength"])+"\n")
  148. writing.write(str("//fullscreen on (0,1)")+"\n")
  149. writing.write(str(dict["fullscreen_on"])+"\n")
  150. writing.write(str("//bloom on (0,1)")+"\n")
  151. writing.write(str(dict["bloom_on"])+"\n")
  152. writing.write(str("//cam")+"\n")
  153. writing.write(str(dict["cam_height"])+"\n")
  154. writing.write(str(dict["focal_length"])+"\n")
  155. writing.write(str(dict["cam_min"])+"\n")
  156. writing.write(str(dict["cam_max"])+"\n")
  157. writing.write(str("//music player on / off")+"\n")
  158. writing.write(str(dict["music_player"])+"\n")
  159. #writing.write(str(own["framerate"])+"\n")
  160. print("writing settings")
  161. writing.close()
  162. def setres():
  163. import GameLogic
  164. import bge
  165. scenes = bge.logic.getSceneList()
  166. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  167. own = main_scene.objects['Empty']
  168. cont = GameLogic.getCurrentController()
  169. own2 = cont.owner
  170. dict = bge.logic.globalDict
  171. resx = dict["resx"]
  172. resy = dict["resy"]
  173. fullscreen = bge.render.getFullScreen()
  174. print("fullscreen = ", fullscreen)
  175. if fullscreen != True:
  176. if dict['fullscreen_on'] == 1:
  177. bge.render.setFullScreen(True)
  178. if fullscreen == True:
  179. if dict['fullscreen_on'] == 0:
  180. bge.render.setFullScreen(False)
  181. bge.render.setWindowSize(resx, resy)
  182. print("resolution = ", resx, resy)
  183. def loadlevel():
  184. import GameLogic
  185. import bge
  186. scenes = bge.logic.getSceneList()
  187. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  188. own = main_scene.objects['Empty']
  189. cont = GameLogic.getCurrentController()
  190. own2 = cont.owner
  191. #readSettings()
  192. dict = bge.logic.globalDict #Get the global dictionary
  193. # resx = dict["resx"]
  194. # resy = dict["resy"]
  195. # #dict['resx'] = resx
  196. # #dict['resy'] = resy
  197. #
  198. # fullscreen = bge.render.getFullScreen()
  199. # print("fullscreen = ", fullscreen)
  200. # if fullscreen != True:
  201. # if dict['fullscreen_on'] == 1:
  202. # bge.render.setFullScreen(True)
  203. # if fullscreen == True:
  204. # if dict['fullscreen_on'] == 0:
  205. # bge.render.setFullScreen(False)
  206. #
  207. # bge.render.setWindowSize(resx, resy)
  208. # print("resolution = ", resx, resy)
  209. #objList = scene.objects
  210. if own["framerate"] == 1:
  211. bge.render.showFramerate(1)
  212. if own["profile"] ==1:
  213. bge.render.showProfile(1)
  214. #cont = GameLogic.getCurrentController()
  215. #own = cont.owner
  216. #cont = own2.controllers['loadLevel']
  217. act = own2.actuators["level"]
  218. #cont.activate(own.actuators["loading"])
  219. #level = own["level"]
  220. dict = bge.logic.globalDict
  221. level = dict['level']
  222. #dict['level'] = level
  223. act.scene = level
  224. cont.activate(own2.actuators["level"])
  225. #cont.activate(own2.actuators["stance"])
  226. dict['npause'] = False
  227. def timer():
  228. import GameLogic
  229. import bge
  230. dict = bge.logic.globalDict
  231. if dict['reload_timer'] == 1:
  232. #restart
  233. # get current scene
  234. scene = bge.logic.getCurrentScene()
  235. # restart the current scene
  236. #scene.restart()
  237. if dict['reload_timer'] > 0:
  238. dict['reload_timer'] -= 1
  239. #print(dict['reload_timer'])
  240. #own['reload_timer'] = dict['reload_timer']