-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathstyle.py
344 lines (314 loc) · 13.5 KB
/
style.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
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
## Custom theme colors, could be adjusted with more RGB values for more creative themes!
## Use these in place of colorama's Fore and Back color literals.
import os
import textwrap
# class for compatible colors for terminals that cannot utilize RGB values outside of the 8-bit ANSI colors
class COMPAT_COLORS:
description = textwrap.wrap("A set of colors that are compatible with most terminals.", width=30, initial_indent="> ", subsequent_indent=" ")
BROWN = "\033[38;5;94m"
LIGHTBLUE = "\033[38;5;33m"
ROUGE = "\033[38;5;13m"
ORANGE = "\033[38;5;208m"
# https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
# Uses Standard colors (0-7) and High-Intensity colors (8-15) from 8-bit ANSI escape codes
RED = "\033[38;5;1m"
YELLOW = "\033[38;5;11m"
GREEN = "\033[38;5;10m"
BLUE = "\033[38;5;4m"
WHITE = "\033[38;5;15m"
CYAN = "\033[38;5;14m"
LIGHTGRAY = "\033[38;5;247m"
LIGHTBLACK = "\033[38;5;8m"
CHANCE = "\033[38;5;214m"
COMMUNITY = "\033[38;5;45m"
BLACK = "\033[38;5;0m"
# Reset color
RESET = "\033[0m"
# Player colors: red, green, yellow, blue, respectively
playerColors = ["\033[38;5;1m", "\033[38;5;2m", "\033[38;5;3m", "\033[38;5;4m"]
# display colors are used for printing text in Terminal, like error messages, etc. Not to be used on gameboard.
dispGREEN = "\033[38;5;2m"
dispRED = "\033[38;5;9m"
dispBLUE = "\033[38;5;12m"
backBROWN = BROWN.replace("38", "48")
backLIGHTBLUE = LIGHTBLUE.replace("38", "48")
backROUGE = ROUGE.replace("38", "48")
backORANGE = ORANGE.replace("38", "48")
backRED = RED.replace("38", "48")
backYELLOW = YELLOW.replace("38", "48")
backGREEN = GREEN.replace("38", "48")
backBLUE = BLUE.replace("38", "48")
backWHITE = WHITE.replace("38", "48")
backCYAN = CYAN.replace("38", "48")
backLIGHTGRAY = LIGHTGRAY.replace("38", "48")
backLIGHTBLACK = LIGHTBLACK.replace("38", "48")
backCHANCE = CHANCE.replace("38", "48")
backCOMMUNITY = COMMUNITY.replace("38", "48")
backBLACK = BLACK.replace("38", "48")
class DEFAULT_COLORS:
description = textwrap.wrap("The default TERMINAL MONOPOLY experience.", width=30, initial_indent="> ", subsequent_indent=" ")
BROWN = "\033[38;2;138;96;25m"
LIGHTBLUE = "\033[38;2;43;249;255m"
ROUGE = "\033[38;2;240;93;231m"
ORANGE = "\033[38;2;246;160;62m"
RED = "\033[38;2;246;62;62m"
YELLOW = "\033[38;2;240;255;91m"
GREEN = "\033[38;2;41;129;32m"
BLUE = "\033[38;2;44;37;255m"
WHITE = "\033[38;2;255;255;255m"
CYAN = "\033[38;2;0;255;239m"
LIGHTGRAY = "\033[38;2;193;193;193m"
LIGHTBLACK = "\033[38;2;88;88;88m"
CHANCE = "\033[38;2;255;191;105m"
COMMUNITY = "\033[38;2;0;137;255m"
BLACK = "\033[38;5;0m"
# Reset color
RESET = "\033[0m"
# Player colors: red, green, yellow, blue, respectively
playerColors = ["\033[38;5;1m", "\033[38;5;2m", "\033[38;5;3m", "\033[38;5;4m"]
# display colors are used for printing text in Terminal, like error messages, etc. Not to be used on gameboard.
dispGREEN = "\033[38;5;2m"
dispRED = "\033[38;5;9m"
dispBLUE = "\033[38;5;12m"
backBROWN = BROWN.replace("38", "48")
backLIGHTBLUE = LIGHTBLUE.replace("38", "48")
backROUGE = ROUGE.replace("38", "48")
backORANGE = ORANGE.replace("38", "48")
backRED = RED.replace("38", "48")
backYELLOW = YELLOW.replace("38", "48")
backGREEN = GREEN.replace("38", "48")
backBLUE = BLUE.replace("38", "48")
backWHITE = WHITE.replace("38", "48")
backCYAN = CYAN.replace("38", "48")
backLIGHTGRAY = LIGHTGRAY.replace("38", "48")
backLIGHTBLACK = LIGHTBLACK.replace("38", "48")
backCHANCE = CHANCE.replace("38", "48")
backCOMMUNITY = COMMUNITY.replace("38", "48")
backBLACK = BLACK.replace("38", "48")
class CRAZY_THEME:
description = textwrap.wrap("A bold colorset.", width=30, initial_indent="> ", subsequent_indent=" ")
fore_prefix = "\033[38;2;"
back_prefix = "\033[48;2;"
BROWN = fore_prefix + "169;0;196m"
LIGHTBLUE = fore_prefix + "157;255;254m"
ROUGE = fore_prefix + "239;180;255m"
ORANGE = fore_prefix + "255;115;0m"
RED = fore_prefix + "204;17;17m"
YELLOW = fore_prefix + "206;255;42m"
GREEN = fore_prefix + "56;255;250m"
BLUE = fore_prefix + "0;20;110m"
WHITE = fore_prefix + "254;229;255m"
CYAN = fore_prefix + "158;254;255m"
LIGHTGRAY = fore_prefix + "220;181;255m"
LIGHTBLACK = fore_prefix + "118;78;78m"
CHANCE = fore_prefix + "228;59;135m"
COMMUNITY = fore_prefix + "13;151;19m"
BLACK = fore_prefix + "39;76;79m"
RESET = "\033[0m"
playerColors = ["\033[38;5;1m", "\033[38;5;2m", "\033[38;5;3m", "\033[38;5;4m"]
dispGREEN = fore_prefix + "245;0;255m"
dispRED = fore_prefix + "7;0;255m"
dispBLUE = fore_prefix + "255;251;0m"
backBROWN = back_prefix + "132;25;25m"
backLIGHTBLUE = back_prefix + "25;127;132m"
backROUGE = back_prefix + "132;25;130m"
backORANGE = back_prefix + "132;93;25m"
backRED = back_prefix + "132;25;25m"
backYELLOW = back_prefix + "126;132;25m"
backGREEN = back_prefix + "41;132;25m"
backBLUE = back_prefix + "25;27;132m"
backWHITE = back_prefix + "255;244;205m"
backCYAN = back_prefix + "49;98;98m"
backLIGHTGRAY = back_prefix + "133;133;133m"
backLIGHTBLACK = back_prefix + "78;78;78m"
backCHANCE = back_prefix + "136;186;234m"
backCOMMUNITY = back_prefix + "210;208;38m"
backBLACK = back_prefix + "38;38;38m"
class MYCOLORS:
description = textwrap.wrap("This is the colorset the player chooses to use in the game.", width=30, initial_indent="> ", subsequent_indent=" ")
BROWN = ""
LIGHTBLUE = ""
ROUGE = ""
ORANGE = ""
RED = ""
YELLOW = ""
GREEN = ""
BLUE = ""
WHITE = ""
CYAN = ""
LIGHTGRAY = ""
LIGHTBLACK = ""
CHANCE = ""
COMMUNITY = ""
BLACK = ""
RESET = ""
playerColors = ["", "", "", ""]
dispGREEN = ""
dispRED = ""
dispBLUE = ""
backBROWN = ""
backLIGHTBLUE = ""
backROUGE = ""
backORANGE = ""
backRED = ""
backYELLOW = ""
backGREEN = ""
backBLUE = ""
backWHITE = ""
backCYAN = ""
backLIGHTGRAY = ""
backLIGHTBLACK = ""
backCHANCE = ""
backCOMMUNITY = ""
backBLACK = ""
def choose_colorset(colorset: str) -> None:
"""
This function sets the colorset for the game. It takes a string as an argument, which is the name of the colorset.
It then sets the colorset to the chosen colorset, and sets the background colors to the chosen colorset.
Parameters:
colorset (str): The name of the colorset to be used.
Returns:
None
"""
global MYCOLORS
if colorset == "COMPAT_COLORS":
# Set the colorset to the compatible colors
for attr in dir(COMPAT_COLORS):
if not attr.startswith('__'):
setattr(MYCOLORS, attr, getattr(COMPAT_COLORS, attr))
elif colorset == "DEFAULT_COLORS":
# Set the colorset to the default defined colors
for attr in dir(DEFAULT_COLORS):
if not attr.startswith('__'):
setattr(MYCOLORS, attr, getattr(DEFAULT_COLORS, attr))
elif colorset == "CRAZY_THEME":
# Set the colorset to the crazy theme colors
for attr in dir(CRAZY_THEME):
if not attr.startswith('__'):
setattr(MYCOLORS, attr, getattr(CRAZY_THEME, attr))
else:
raise ValueError("Invalid colorset. Please choose either 'COMPAT_COLORS' or 'DEFAULT_COLORS'.")
def colortest():
"""
Prints a test of all colors defined in the COLORS class.
"""
set_cursor(1, 4)
print(graphics.get("colortestboundary"))
y = 7
for color in dir(MYCOLORS):
if not color.startswith('__') and color != "back_prefix" and not color.startswith('back') and color != "RESET" and color != "description" and color != "fore_prefix":
value = getattr(MYCOLORS, color)
if isinstance(value, list):
for item in value:
set_cursor(2, y)
print(item + f"█████ {color}" + MYCOLORS.RESET)
y += 1
else:
set_cursor(2, y)
print(value + f"█████ {color}" + MYCOLORS.RESET)
y += 1
set_cursor(2, y)
y = y + 1
for color in dir(MYCOLORS):
if color.startswith('back'):
value = getattr(MYCOLORS, color)
set_cursor(2, y)
print(value + f" {color}" + MYCOLORS.RESET)
y += 1
print(COMPAT_COLORS.WHITE, end="") # Reset foreground to white for better visibility
sets = [DEFAULT_COLORS, COMPAT_COLORS, CRAZY_THEME] # Add to this list to add more color sets to the test.
offset = max([len(sets[x].description) for x in range(len(sets))]) + 1
for x in range(len(sets)):
x_offset = 31
y = 0
set_cursor(x*x_offset + x_offset, y)
lines = textwrap.wrap(f"Testing color set {sets[x].__name__}:", width=x_offset)
for line in lines:
set_cursor(x*x_offset + x_offset, y+1)
print(line, end="")
y += 1
j = 0
for line in sets[x].description:
set_cursor(x*x_offset + x_offset, y+1+j)
print(line, end="")
j += 1
y = offset
set_cursor(x*x_offset + x_offset, y+2)
print("Testing foreground colors:\n")
for color in dir(sets[x]):
if not color.startswith('__') and color != "back_prefix" and not color.startswith('back') and color != "RESET" and color != "description" and color != "fore_prefix":
value = getattr(sets[x], color)
if isinstance(value, list): # Special case for playerColors
for item in value:
set_cursor(x*x_offset + x_offset, y+3)
print(item + f"█████ {color}" + sets[x].RESET)
y += 1
else:
set_cursor(x*x_offset + x_offset, y+3)
print(value + f"█████ {color}" + sets[x].RESET)
y += 1
print(COMPAT_COLORS.WHITE, end="") # Reset foreground to white for better visibility
set_cursor(x*x_offset + x_offset, y+3)
print("Testing background colors:")
for color in dir(sets[x]):
print(COMPAT_COLORS.WHITE, end="") # Reset foreground to white for better visibility
if color.startswith('back'):
value = getattr(sets[x], color)
set_cursor(x*x_offset + x_offset, y+4)
print(value + f" {color}" + sets[x].RESET)
y += 1
def print_w_dots(text: str, size: int=50, end: str='\n') -> None:
"""
Prints a green string with predetermined dot padding after it.
Parameters:
text (str): string to pad dots after.
size (int): integer of how long the padded string should be. Default 50.
end (str): value to print immediately at the end of the text (after clearing color formatting). Default newline.
Returns:
None
"""
for i in range(size-len(text)):
text += '.'
print(DEFAULT_COLORS.dispGREEN+text, end=DEFAULT_COLORS.RESET+end)
def center_lines(text, width):
lines = text.split('\n')
centered_lines = [line.center(width) for line in lines]
return '\n'.join(centered_lines)
def get_graphics() -> dict:
"""
Reads all graphics from the ascii directory into a dictionary.
Parameters: None
Returns:
Dictionary with the key names of the graphics and the value of the graphic itself.
The graphics are read from the ascii folder, where the key is the filename and the value is the graphic.
"""
text_dict = {}
for dir_name, sub_dirs, files in os.walk("./ascii/"):
for file in files:
with open(os.path.join(dir_name, file), encoding='utf-8') as ascii_text:
full_file = ascii_text.read()
split_file = full_file.splitlines(True)
no_header_ascii = ''.join(split_file[1:])
if (split_file[0].strip() == "GAMEBD"):
text_dict[file] = bytes(no_header_ascii, 'utf-8').decode('unicode_escape').encode('latin-1').decode('utf-8')
elif (split_file[0].strip() == "CENTER"):
text_dict[file] = center_lines(no_header_ascii, 75)
elif (split_file[0].strip() == "NWLCUT"):
text_dict[file] = no_header_ascii.replace('\n', '')
elif (split_file[0].strip() == "NSTRIP"):
text_dict[file] = no_header_ascii.strip()
elif (split_file[0].strip() == "LSTRIP"):
text_dict[file] = no_header_ascii.lstrip()
elif (split_file[0].strip() == "RSTRIP"):
text_dict[file] = no_header_ascii.rstrip()
else:
text_dict[file] = '\n' + full_file
return text_dict
# Use this object to access all graphics, instead of calling get_graphics() every time.
graphics = get_graphics()
def set_cursor(x: int, y: int) -> None:
print(f"\033[{y};{x}H",end="")
def set_cursor_str(x:int ,y:int) -> str:
return f"\033[{y};{x}H"
if __name__ == "__main__":
colortest()