forked from rmct/AutoReferee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-colors.py
31 lines (24 loc) · 906 Bytes
/
generate-colors.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
import urllib.request
import re
# these colors are borrowed from webbukkit/DynmapCore
COLOR_FILE = 'https://raw.github.com/webbukkit/DynmapCore/master/src/main/resources/extracted/colorschemes/default.txt'
def check(line):
parts = line.split()
return len(parts) and re.match('\d+(:\d+)?', parts[0])
with urllib.request.urlopen(COLOR_FILE) as u:
lines = [line.split() for line in u.read().decode('utf8').splitlines() if check(line)]
materials = dict()
for line in lines:
info, r, g, b, *rest = line
parts = info.split(':')
mat = int(parts[0])
if mat not in materials:
materials[mat] = dict()
data = int(parts[1]) if len(parts) > 1 else -1
materials[mat][data] = (r, g, b)
for mat in sorted(materials.keys()):
if len(materials[mat]) > 1:
del materials[mat][-1]
for data in sorted(materials[mat].keys()):
r, g, b = materials[mat][data]
print("%d %d %s %s %s" % (mat, data, r, g, b))