This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_config.py
72 lines (59 loc) · 2.29 KB
/
game_config.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
"""
Copyright (C) 2021 Ilya "Faer" Gurov (ilya.faer@mail.ru)
License: https://github.com/IlyaFaer/ForwardOnlyGame/blob/master/LICENSE.md
Game configurations API.
"""
import os.path
class Config:
"""Includes and orchestrates all the game configurations."""
opts_file = "options.cfg"
def __init__(self):
if not os.path.exists(self.opts_file):
self._create_default()
with open(self.opts_file, "r") as opts_file:
(
self.resolution,
lang,
tutorial_on,
fps,
fps_meter,
multi_threading,
) = opts_file.readlines()
self.resolution = self.resolution.strip()
self.tutorial_enabled = tutorial_on.strip() == "True"
self.language = lang.strip()
self.fps_limit = int(fps)
self.fps_meter = fps_meter.strip() == "True"
self.multi_threading = multi_threading.strip() == "True"
def _create_default(self):
"""Create default game configurations file.
Multithreading mode must always be the last option!
Defaults:
Screen resolution: player's monitor size.
Language: English
Turorial: enabled
"""
with open(self.opts_file, "w") as opts_file:
opts_file.write(
str(base.pipe.getDisplayWidth()) # noqa: F82
+ "x"
+ str(base.pipe.getDisplayHeight()) # noqa: F82
+ "\nEN\nTrue\n120\nFalse\nTrue"
)
def update(self, resolution, lang, tutorial, fps_limit, fps_meter, multi_threading):
"""Update the game configurations with new values.
Multithreading mode must always be the last option!
Args:
resolution (str): New screen resolution.
lang (str): New language code.
tutorial (str): New value for Tutorial Enabled option.
fps_limit (int): Framerate limit.
fps_meter (bool): Enable FPS meter.
multi_threading (bool): Enable multi threading mode.
"""
with open(self.opts_file, "w") as opts_file:
opts_file.write(
"\n".join(
(resolution, lang, tutorial, fps_limit, fps_meter, multi_threading)
)
)