-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
104 lines (83 loc) · 4 KB
/
Copy pathmain.py
File metadata and controls
104 lines (83 loc) · 4 KB
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
from os import remove
from os.path import exists
from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from screens.MainMenuWindow import MainMenuWindow
from screens.NewGameWindow import NewGameWindow
from screens.OpponentSelectionViewWindow import OpponentSelectionViewWindow
from screens.RoundSelectionViewWindow import RoundSelectionViewWindow
from screens.GameWindow import GameWindow
from screens.ScoreboardWindow import ScoreboardWindow
from screens.SettingsWindow import SettingsWindow
from screens.UserNameInputScreen import UsernameInputScreen
from screens.HelpWindow import HelpWindow
from screens.WindowManager import WindowManager
from data import constants
from settings_file_helper import create_settings_file, update_settings_file
kv = Builder.load_file(constants.KV_FILE)
settings = dict()
act_settings_file = constants.ACT_GAME_SETTINGS_RELATIVE_PATH + constants.ACT_GAME_SETTINGS_FILE_NAME
settings_file = constants.SETTINGS_FILE_RELATIVE_PATH + constants.SETTINGS_FILE_NAME
def create_settings_file_with_default_values():
create_settings_file(settings_file,
constants.SETTINGS_HEADER)
update_settings_file(settings_file,
constants.SETTINGS_IS_FIRST_START_KEY,
constants.SETTINGS_IS_FIRST_START_DEFAULT_VALUE,
constants.SETTINGS_HEADER)
update_settings_file(settings_file,
constants.SETTINGS_FULLSCREEN_KEY,
constants.SETTINGS_FULLSCREEN_DEFAULT_VALUE,
constants.SETTINGS_HEADER)
update_settings_file(settings_file,
constants.SETTINGS_MIN_DETECTION_CONFIDENCE_KEY,
constants.SETTINGS_MIN_DETECTION_CONFIDENCE_DEFAULT_VALUE,
constants.SETTINGS_HEADER)
update_settings_file(settings_file,
constants.SETTINGS_MIN_TRACKING_CONFIDENCE_KEY,
constants.SETTINGS_MIN_TRACKING_CONFIDENCE_DEFAULT_VALUE,
constants.SETTINGS_HEADER)
update_settings_file(settings_file,
constants.SETTINGS_CAMERA_DEVICE_KEY,
constants.SETTINGS_CAMERA_DEVICE_DEFAULT_VALUE,
constants.SETTINGS_HEADER)
update_settings_file(settings_file,
constants.SETTINGS_SHOULD_DRAW_HANDMARKS_KEY,
constants.SETTINGS_SHOULD_DRAW_HANDMARKS_DEFAULT_VALUE,
constants.SETTINGS_HEADER)
def read_settings():
global settings
with open(settings_file, 'r') as saved_settings_file:
settings_lines = saved_settings_file.readlines()[1:]
for line in settings_lines:
line_parts = line.split(' ')
line_parts[0] = line_parts[0] + ' '
settings[line_parts[0]] = line_parts[1].strip()
#
#
if not exists(settings_file):
create_settings_file_with_default_values()
read_settings()
if settings[constants.SETTINGS_FULLSCREEN_KEY] == 'auto':
Window.fullscreen = settings[constants.SETTINGS_FULLSCREEN_KEY]
elif settings[constants.SETTINGS_FULLSCREEN_KEY] == 'False':
Window.fullscreen = False
Window.size = (1360, 768)
Window.minimum_width, Window.minimum_height = Window.size
class RockPaperScissorsMainApp(App):
def build(self):
self.title = constants.TITLE
return kv
def on_start(self):
create_settings_file(act_settings_file)
if settings[constants.SETTINGS_IS_FIRST_START_KEY] == 'True':
update_settings_file(settings_file,
constants.SETTINGS_IS_FIRST_START_KEY,
False,
constants.SETTINGS_HEADER)
App.get_running_app().root.current = 'help'
def on_stop(self):
remove(constants.ACT_GAME_SETTINGS_RELATIVE_PATH + constants.ACT_GAME_SETTINGS_FILE_NAME)
if __name__ == '__main__':
RockPaperScissorsMainApp().run()