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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. print('###############start game##########')
  10. dict['music_player'] = 1
  11. def to_dict(section, key):
  12. dict = bge.logic.globalDict
  13. value = config[key]
  14. if isinstance(value, str):
  15. if value.isdigit():
  16. value = int(value)
  17. else:
  18. try:
  19. value = float(value)
  20. except:
  21. pass
  22. dict[key] = value
  23. #print(key, value)
  24. def readChar():
  25. mainDir = GameLogic.expandPath("//characters/")
  26. fileName = mainDir + dict['character'] + ".ini"
  27. #print('loading character settings', fileName)
  28. char_config = ConfigObj(fileName, interpolation=True)
  29. def to_dict2(section, key):
  30. dict = bge.logic.globalDict
  31. value = char_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. #print(key, value)
  42. char_config.walk(to_dict2, char_config)
  43. def writeChar():
  44. dict = bge.logic.globalDict
  45. mainDir = GameLogic.expandPath("//characters/")
  46. fileName = mainDir + dict['character'] + ".ini"
  47. print('writing character settings', fileName)
  48. char_config = ConfigObj(fileName, interpolation=True)
  49. def from_dict2(section, key):
  50. char_config[key] = dict[key]
  51. char_config.walk(from_dict2)
  52. #char_config[key] = dict[key]
  53. char_config.write()
  54. def readSettings():
  55. config.walk(to_dict)
  56. readChar()
  57. def from_dict(section, key):
  58. dict = bge.logic.globalDict
  59. config[key] = dict[key]
  60. def writeSettings():
  61. config.walk(from_dict)
  62. config.write()
  63. dict = bge.logic.globalDict
  64. def setres():
  65. import GameLogic
  66. import bge
  67. scenes = bge.logic.getSceneList()
  68. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  69. own = main_scene.objects['Empty']
  70. cont = GameLogic.getCurrentController()
  71. own2 = cont.owner
  72. dict = bge.logic.globalDict
  73. resx = int(dict["resx"])
  74. resy = int(dict["resy"])
  75. fullscreen = bge.render.getFullScreen()
  76. #print("fullscreen = ", fullscreen)
  77. if fullscreen != True:
  78. if dict['fullscreen_on'] == 1:
  79. bge.render.setFullScreen(True)
  80. if fullscreen == True:
  81. if dict['fullscreen_on'] == 0:
  82. bge.render.setFullScreen(False)
  83. bge.render.setWindowSize(resx, resy)
  84. bge.render.setVsync(dict['vsync_on']) #doesn't work?
  85. #print("resolution = ", resx, resy)
  86. def loadlevel():
  87. import GameLogic
  88. import bge
  89. scenes = bge.logic.getSceneList()
  90. main_scene = [scene for scene in scenes if scene.name=="main"][0]
  91. own = main_scene.objects['Empty']
  92. cont = GameLogic.getCurrentController()
  93. own2 = cont.owner
  94. dict = bge.logic.globalDict #Get the global dictionary
  95. dict['scene_inited'] = False
  96. if own["framerate"] == 1:
  97. bge.render.showFramerate(1)
  98. if own["profile"] ==1:
  99. bge.render.showProfile(1)
  100. act = own2.actuators["level"]
  101. dict = bge.logic.globalDict
  102. level = dict['level']
  103. print('loading level', level)
  104. act.scene = level
  105. cont.activate(own2.actuators["level"])
  106. dict['npause'] = False
  107. def timer():
  108. import GameLogic
  109. import bge
  110. dict = bge.logic.globalDict
  111. if dict['reload_timer'] == 1:
  112. scene = bge.logic.getCurrentScene()
  113. if dict['reload_timer'] > 0:
  114. dict['reload_timer'] -= 1