-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfigure.py
More file actions
407 lines (359 loc) · 15.7 KB
/
Copy pathconfigure.py
File metadata and controls
407 lines (359 loc) · 15.7 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
from enum import Enum
import re
from ast import literal_eval
import os
import time
import sys
import keyboard
# Configuration
SETTINGS_FILE = "modules/settings.py"
USER_CONFIG_FILE = "modules/user_config.py"
EDITABLE_SETTINGS = {
'PLAYER_NAME', 'HP_MAX', 'HP_CURRENT', 'AP_MAX', 'AP_CURRENT', 'LEVEL',
'PIP_BOY_LIGHT', 'PIP_BOY_MID', 'PIP_BOY_DARKER',
'SCREEN_WIDTH', 'SCREEN_HEIGHT', 'FPS', 'SOUND_ON', 'SHOW_CRT', 'BLOOM_EFFECT'
}
DEFAULT_SETTINGS = {
'PLAYER_NAME': 'VAULT-DWELLER',
'HP_MAX': 100,
'HP_CURRENT': 100,
'AP_MAX': 100,
'AP_CURRENT': 100,
'LEVEL': 1,
'PIP_BOY_LIGHT': (0, 255, 0),
'PIP_BOY_MID': (0, 127, 0),
'PIP_BOY_DARKER': (0, 63, 0),
'SCREEN_WIDTH': 320,
'SCREEN_HEIGHT': 240,
'FPS': 30,
'SOUND_ON': True,
'SHOW_CRT': True,
'BLOOM_EFFECT': True
}
class PipBoyTheme:
class Color(Enum):
PRIMARY = "\033[38;5;40m" # Pip-Boy Green
SECONDARY = "\033[38;5;34m" # Darker Green
ACCENT = "\033[38;5;226m" # Amber
WARNING = "\033[38;5;196m" # Red
DISABLED = "\033[38;5;240m" # Gray
RESET = "\033[0m"
@classmethod
def apply_crt_effect(cls, text):
crt_pattern = [
"▗▄▖▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
"▝▀▘▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"
]
return "".join([f"{cls.Color.DISABLED.value}{c}{cls.Color.RESET.value}" for c in crt_pattern[0]]) + "\n" + text
class PipBoyDisplay:
@staticmethod
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
@staticmethod
def draw_border():
border = PipBoyTheme.Color.SECONDARY.value + "╔" + "═"*76 + "╗" + PipBoyTheme.Color.RESET.value
print(border)
@staticmethod
def draw_divider():
print(PipBoyTheme.Color.SECONDARY.value + "╠" + "═"*76 + "╣" + PipBoyTheme.Color.RESET.value)
@staticmethod
def draw_footer():
footer = PipBoyTheme.Color.SECONDARY.value + "╚" + "═"*76 + "╝" + PipBoyTheme.Color.RESET.value
print(footer)
@staticmethod
def typewriter(text, delay=0.02):
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(delay)
print()
@staticmethod
def loading_animation(duration=1):
frames = ["[■□□□□□□□□□]", "[■■□□□□□□□□]", "[■■■□□□□□□□]", "[■■■■□□□□□□]",
"[■■■■■□□□□□]", "[■■■■■■□□□□]", "[■■■■■■■□□□]", "[■■■■■■■■□□]",
"[■■■■■■■■■□]", "[■■■■■■■■■■]"]
end_time = time.time() + duration
while time.time() < end_time:
for frame in frames:
sys.stdout.write("\r" + PipBoyTheme.Color.ACCENT.value + frame + PipBoyTheme.Color.RESET.value)
sys.stdout.flush()
time.sleep(0.1)
print("\r" + " "*15)
def parse_settings():
"""Load settings with proper priority: DEFAULT < settings.py < user_config.py"""
settings = DEFAULT_SETTINGS.copy()
def load_from_file(filename):
if os.path.exists(filename):
with open(filename, 'r') as f:
content = f.read()
for match in re.finditer(r'^([A-Z_]+)\s*=\s*(.*)$', content, re.M):
var_name = match.group(1)
if var_name in EDITABLE_SETTINGS:
try:
settings[var_name] = literal_eval(match.group(2).strip())
except:
pass
load_from_file(SETTINGS_FILE)
load_from_file(USER_CONFIG_FILE)
return settings
def update_user_config(new_settings):
"""Save only modified settings compared to original defaults"""
# Load original defaults without user config
original_defaults = DEFAULT_SETTINGS.copy()
if os.path.exists(SETTINGS_FILE):
with open(SETTINGS_FILE, 'r') as f:
content = f.read()
for match in re.finditer(r'^([A-Z_]+)\s*=\s*(.*)$', content, re.M):
var_name = match.group(1)
if var_name in EDITABLE_SETTINGS:
try:
original_defaults[var_name] = literal_eval(match.group(2).strip())
except:
pass
# Filter settings that differ from original defaults
filtered_settings = {
k: v for k, v in new_settings.items()
if k in EDITABLE_SETTINGS and v != original_defaults.get(k, None)
}
# Generate config file content
output = "# User Configuration (Auto-generated)\n# Overrides settings.py\n\n"
for var, value in filtered_settings.items():
if isinstance(value, str):
output += f'{var} = "{value}"\n'
elif isinstance(value, tuple):
output += f'{var} = {tuple(value)}\n'
else:
output += f'{var} = {value}\n'
with open(USER_CONFIG_FILE, 'w') as f:
f.write(output)
def display_header(title):
PipBoyDisplay.clear()
print(PipBoyTheme.Color.PRIMARY.value)
print(r"""
/$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$
| $$__ $$|_ $$_/| $$__ $$| $$__ $$ /$$__ $$| $$ /$$/
| $$ \ $$ | $$ | $$ \ $$| $$ \ $$| $$ \ $$ \ $$ /$$/
| $$$$$$$/ | $$ | $$$$$$$/| $$$$$$$ | $$ | $$ \ $$$$/
| $$____/ | $$ | $$____/ | $$__ $$| $$ | $$ \ $$/
| $$ | $$ | $$ | $$ \ $$| $$ | $$ | $$
| $$ /$$$$$$| $$ | $$$$$$$/| $$$$$$/ | $$
|__/ |______/|__/ |_______/ \______/ |__/
""")
print(f"{PipBoyTheme.Color.ACCENT.value}=== {title} ==={PipBoyTheme.Color.RESET.value}\n")
def draw_menu(options, selected_index):
PipBoyDisplay.draw_border()
for i, (text, value) in enumerate(options):
prefix = f"{PipBoyTheme.Color.ACCENT.value}▶ {PipBoyTheme.Color.PRIMARY.value}" if i == selected_index else " "
if value is None:
print(f"{prefix}{text}")
else:
value_color = PipBoyTheme.Color.ACCENT.value if isinstance(value, str) else PipBoyTheme.Color.PRIMARY.value
print(f"{prefix}{text.ljust(60)}{value_color}{value}{PipBoyTheme.Color.RESET.value}")
PipBoyDisplay.draw_footer()
last_key_time = 0
KEY_DEBOUNCE = 0.2 # 200ms cooldown
def get_key():
global last_key_time
while True:
event = keyboard.read_event(suppress=True)
now = time.time()
if now - last_key_time < KEY_DEBOUNCE:
continue
if event.event_type == keyboard.KEY_DOWN:
last_key_time = now
if event.name == 'up':
return 'up'
elif event.name == 'down':
return 'down'
elif event.name == 'enter':
return 'enter'
elif event.name == 'esc':
return 'esc'
def draw_color_preview(color):
"""Draw ASCII art color preview with proper color codes"""
# Calculate text color (white or black based on brightness)
brightness = (0.299 * color[0] + 0.587 * color[1] + 0.114 * color[2])
text_color = "\033[38;2;255;255;255m" if brightness < 127 else "\033[38;2;0;0;0m"
reset = "\033[0m"
preview = [
"████████████████████████████████████████████████████████████",
"████████████████████████████████████████████████████████████",
f"██ CURRENT COLOR: {str(color).ljust(36)} ██",
"████████████████████████████████████████████████████████████"
]
for line in preview:
colored_line = []
for char in line:
if char == "█":
# Full block with selected color
colored_line.append(
f"\033[48;2;{color[0]};{color[1]};{color[2]}m" # Background
f"\033[38;2;{color[0]};{color[1]};{color[2]}m" # Foreground
"▄" # Use lower half block
)
else:
# Text with contrasting color
colored_line.append(f"{text_color}{char}")
colored_line.append(reset)
print("".join(colored_line))
def validate_int_input(prompt, min_val, max_val):
"""Get validated integer input with retry logic"""
while True:
try:
PipBoyDisplay.typewriter(f"{PipBoyTheme.Color.PRIMARY.value}{prompt}: ", 0.01)
value = int(input())
if min_val <= value <= max_val:
return value
raise ValueError
except ValueError:
PipBoyDisplay.typewriter(f"{PipBoyTheme.Color.WARNING.value}INVALID INPUT - ENTER VALUE BETWEEN {min_val}-{max_val}", 0.03)
time.sleep(0.5)
def player_settings_menu(settings):
selected = 0
while True:
options = [
(f"Name: {settings['PLAYER_NAME']}", "VAULT-DWELLER ID"),
(f"HP: {settings['HP_CURRENT']}/{settings['HP_MAX']}", "HEALTH STATUS"),
(f"AP: {settings['AP_CURRENT']}/{settings['AP_MAX']}", "ACTION POINTS"),
(f"Level: {settings['LEVEL']}", "VAULT-TEC RATING"),
("Return to Main Menu", "BACK")
]
display_header("PLAYER CONFIGURATION")
draw_menu(options, selected)
key = get_key()
if key == 'up' and selected > 0:
selected -= 1
elif key == 'down' and selected < len(options)-1:
selected += 1
elif key == 'enter':
if selected == 0:
PipBoyDisplay.typewriter(f"{PipBoyTheme.Color.PRIMARY.value}ENTER NEW NAME: ", 0.05)
settings['PLAYER_NAME'] = input().strip()[:20]
elif selected == 1:
settings['HP_CURRENT'] = validate_int_input("CURRENT HP (0-999)", 0, 999)
settings['HP_MAX'] = validate_int_input("MAX HP (1-999)", 1, 999)
elif selected == 2:
settings['AP_CURRENT'] = validate_int_input("CURRENT AP (0-999)", 0, 999)
settings['AP_MAX'] = validate_int_input("MAX AP (1-999)", 1, 999)
elif selected == 3:
settings['LEVEL'] = validate_int_input("VAULT-TEC RATING LEVEL (1-99)", 1, 99)
elif selected == 4:
return
elif key == 'esc':
return
def color_settings_menu(settings):
selected = 0
color = settings['PIP_BOY_LIGHT']
while True:
options = [
("Classic Green", "VAULT-TEC STANDARD"),
("Amber", "PRE-WAR MILSPEC"),
("Blue", "ROBOCO INDUSTRIAL"),
("White", "EXPERIMENTAL"),
("Custom RGB", "ADVANCED CONFIG"),
("Return to Main Menu", "BACK")
]
display_header("DISPLAY COLOR PROFILE")
draw_color_preview(color)
draw_menu(options, selected)
key = get_key()
if key == 'up' and selected > 0:
selected -= 1
elif key == 'down' and selected < len(options)-1:
selected += 1
elif key == 'enter':
if selected == 0:
color = (0, 255, 0)
elif selected == 1:
color = (255, 191, 0)
elif selected == 2:
color = (0, 127, 255)
elif selected == 3:
color = (255, 255, 255)
elif selected == 4:
r = validate_int_input("RED VALUE (0-255)", 0, 255)
g = validate_int_input("GREEN VALUE (0-255)", 0, 255)
b = validate_int_input("BLUE VALUE (0-255)", 0, 255)
color = (r, g, b)
elif selected == 5:
settings['PIP_BOY_LIGHT'] = color
settings['PIP_BOY_MID'] = tuple(x//2 for x in color)
settings['PIP_BOY_DARKER'] = tuple(x//4 for x in color)
return
elif key == 'esc':
return
def system_settings_menu(settings):
selected = 0
while True:
options = [
(f"Resolution: {settings['SCREEN_WIDTH']}x{settings['SCREEN_HEIGHT']}", "DISPLAY DIMENSIONS"),
(f"FPS: {settings['FPS']}", "REFRESH RATE"),
(f"Sound: {'ENABLED' if settings['SOUND_ON'] else 'DISABLED'}", "AUDIO OUTPUT"),
(f"CRT Effect: {'ACTIVE' if settings['SHOW_CRT'] else 'OFFLINE'}", "RETRO FILTER"),
(f"Bloom Effect: {'ACTIVE' if settings['BLOOM_EFFECT'] else 'OFFLINE'}", "LIGHTING SYSTEM"),
("Return to Main Menu", "BACK")
]
display_header("SYSTEM PREFERENCES")
draw_menu(options, selected)
key = get_key()
if key == 'up' and selected > 0:
selected -= 1
elif key == 'down' and selected < len(options)-1:
selected += 1
elif key == 'enter':
if selected == 0:
settings['SCREEN_WIDTH'] = validate_int_input("HORIZONTAL RESOLUTION", 320, 3840)
settings['SCREEN_HEIGHT'] = validate_int_input("VERTICAL RESOLUTION", 240, 2160)
elif selected == 1:
settings['FPS'] = validate_int_input("FRAMES PER SECOND", 24, 144)
elif selected == 2:
settings['SOUND_ON'] = not settings['SOUND_ON']
elif selected == 3:
settings['SHOW_CRT'] = not settings['SHOW_CRT']
elif selected == 4:
settings['BLOOM_EFFECT'] = not settings['BLOOM_EFFECT']
elif selected == 5:
return
elif key == 'esc':
return
def main():
PipBoyDisplay.clear()
PipBoyDisplay.typewriter(f"{PipBoyTheme.Color.PRIMARY.value}INITIALIZING VAULT-TEC CONFIGURATION SYSTEM...")
PipBoyDisplay.loading_animation()
settings = parse_settings()
selected = 0
while True:
options = [
("Player Configuration", "STATUS: ONLINE"),
("Display Settings", "COLOR PROFILE"),
("System Preferences", "ADVANCED OPTIONS"),
("Save & Exit Program", "WRITE TO MEMORY")
]
display_header("MAIN SYSTEM MENU")
draw_menu(options, selected)
key = get_key()
if key == 'up' and selected > 0:
selected -= 1
elif key == 'down' and selected < len(options)-1:
selected += 1
elif key == 'enter':
if selected == 0:
player_settings_menu(settings)
elif selected == 1:
color_settings_menu(settings)
elif selected == 2:
system_settings_menu(settings)
elif selected == 3:
PipBoyDisplay.typewriter(f"{PipBoyTheme.Color.PRIMARY.value}SAVING CONFIGURATION TO MEMORY...")
PipBoyDisplay.loading_animation()
update_user_config(settings)
PipBoyDisplay.typewriter(f"{PipBoyTheme.Color.ACCENT.value}CONFIGURATION SAVED TO {USER_CONFIG_FILE}")
time.sleep(1)
return
elif key == 'esc':
return
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print(f"\n{PipBoyTheme.Color.WARNING.value}TERMINAL INTERRUPTED - EXITING SAFE MODE{PipBoyTheme.Color.RESET.value}")