123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import bge
- import GameLogic
- import configobj
- from configobj import ConfigObj
-
- mainDir = GameLogic.expandPath("//")
- fileName = mainDir + "config.ini"
-
- config = ConfigObj(fileName, interpolation=True)
- dict = bge.logic.globalDict
-
- print('###############start game##########')
- dict['music_player'] = 1
-
- def to_dict(section, key):
- dict = bge.logic.globalDict
- value = config[key]
- if isinstance(value, str):
- if value.isdigit():
- value = int(value)
- else:
- try:
- value = float(value)
- except:
- pass
- dict[key] = value
- #print(key, value)
-
- def readChar():
- mainDir = GameLogic.expandPath("//characters/")
- fileName = mainDir + dict['character'] + ".ini"
- print('loading character settings', fileName)
- char_config = ConfigObj(fileName, interpolation=True)
-
-
- def to_dict2(section, key):
- dict = bge.logic.globalDict
- value = char_config[key]
- if isinstance(value, str):
- if value.isdigit():
- value = int(value)
- else:
- try:
- value = float(value)
- except:
- pass
- dict[key] = value
- print(key, value)
-
-
- char_config.walk(to_dict2, char_config)
-
- def writeChar():
- dict = bge.logic.globalDict
- mainDir = GameLogic.expandPath("//characters/")
- fileName = mainDir + dict['character'] + ".ini"
- print('writing character settings', fileName)
- char_config = ConfigObj(fileName, interpolation=True)
-
- def from_dict2(section, key):
- char_config[key] = dict[key]
-
- char_config.walk(from_dict2)
- #char_config[key] = dict[key]
- char_config.write()
-
-
- def readSettings():
- config.walk(to_dict)
- readChar()
-
- def from_dict(section, key):
- dict = bge.logic.globalDict
- config[key] = dict[key]
-
- def writeSettings():
- config.walk(from_dict)
- config.write()
- dict = bge.logic.globalDict
-
- def setres():
- import GameLogic
- import bge
- scenes = bge.logic.getSceneList()
- main_scene = [scene for scene in scenes if scene.name=="main"][0]
- own = main_scene.objects['Empty']
- cont = GameLogic.getCurrentController()
- own2 = cont.owner
- dict = bge.logic.globalDict
- resx = int(dict["resx"])
- resy = int(dict["resy"])
- fullscreen = bge.render.getFullScreen()
- print("fullscreen = ", fullscreen)
- if fullscreen != True:
- if dict['fullscreen_on'] == 1:
- bge.render.setFullScreen(True)
- if fullscreen == True:
- if dict['fullscreen_on'] == 0:
- bge.render.setFullScreen(False)
-
- bge.render.setWindowSize(resx, resy)
- print("resolution = ", resx, resy)
-
- def loadlevel():
- import GameLogic
- import bge
- scenes = bge.logic.getSceneList()
- main_scene = [scene for scene in scenes if scene.name=="main"][0]
- own = main_scene.objects['Empty']
- cont = GameLogic.getCurrentController()
- own2 = cont.owner
-
- dict = bge.logic.globalDict #Get the global dictionary
- dict['scene_inited'] = False
- if own["framerate"] == 1:
- bge.render.showFramerate(1)
- if own["profile"] ==1:
- bge.render.showProfile(1)
- act = own2.actuators["level"]
- dict = bge.logic.globalDict
- level = dict['level']
- print('loading level', level)
- act.scene = level
- cont.activate(own2.actuators["level"])
- dict['npause'] = False
-
- def timer():
- import GameLogic
- import bge
-
- dict = bge.logic.globalDict
-
- if dict['reload_timer'] == 1:
- scene = bge.logic.getCurrentScene()
-
- if dict['reload_timer'] > 0:
- dict['reload_timer'] -= 1
|