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 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import bge
  2. import GameLogic
  3. import configobj
  4. from configobj import ConfigObj
  5. mainDir = GameLogic.expandPath("//")
  6. fileName = mainDir + "config.ini"
  7. config = ConfigObj(fileName, interpolation=True)
  8. dict = bge.logic.globalDict
  9. #map_config = {}
  10. print('###############start game##########')
  11. dict['music_player'] = 1
  12. def to_dict3(section, key):
  13. #dict = bge.logic.globalDict
  14. print(section, key)
  15. #d = dict['map']
  16. fileName2 = GameLogic.expandPath("//assets/maps/" + dict['map'] + '/map_settings.ini')
  17. map_config = ConfigObj(fileName2, interpolation=True)
  18. value = map_config[key]
  19. if isinstance(value, str):
  20. if value.isdigit():
  21. value = int(value)
  22. else:
  23. try:
  24. value = float(value)
  25. except:
  26. pass
  27. #print(dict['mapDict'])
  28. dict[key] = value
  29. def to_dict(section, key):
  30. dict = bge.logic.globalDict
  31. value = config[key]
  32. if isinstance(value, str):
  33. if value.isdigit():
  34. value = int(value)
  35. else:
  36. try:
  37. value = float(value)
  38. except:
  39. pass
  40. dict[key] = value
  41. def readMap():
  42. fileName = GameLogic.expandPath("//assets/maps/" + dict['map'] + '/map_settings.ini')
  43. #fileName = mainDir + dict['character'] + ".ini"
  44. #print('loading character settings', fileName)
  45. map_config = ConfigObj(fileName, interpolation=True)
  46. print('map_config', map_config)
  47. dict['mapDict'] = map_config
  48. # def to_dict2(section, key):
  49. # #dict = bge.logic.globalDict
  50. # value = map_config[key]
  51. # if isinstance(value, str):
  52. # if value.isdigit():
  53. # value = int(value)
  54. # else:
  55. # try:
  56. # value = float(value)
  57. # except:
  58. # pass
  59. # dict[key] = value
  60. def readChar():
  61. mainDir = GameLogic.expandPath("//characters/")
  62. fileName = mainDir + dict['character'] + ".ini"
  63. #print('loading character settings', fileName)
  64. char_config = ConfigObj(fileName, interpolation=True)
  65. def to_dict2(section, key):
  66. #dict = bge.logic.globalDict
  67. value = char_config[key]
  68. if isinstance(value, str):
  69. if value.isdigit():
  70. value = int(value)
  71. else:
  72. try:
  73. value = float(value)
  74. except:
  75. pass
  76. dict[key] = value
  77. #print(key, value)
  78. char_config.walk(to_dict2, char_config)
  79. def writeChar():
  80. #dict = bge.logic.globalDict
  81. mainDir = GameLogic.expandPath("//characters/")
  82. fileName = mainDir + dict['character'] + ".ini"
  83. print('writing character settings', fileName)
  84. char_config = ConfigObj(fileName, interpolation=True)
  85. def from_dict2(section, key):
  86. char_config[key] = dict[key]
  87. char_config.walk(from_dict2)
  88. #char_config[key] = dict[key]
  89. char_config.write()
  90. def readSettings():
  91. config.walk(to_dict)
  92. dict['mapDict'] = {}
  93. fileName2 = GameLogic.expandPath("//assets/maps/" + dict['map'] + '/map_settings.ini')
  94. map_config = ConfigObj(fileName2, interpolation=True)
  95. map_config.walk(to_dict3)
  96. #readMap()
  97. readChar()
  98. def from_dict(section, key):
  99. #dict = bge.logic.globalDict
  100. config[key] = dict[key]
  101. def writeSettings():
  102. config.walk(from_dict)
  103. config.write()
  104. #dict = bge.logic.globalDict
  105. def setres():
  106. #import GameLogic
  107. #import bge
  108. scenes = bge.logic.getSceneList()
  109. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  110. own = main_scene.objects['Empty']
  111. cont = bge.logic.getCurrentController()
  112. own2 = cont.owner
  113. dict = bge.logic.globalDict
  114. resx = int(dict["resx"])
  115. resy = int(dict["resy"])
  116. fullscreen = bge.render.getFullScreen()
  117. #print("fullscreen = ", fullscreen)
  118. if fullscreen != True:
  119. if dict['fullscreen_on'] == 1:
  120. bge.render.setFullScreen(True)
  121. if fullscreen == True:
  122. if dict['fullscreen_on'] == 0:
  123. bge.render.setFullScreen(False)
  124. bge.render.setWindowSize(resx, resy)
  125. bge.render.setVsync(dict['vsync_on']) #doesn't work?
  126. #print("resolution = ", resx, resy)
  127. def loadlevel():
  128. scenes = bge.logic.getSceneList()
  129. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  130. own = main_scene.objects['Empty']
  131. cont = GameLogic.getCurrentController()
  132. own2 = cont.owner
  133. dict = bge.logic.globalDict #Get the global dictionary
  134. dict['scene_inited'] = False
  135. if own["framerate"] == 1:
  136. bge.render.showFramerate(1)
  137. if own["profile"] ==1:
  138. bge.render.showProfile(1)
  139. act = own2.actuators["level"]
  140. #dict = bge.logic.globalDict
  141. fileName2 = GameLogic.expandPath("//assets/maps/" + dict['map'] + '/map_settings.ini')
  142. map_config = ConfigObj(fileName2, interpolation=True)
  143. map_config.walk(to_dict3)
  144. level = dict['map_template']
  145. dict['level'] = level
  146. #level = dict['level']
  147. print('loading template level', level)
  148. act.scene = level
  149. cont.activate(own2.actuators["level"])
  150. dict['npause'] = False
  151. def timer():
  152. #dict = bge.logic.globalDict
  153. if dict['reload_timer'] == 1:
  154. scene = bge.logic.getCurrentScene()
  155. if dict['reload_timer'] > 0:
  156. dict['reload_timer'] -= 1