forked from quasar098/midi-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
159 lines (144 loc) · 5.08 KB
/
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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import pygame
from typing import Optional, Any
from json import load, dump
from os.path import isfile
class Config:
# constants
SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080
CAMERA_SPEED = 500
SQUARE_SIZE = 50
PARTICLE_SPEED = 10
# colors
#
# each color theme requires a hallway color, a background color, and at least one square color
# optionally, the color theme provides an hp_bar_border color (default 10, 9, 8),
# an hp_bar_background color (default 34, 51, 59), and a list
# of hp_bar_fill colors (default (156, 198, 155), (189, 228, 168), (215, 242, 186))
#
color_themes = {
"dark": {
"hallway": pygame.Color(214, 209, 205),
"background": pygame.Color(60, 63, 65),
"square": [
pygame.Color(224, 26, 79),
pygame.Color(173, 247, 182),
pygame.Color(249, 194, 46),
pygame.Color(83, 179, 203)
]
},
# credits to TheCodingCrafter for these themes
"light": {
"hallway": pygame.Color(60, 63, 65),
"background": pygame.Color(214, 209, 205),
"square": [
pygame.Color(224, 26, 79),
pygame.Color(173, 247, 182),
pygame.Color(249, 194, 46),
pygame.Color(83, 179, 203)
]
},
"rainbow": {
"hallway": pygame.Color((214, 209, 205)),
"background": pygame.Color((60, 63, 65)),
"square": [
pygame.Color(0, 0, 0)
]
},
"autumn": {
"hallway": pygame.Color((252, 191, 73)),
"background": pygame.Color((247, 127, 0)),
"square": [
pygame.Color(224, 26, 79),
pygame.Color(173, 247, 182),
pygame.Color(249, 194, 46),
pygame.Color(83, 179, 203)
]
},
"winter": {
"hallway": pygame.Color((202, 240, 255)),
"background": pygame.Color((0, 180, 216)),
"square": [
pygame.Color(224, 26, 79),
pygame.Color(173, 247, 182),
pygame.Color(249, 194, 46),
pygame.Color(83, 179, 203)
]
},
"spring": {
"hallway": pygame.Color((158, 240, 26)),
"background": pygame.Color((112, 224, 0)),
"square": [
pygame.Color(224, 26, 79),
pygame.Color(173, 247, 182),
pygame.Color(249, 194, 46),
pygame.Color(83, 179, 203)
]
},
"magenta": {
"hallway": pygame.Color((239, 118, 116)),
"background": pygame.Color((218, 52, 77)),
"square": [
pygame.Color(224, 26, 79),
pygame.Color(173, 247, 182),
pygame.Color(249, 194, 46),
pygame.Color(83, 179, 203)
]
},
"monochromatic": {
"hallway": pygame.Color((255, 255, 255)),
"background": pygame.Color((0, 0, 0)),
"square": [
pygame.Color(80, 80, 80),
pygame.Color(150, 150, 150),
pygame.Color(100, 100, 100),
pygame.Color(200, 200, 200)
]
}
}
# intended configurable settings
theme: Optional[str] = "dark"
seed: Optional[int] = None
camera_mode: Optional[int] = 2
start_playing_delay = 3000
max_notes: Optional[int] = None
bounce_min_spacing: Optional[float] = 30
square_speed: Optional[int] = 600
volume: Optional[int] = 70
music_offset: Optional[int] = -300
direction_change_chance: Optional[int] = 30
hp_drain_rate = 10
theatre_mode = False
# settings that are not configurable (yet)
backtrack_chance: Optional[float] = 0.01
backtrack_amount: Optional[int] = 40
rainbow_speed: Optional[int] = 30
square_swipe_anim_speed: Optional[int] = 4
particle_amount = 10
# just global stuff
midi_file_name: Optional[str] = None
audio_file_name: Optional[str] = None
# keys to save and load
save_attrs = ["theme", "seed", "camera_mode", "start_playing_delay", "max_notes", "bounce_min_spacing",
"square_speed", "volume", "music_offset", "direction_change_chance", "hp_drain_rate", "theatre_mode"]
def get_colors():
return Config.color_themes.get(Config.theme, "dark")
def save_to_file(dat: Optional[dict[str, Any]] = None):
if dat is None:
dat = {k: getattr(Config, k) for k in Config.save_attrs}
with open("./assets/settings.json", "w") as f:
dump(dat, f)
def load_from_file():
try:
if isfile("./assets/settings.json"):
with open("./assets/settings.json", "r") as f:
data = load(f)
for setting in data:
setattr(Config, setting, data[setting])
else:
with open("./assets/settings.json", "w") as f:
f.write("{}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "config":
load_from_file()