-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameConfiguration.py
107 lines (90 loc) · 2.79 KB
/
GameConfiguration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import json
from ursina import *
# settings
music_volume = 1
sound_volume = 1
play_intro = False
hide_fps = False
borderless = False
fullscreen = True
extra_ui_info = True
discord_presence = False
language = "English"
font = "Graphics/fonts/JPfont.ttf"
window_size = 500, 500
window_position = 0, 0
window_ratio = 1.333
# build info
server = "https://gdcheerios.com"
local_dev_branch = True
# game config
random_pitch_range = (0.7, 1.3)
fade_time = 0.6
def update_config(settings: dict):
try:
# language
global language
global font
language = settings["language"]
if language == "English":
pass
elif language == "日本語":
pass
# audio
global music_volume
global sound_volume
music_volume = settings["audio"]["music volume"]
sound_volume = settings["audio"]["sound volume"]
# graphics
global hide_fps
global fullscreen
global borderless
global extra_ui_info
hide_fps = settings["graphics"]["hide fps"]
fullscreen = settings["graphics"]["fullscreen"]
borderless = settings["graphics"]["borderless"]
extra_ui_info = settings["graphics"]["extra ui info"]
# cache
global window_position
global window_ratio
global window_size
window_position = settings["cache"]["window position"][0], settings["cache"]["window position"][1]
window_ratio = settings["cache"]["window ratio"]
window_size = settings["cache"]["window size"][0], settings["cache"]["window size"][1]
print("Updated Config!")
except KeyError:
print("There was an error updating configuration...")
print("Resetting settings... T_T")
save_settings()
def save_settings():
settings = {
"language": language,
"audio": {
"music volume": music_volume,
"sound volume": sound_volume
},
"graphics": {
"hide fps": hide_fps,
"fullscreen": fullscreen,
"borderless": borderless,
"extra ui info": extra_ui_info
},
"cache": {
"window position": [window_position[0], window_position[1]],
"window ratio": window_ratio,
"window size": [window_size[0], window_size[1]]
}
}
json.dump(settings, open("settings.json", "w+", encoding="utf-8"), indent=4)
print("Saved Settings!")
def apply_settings():
window.windowed_position = window_position
# window.forced_aspect_ratio = window_ratio
window.windowed_size = window_size
print("Applied Settings!")
if os.path.isfile("settings.json"):
settings = json.load(open("settings.json", "r", encoding="utf-8"))
update_config(settings)
else:
save_settings()
apply_settings()