-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.py
41 lines (33 loc) · 1.47 KB
/
Settings.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
import json
import os
import constants
class Settings:
default_settings = {
'field_width': constants.FIELD_WIDTH,
'field_height': constants.FIELD_HEIGHT,
'grid': constants.GRID,
'stop_color': constants.STOP_COLOR,
}
def __init__(self):
self.settings = self.default_settings
self.window_width = self.settings['field_width'] * constants.POINT_SIZE + 2 * constants.FRAME_THICKNESS + constants.SCORE_TABLE_WIDTH
self.window_height = self.settings['field_height'] * constants.POINT_SIZE + 2 * constants.FRAME_THICKNESS
self.upload_settings()
def upload_settings(self):
try:
with open(constants.WAY_SETTINGS, 'r') as file:
data = json.load(file)
if data.keys() == self.default_settings.keys():
self.update_settings(data)
else:
self.update_settings()
except FileNotFoundError:
self.update_settings()
def update_settings(self, new_settings=default_settings):
self.settings = new_settings
self.window_width = self.settings['field_width'] * constants.POINT_SIZE + 2 * constants.FRAME_THICKNESS + constants.SCORE_TABLE_WIDTH
self.window_height = self.settings['field_height'] * constants.POINT_SIZE + 2 * constants.FRAME_THICKNESS
with open(constants.WAY_SETTINGS, 'w') as file:
json.dump(self.settings, file)
if __name__ == '__main__':
s = Settings()