-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorMindustry.py
193 lines (171 loc) · 5.68 KB
/
ColorMindustry.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
import random
import os
import json
import re
__namelib__ = "ColorMindustry"
__version__ = "0.2-beta"
__author__ = "Roman Slabicky"
__company__ = "RCR"
class fw:
colors = ["[black]", "[white]", "[lightgray]", "[gray]", "[darkgray]", "[blue]", "[navy]", "[royal]", "[slate]", "[sky]", "[cyan]", "[teal]", "[green]", "[charteuse]", "[lime]", "[forest]", "[olive]", "[yellow]", "[gold]", "[goldenrod]", "[orange]", "[brown]", "[tan]", "[firebrick]", "[red]", "[scarlet]", "[coral]", "[salmon]", "[pink]", "[magneta]", "[purple]", "[violet]", "[maroon]", "[crimson]"]
temp = {}
def colors():
return fw.colors, len(fw.colors)
def clear_temp(name_var: str):
global fw
if name_var in fw.temp:
try:
del fw.temp[name_var]
return True, "ok"
except:
return False, "deletion-error"
else:
return False, "missing-variable"
def info():
print(str(__namelib__) + " (v" + str(__version__) + ")\n" + ("-" * (24 + len(__company__) + len(__author__))) + "\nCompany is " + str(__company__) + " @ Author is " + str(__author__))
def is_color(color: str):
testing = {"presence-of-brackets": None, "color-type": None}
if ("[" in color) and ("]" in color):
testing["presence-of-brackets"] = True
else:
testing["presence-of-brackets"] = False
if testing["presence-of-brackets"] == True:
ctt = re.match(r'#[0-9A-Fa-f]{6}', str(color[1:-1]))
else:
ctt = re.match(r'#[0-9A-Fa-f]{6}', str(color))
if ctt == None:
if color in fw.colors:
testing["color-type"] = "color"
else:
testing["color-type"] = "str"
else:
testing["color-type"] = "color-code"
return testing["presence-of-brackets"], testing["color-type"]
def add_color(color: str):
global fw
if not(color in fw.colors) and (is_color(color)[0] == True):
fw.colors.append(color)
def add_colors(colors: list):
global fw
wag = 0
while wag != len(colors):
add_color(colors[wag])
wag += 1
def save_colors(filename: str):
global fw
try:
with open(filename, "w") as file:
json.dump({"colors": fw.colors}, file)
return True
except:
return False
def load_colors(filename: str):
global fw
if (os.path.isabs(filename)) or (filename in os.listdir()):
if os.path.isfile(filename):
if os.path.getsize(filename) != 0:
try:
with open(filename) as file:
fdata = json.load(file)
try:
cdata = fdata["colors"]
except:
return False, "absent-colors-list"
if len(cdata) != 0:
wag = 0
while wag != len(cdata):
add_color(cdata[wag])
wag += 1
return True, "ok"
else:
return False, "null-color-list"
except:
return False, "failed-open"
else:
return False, "null-file"
else:
return False, "not-file"
else:
return False, "wrong-path"
def random_color():
return fw.colors[random.randint(0, len(fw.colors))]
def random_colors(count: int):
global fw
if count > len(fw.colors):
count = len(fw.colors)
fw.temp["colors-added"] = []
fw.temp["colors-done"] = []
wag = 0
while wag != count:
color = str(random_color())
if not(color in fw.temp["colors-added"]):
fw.temp["colors-added"].append(color)
fw.temp["colors-done"].append(color)
wag += 1
done = fw.temp["colors-done"]
clear_temp("colors-done")
clear_temp("colors-added")
return done
def del_color_in_str(text: str):
return (re.sub(r"(?<=\[).*?(?=\])", "", text)).replace("[", "").replace("]", "")
def tstlib():
global fw
testing_done = {"colors": 1, "is_color": 0, "add_color": 0, "add_colors": 0, "save_colors": 0, "load_colors": 0, "random_color": 1, "random_colors": 1}
# 1 (max is 1)
try:
colors_list, colors_count = colors()
except:
testing_done["colors"] -= 1
del colors_list, colors_count
# 2 (max is 5)
test_iscolor1 = is_color("white")
test_iscolor2 = is_color("[]")
test_iscolor3 = is_color("[white]")
test_iscolor4 = is_color("#FFFFFF")
test_iscolor5 = is_color("[#FFFFFF]")
if (test_iscolor1[0] == False) and (test_iscolor1[1] == "str"):
testing_done["is_color"] += 1
if (test_iscolor2[0] == True) and (test_iscolor2[1] == "str"):
testing_done["is_color"] += 1
if (test_iscolor3[0] == True) and (test_iscolor3[1] == "color"):
testing_done["is_color"] += 1
if (test_iscolor4[0] == False) and (test_iscolor4[1] == "color-code"):
testing_done["is_color"] += 1
if (test_iscolor5[0] == True) and (test_iscolor5[1] == "color-code"):
testing_done["is_color"] += 1
del test_iscolor1, test_iscolor2, test_iscolor3, test_iscolor4, test_iscolor5
# 3 (max is 1)
add_color("[test]")
if "[test]" in fw.colors:
testing_done["add_color"] += 1
fw.colors.remove("[test]")
# 4 (max is 1)
add_colors(["[test]", "[white]"])
if "[test]" in fw.colors:
testing_done["add_colors"] += 1
fw.colors.remove("[test]")
# 5 (max 2)
if save_colors("test.cfg") == True:
testing_done["save_colors"] += 1
if "test.cfg" in os.listdir():
testing_done["save_colors"] += 1
# 6 (max 1)
if load_colors("test.cfg")[0] == True:
testing_done["load_colors"] += 1
os.remove("test.cfg")
# 7 (max 1)
try:
color_rand = random_color()
del color_rand
except:
testing_done["random_color"] -= 1
# 8 (max 1)
try:
colors_rand = random_colors(8)
del colors_rand
except:
testing_done["random_colors"] -= 1
return testing_done["colors"], testing_done["is_color"], testing_done["add_color"], testing_done["add_colors"], testing_done["save_colors"], testing_done["load_colors"], testing_done["random_color"], testing_done["random_colors"]
def testing():
TestResults = tstlib()
print(f"Test Results:\n\tcolors: {TestResults[0]}/1\n\tis_color: {TestResults[1]}/5\n\tadd_color: {TestResults[2]}/1\n\tadd_colors: {TestResults[3]}/1\n\tsave_colors: {TestResults[4]}/2\n\tload_colors: {TestResults[5]}/1\n\trandom_color: {TestResults[6]}/1\n\trandom_colors: {TestResults[7]}/1\nOverall result: {sum(TestResults)}/13")